From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15332 invoked by alias); 13 Sep 2018 05:30:53 -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 14968 invoked by uid 89); 13 Sep 2018 05:30:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1678 X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Sep 2018 05:30:29 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 1386CACD3 for ; Thu, 13 Sep 2018 00:30:23 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 0KChgdfqCbXuJ0KCogwZM7; Thu, 13 Sep 2018 00:30:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=y0R89Nb+ZsG7P7TgV1ujp1ej/5A7jSK+L3ZN8H4Coyg=; b=nDkm8Ld/y4rWFRnJbaJyWpLj37 8iB41G2NuBxf6PIf9ijF0k3faVp8izvF3RTVFFZs3eKbYPhtMn08x37nl7XURISy4Axpn61M6vtkl cfHadfCYGesof/5bvBe0oEbeg; Received: from 97-122-189-157.hlrn.qwest.net ([97.122.189.157]:54318 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g0KCh-0045EG-E8; Thu, 13 Sep 2018 00:30:11 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/4] Change pspace_to_pspace_object to return a new reference Date: Thu, 13 Sep 2018 05:30:00 -0000 Message-Id: <20180913053007.11780-2-tom@tromey.com> In-Reply-To: <20180913053007.11780-1-tom@tromey.com> References: <20180913053007.11780-1-tom@tromey.com> X-SW-Source: 2018-09/txt/msg00410.txt.bz2 This changes pspace_to_pspace_object to return a new reference and fixes up all the callers. gdb/ChangeLog 2018-09-12 Tom Tromey * python/python-internal.h (pspace_to_pspace_object): Change return type. * python/py-newobjfileevent.c (create_clear_objfiles_event_object): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/python.c (gdbpy_get_current_progspace): Update. (gdbpy_progspaces): Update. * python/py-progspace.c (pspace_to_pspace_object): Return a new reference. * python/py-objfile.c (objfpy_get_progspace): Update. * python/py-prettyprint.c (find_pretty_printer_from_progspace): Update. --- gdb/ChangeLog | 16 ++++++++++++++++ gdb/python/py-newobjfileevent.c | 10 ++++------ gdb/python/py-objfile.c | 6 ++---- gdb/python/py-prettyprint.c | 6 +++--- gdb/python/py-progspace.c | 31 ++++++++++++++++--------------- gdb/python/py-xmethods.c | 6 +++--- gdb/python/python-internal.h | 3 +-- gdb/python/python.c | 11 +++-------- 8 files changed, 48 insertions(+), 41 deletions(-) diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c index a9341a3be18..aa31fb4849b 100644 --- a/gdb/python/py-newobjfileevent.c +++ b/gdb/python/py-newobjfileevent.c @@ -66,12 +66,10 @@ create_clear_objfiles_event_object (void) if (objfile_event == NULL) return NULL; - /* Note that pspace_to_pspace_object returns a borrowed reference, - so we don't need a decref here. */ - PyObject *py_progspace = pspace_to_pspace_object (current_program_space); - if (!py_progspace || evpy_add_attribute (objfile_event.get (), - "progspace", - py_progspace) < 0) + gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space); + if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (), + "progspace", + py_progspace.get ()) < 0) return NULL; return objfile_event; diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index c2b40ff5352..8fd160c7bf8 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -167,10 +167,8 @@ objfpy_get_progspace (PyObject *self, void *closure) if (obj->objfile) { - PyObject *pspace = pspace_to_pspace_object (obj->objfile->pspace); - - Py_XINCREF (pspace); - return pspace; + gdbpy_ref<> pspace = pspace_to_pspace_object (obj->objfile->pspace); + return pspace.get (); } Py_RETURN_NONE; diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 7da0f2d9af2..9aadd3b27c9 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -128,11 +128,11 @@ find_pretty_printer_from_objfiles (PyObject *value) static PyObject * find_pretty_printer_from_progspace (PyObject *value) { - PyObject *obj = pspace_to_pspace_object (current_program_space); + gdbpy_ref<> obj = pspace_to_pspace_object (current_program_space); - if (!obj) + if (obj == NULL) return NULL; - gdbpy_ref<> pp_list (pspy_get_printers (obj, NULL)); + gdbpy_ref<> pp_list (pspy_get_printers (obj.get (), NULL)); return search_pp_list (pp_list.get (), value); } diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 3eaa466666d..2aeeca92eb2 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -337,30 +337,31 @@ py_free_pspace (struct program_space *pspace, void *datum) object->pspace = NULL; } -/* Return a borrowed reference to the Python object of type Pspace +/* Return a new reference to the Python object of type Pspace representing PSPACE. If the object has already been created, return it. Otherwise, create it. Return NULL and set the Python error on failure. */ -PyObject * +gdbpy_ref<> pspace_to_pspace_object (struct program_space *pspace) { - gdbpy_ref object - ((pspace_object *) program_space_data (pspace, pspy_pspace_data_key)); - if (object == NULL) + PyObject *result + ((PyObject *) program_space_data (pspace, pspy_pspace_data_key)); + if (result == NULL) { - object.reset (PyObject_New (pspace_object, &pspace_object_type)); - if (object != NULL) - { - if (!pspy_initialize (object.get ())) - return NULL; - - object->pspace = pspace; - set_program_space_data (pspace, pspy_pspace_data_key, object.get ()); - } + gdbpy_ref object + ((pspace_object *) PyObject_New (pspace_object, &pspace_object_type)); + if (object == NULL) + return NULL; + if (!pspy_initialize (object.get ())) + return NULL; + + object->pspace = pspace; + set_program_space_data (pspace, pspy_pspace_data_key, object.get ()); + result = (PyObject *) object.release (); } - return (PyObject *) object.release (); + return gdbpy_ref<>::new_reference (result); } int diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index f7e3c37210c..c568295a165 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -122,7 +122,6 @@ gdbpy_get_matching_xmethod_workers std::vector *dm_vec) { struct objfile *objfile; - PyObject *py_progspace; gdb_assert (obj_type != NULL && method_name != NULL); @@ -170,10 +169,11 @@ gdbpy_get_matching_xmethod_workers /* Gather debug methods matchers registered with the current program space. */ - py_progspace = pspace_to_pspace_object (current_program_space); + gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space); if (py_progspace != NULL) { - gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace, NULL)); + gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace.get (), + NULL)); gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (), pspace_matchers.get ())); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 3874fdc5e79..a6dc5f090b5 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -517,8 +517,7 @@ PyObject *value_to_value_object (struct value *v); PyObject *type_to_type_object (struct type *); PyObject *frame_info_to_frame_object (struct frame_info *frame); PyObject *symtab_to_linetable_object (PyObject *symtab); -PyObject *pspace_to_pspace_object (struct program_space *) - CPYCHECKER_RETURNS_BORROWED_REF; +gdbpy_ref<> pspace_to_pspace_object (struct program_space *); PyObject *pspy_get_printers (PyObject *, void *); PyObject *pspy_get_frame_filters (PyObject *, void *); PyObject *pspy_get_frame_unwinders (PyObject *, void *); diff --git a/gdb/python/python.c b/gdb/python/python.c index 6f798a0e461..93d6d1156d8 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1339,12 +1339,7 @@ gdbpy_print_stack (void) static PyObject * gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2) { - PyObject *result; - - result = pspace_to_pspace_object (current_program_space); - if (result) - Py_INCREF (result); - return result; + return pspace_to_pspace_object (current_program_space).release (); } /* Return a sequence holding all the Progspaces. */ @@ -1360,9 +1355,9 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2) ALL_PSPACES (ps) { - PyObject *item = pspace_to_pspace_object (ps); + gdbpy_ref<> item = pspace_to_pspace_object (ps); - if (!item || PyList_Append (list.get (), item) == -1) + if (item == NULL || PyList_Append (list.get (), item.get ()) == -1) return NULL; } -- 2.17.1