From patchwork Mon Nov 7 05:47:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17243 Received: (qmail 75728 invoked by alias); 7 Nov 2016 05:47:58 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 75667 invoked by uid 89); 7 Nov 2016 05:47:55 -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*r:4.86_1, H*Ad:U*tom, H*r:cmgw2, Hx-spam-relays-external:10.0.90.83 X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Mon, 07 Nov 2016 05:47:45 +0000 Received: (qmail 22784 invoked by uid 0); 7 Nov 2016 05:47:44 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy10.mail.unifiedlayer.com with SMTP; 7 Nov 2016 05:47:44 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 4tnf1u00E2f2jeq01tniu7; Sun, 06 Nov 2016 22:47:42 -0700 X-Authority-Analysis: v=2.1 cv=PIacp5aC 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=b4gVn1TtrA0JEBDspYkA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:47918 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c3cmS-0008A3-TG; Sun, 06 Nov 2016 22:47:41 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 05/14] Use gdbpy_reference in py-function.c Date: Sun, 6 Nov 2016 22:47:27 -0700 Message-Id: <1478497656-11832-6-git-send-email-tom@tromey.com> In-Reply-To: <1478497656-11832-1-git-send-email-tom@tromey.com> References: <1478497656-11832-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c3cmS-0008A3-TG X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:47918 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes some code in py-function.c to use gdbpy_reference. 2016-11-06 Tom Tromey * python/py-function.c (convert_values_to_python, fnpy_init): Use gdbpy_reference. --- gdb/ChangeLog | 5 +++++ gdb/python/py-function.c | 27 +++++++++++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1a0a21f..8271499 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-11-06 Tom Tromey + * python/py-function.c (convert_values_to_python, fnpy_init): Use + gdbpy_reference. + +2016-11-06 Tom Tromey + * python/py-cmd.c (gdbpy_string_to_argv): Use gdbpy_reference. 2016-11-06 Tom Tromey diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c index d42dbde..eb7b3c7 100644 --- a/gdb/python/py-function.c +++ b/gdb/python/py-function.c @@ -27,6 +27,7 @@ #include "completer.h" #include "expression.h" #include "language.h" +#include "py-ref.h" extern PyTypeObject fnpy_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject"); @@ -37,22 +38,19 @@ static PyObject * convert_values_to_python (int argc, struct value **argv) { int i; - PyObject *result = PyTuple_New (argc); + gdbpy_reference result (PyTuple_New (argc)); - if (! result) + if (result == NULL) return NULL; for (i = 0; i < argc; ++i) { - PyObject *elt = value_to_value_object (argv[i]); - if (! elt) - { - Py_DECREF (result); - return NULL; - } - PyTuple_SetItem (result, i, elt); + gdbpy_reference elt (value_to_value_object (argv[i])); + if (elt == NULL) + return NULL; + PyTuple_SetItem (result.get (), i, elt.release ()); } - return result; + return result.release (); } /* Call a Python function object's invoke method. */ @@ -173,21 +171,18 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds) if (PyObject_HasAttrString (self, "__doc__")) { - PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__"); + gdbpy_reference ds_obj (PyObject_GetAttrString (self, "__doc__")); if (ds_obj != NULL) { - if (gdbpy_is_string (ds_obj)) + if (gdbpy_is_string (ds_obj.get ())) { - docstring = python_string_to_host_string (ds_obj); + docstring = python_string_to_host_string (ds_obj.get ()); if (docstring == NULL) { Py_DECREF (self); - Py_DECREF (ds_obj); return -1; } } - - Py_DECREF (ds_obj); } } if (! docstring)