From patchwork Sun Nov 20 20:41:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17648 Received: (qmail 1420 invoked by alias); 20 Nov 2016 20:41: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 1167 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=0.3 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=2696, H*F:U*tom, 2718, H*RU:10.0.90.82 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:47 +0000 Received: (qmail 19368 invoked by uid 0); 20 Nov 2016 20:41:45 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy4.mail.unifiedlayer.com with SMTP; 20 Nov 2016 20:41:45 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id ALhh1u0022f2jeq01LhkLF; Sun, 20 Nov 2016 13:41:44 -0700 X-Authority-Analysis: v=2.1 cv=QtDNgzCd 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=BMIDpAJS5CtdVIYuvpoA:9 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 1c8Yvm-0005f5-Fr; Sun, 20 Nov 2016 13:41:42 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 06/13] Use gdbpy_ref in py-inferior.c Date: Sun, 20 Nov 2016 13:41:29 -0700 Message-Id: <1479674496-14000-7-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: 1c8Yvm-0005f5-Fr 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: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes py-inferior.c to use gdbpy_ref in more places. 2016-11-20 Tom Tromey * python/py-inferior.c (find_thread_object, build_inferior_list): Use gdbpy_ref. --- gdb/ChangeLog | 5 +++++ gdb/python/py-inferior.c | 23 ++++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 545dbde..28e427e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-11-20 Tom Tromey + * python/py-inferior.c (find_thread_object, build_inferior_list): + Use gdbpy_ref. + +2016-11-20 Tom Tromey + * python/py-framefilter.c (py_print_frame): Use gdbpy_ref. 2016-11-20 Tom Tromey diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index a9993a8..4ba20ce 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -251,19 +251,17 @@ find_thread_object (ptid_t ptid) { int pid; struct threadlist_entry *thread; - PyObject *inf_obj; thread_object *found = NULL; pid = ptid_get_pid (ptid); if (pid == 0) return NULL; - inf_obj = find_inferior_object (pid); - - if (! inf_obj) + gdbpy_ref inf_obj (find_inferior_object (pid)); + if (inf_obj == NULL) return NULL; - for (thread = ((inferior_object *)inf_obj)->threads; thread; + for (thread = ((inferior_object *)(inf_obj.get ()))->threads; thread; thread = thread->next) if (ptid_equal (thread->thread_obj->thread->ptid, ptid)) { @@ -271,8 +269,6 @@ find_thread_object (ptid_t ptid) break; } - Py_DECREF (inf_obj); - if (found) return found; @@ -416,19 +412,12 @@ static int build_inferior_list (struct inferior *inf, void *arg) { PyObject *list = (PyObject *) arg; - PyObject *inferior = inferior_to_inferior_object (inf); - int success = 0; + gdbpy_ref inferior (inferior_to_inferior_object (inf)); - if (! inferior) + if (inferior == NULL) return 0; - success = PyList_Append (list, inferior); - Py_DECREF (inferior); - - if (success) - return 1; - - return 0; + return PyList_Append (list, inferior.get ()) ? 1 : 0; } /* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).