From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1212 invoked by alias); 20 Nov 2016 20:41:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 1170 invoked by uid 89); 20 Nov 2016 20:41:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=H*F:U*tom, borrowed, RETURN_MASK_ALL, python.c X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Sun, 20 Nov 2016 20:41:46 +0000 Received: (qmail 19332 invoked by uid 0); 20 Nov 2016 20:41:44 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy4.mail.unifiedlayer.com with SMTP; 20 Nov 2016 20:41:44 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id ALhh1u0082f2jeq01Lhk8B; Sun, 20 Nov 2016 13:41:44 -0700 X-Authority-Analysis: v=2.1 cv=K/+xQUmI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=RYYPFV1VSeSSHpZ-Wz0A:9 a=UI6uJWf16rc_OS3R:21 a=lYuHWz_MePKg6VQ5:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:40590 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c8Yvk-0005f5-U8; Sun, 20 Nov 2016 13:41:41 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 01/13] Use gdbpy_ref in archpy_disassemble Date: Sun, 20 Nov 2016 20:41:00 -0000 Message-Id: <1479674496-14000-2-git-send-email-tom@tromey.com> In-Reply-To: <1479674496-14000-1-git-send-email-tom@tromey.com> References: <1479674496-14000-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c8Yvk-0005f5-U8 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:40590 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2016-11/txt/msg00586.txt.bz2 This changes archpy_disassemble to use gdbpy_ref. It also fixes a latent bug where archpy_disassemble was decref'ing the results of a all to PyArg_ParseTupleAndKeywords. This is incorrect because PyArg_ParseTupleAndKeywords returns borrowed references. 2016-11-20 Tom Tromey * python/py-arch.c (archpy_disassemble): Use gdbpy_ref. Don't decref results of PyArg_ParseTupleAndKeywords. --- gdb/ChangeLog | 5 +++++ gdb/python/py-arch.c | 29 +++++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 49c226b..527053f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2016-11-20 Tom Tromey + + * python/py-arch.c (archpy_disassemble): Use gdbpy_ref. Don't + decref results of PyArg_ParseTupleAndKeywords. + 2016-11-12 Tom Tromey * python/python.c (python_run_simple_file): Use diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 60cc5a9..216a668 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -22,6 +22,7 @@ #include "arch-utils.h" #include "disasm.h" #include "python-internal.h" +#include "py-ref.h" typedef struct arch_object_type_object { PyObject_HEAD @@ -120,7 +121,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) CORE_ADDR pc; gdb_py_ulongest start_temp; long count = 0, i; - PyObject *result_list, *end_obj = NULL, *count_obj = NULL; + PyObject *end_obj = NULL, *count_obj = NULL; struct gdbarch *gdbarch = NULL; ARCHPY_REQUIRE_VALID (self, gdbarch); @@ -149,8 +150,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) #endif else { - Py_DECREF (end_obj); - Py_XDECREF (count_obj); PyErr_SetString (PyExc_TypeError, _("Argument 'end_pc' should be a (long) integer.")); @@ -159,8 +158,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) if (end < start) { - Py_DECREF (end_obj); - Py_XDECREF (count_obj); PyErr_SetString (PyExc_ValueError, _("Argument 'end_pc' should be greater than or " "equal to the argument 'start_pc'.")); @@ -173,8 +170,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) count = PyInt_AsLong (count_obj); if (PyErr_Occurred () || count < 0) { - Py_DECREF (count_obj); - Py_XDECREF (end_obj); PyErr_SetString (PyExc_TypeError, _("Argument 'count' should be an non-negative " "integer.")); @@ -183,7 +178,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) } } - result_list = PyList_New (0); + gdbpy_ref result_list (PyList_New (0)); if (result_list == NULL) return NULL; @@ -199,19 +194,16 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) { int insn_len = 0; struct ui_file *memfile = mem_fileopen (); - PyObject *insn_dict = PyDict_New (); + gdbpy_ref insn_dict (PyDict_New ()); if (insn_dict == NULL) { - Py_DECREF (result_list); ui_file_delete (memfile); return NULL; } - if (PyList_Append (result_list, insn_dict)) + if (PyList_Append (result_list.get (), insn_dict.get ())) { - Py_DECREF (result_list); - Py_DECREF (insn_dict); ui_file_delete (memfile); return NULL; /* PyList_Append Sets the exception. */ @@ -223,7 +215,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) } CATCH (except, RETURN_MASK_ALL) { - Py_DECREF (result_list); ui_file_delete (memfile); gdbpy_convert_exception (except); @@ -233,17 +224,15 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) std::string as = ui_file_as_string (memfile); - if (PyDict_SetItemString (insn_dict, "addr", + if (PyDict_SetItemString (insn_dict.get (), "addr", gdb_py_long_from_ulongest (pc)) - || PyDict_SetItemString (insn_dict, "asm", + || PyDict_SetItemString (insn_dict.get (), "asm", PyString_FromString (!as.empty () ? as.c_str () : "")) - || PyDict_SetItemString (insn_dict, "length", + || PyDict_SetItemString (insn_dict.get (), "length", PyInt_FromLong (insn_len))) { - Py_DECREF (result_list); - ui_file_delete (memfile); return NULL; @@ -254,7 +243,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) ui_file_delete (memfile); } - return result_list; + return result_list.release (); } /* Initializes the Architecture class in the gdb module. */ -- 2.7.4