From patchwork Thu Sep 13 05:30:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29358 Received: (qmail 15145 invoked by alias); 13 Sep 2018 05:30:52 -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 14967 invoked by uid 89); 13 Sep 2018 05:30:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ptid_t, *thr X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (50.116.126.2) 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 gateway36.websitewelcome.com (Postfix) with ESMTP id 03A0C402643AB for ; Wed, 12 Sep 2018 23:35:27 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 0KCigdftUbXuJ0KCqgwZNn; Thu, 13 Sep 2018 00:30:26 -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=odwHRAiZFSds5CG99cKFfEnzxSLsTGBYY62oOSHHTdQ=; b=G56AjByRS0qh3KyOe/yBxp/3mB q+qdYkpsUVaNIxEWWZjYJWZEKf4QQxFYZiHMNuhy21DNhch2C8BRmwEfc1zWsYEuCNKxnQQpPTRZo V6bgNt29tbZGpWeRl/jhEGlnC; 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 1g0KCi-0045EG-17; Thu, 13 Sep 2018 00:30:12 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/4] Change thread_to_thread_object to return a new reference Date: Wed, 12 Sep 2018 23:30:06 -0600 Message-Id: <20180913053007.11780-4-tom@tromey.com> In-Reply-To: <20180913053007.11780-1-tom@tromey.com> References: <20180913053007.11780-1-tom@tromey.com> This changes thread_to_thread_object to return a new reference and fixes up all the callers. 2018-09-12 Tom Tromey * python/python-internal.h (thread_to_thread_object): Change return type. * python/py-inferior.c (thread_to_thread_object): Return a new reference. (infpy_thread_from_thread_handle): Update. * python/py-infthread.c (gdbpy_selected_thread): Update. * python/py-stopevent.c (create_stop_event_object): Update. * python/py-threadevent.c (py_get_event_thread): Return a new reference. (py_get_event_thread): Update. * python/py-event.h (py_get_event_thread): Change return type. * python/py-continueevent.c (create_continue_event_object): Update. --- gdb/ChangeLog | 16 ++++++++++++ gdb/python/py-continueevent.c | 5 ++-- gdb/python/py-event.h | 5 ++-- gdb/python/py-inferior.c | 46 ++++++++++++++++------------------- gdb/python/py-infthread.c | 10 +------- gdb/python/py-stopevent.c | 4 +-- gdb/python/py-threadevent.c | 8 +++--- gdb/python/python-internal.h | 3 +-- 8 files changed, 50 insertions(+), 47 deletions(-) diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c index 759b4831366..9708c0d4059 100644 --- a/gdb/python/py-continueevent.c +++ b/gdb/python/py-continueevent.c @@ -32,12 +32,13 @@ static gdbpy_ref<> create_continue_event_object (ptid_t ptid) { - PyObject *py_thr = py_get_event_thread (ptid); + gdbpy_ref<> py_thr = py_get_event_thread (ptid); if (py_thr == nullptr) return nullptr; - return create_thread_event_object (&continue_event_object_type, py_thr); + return create_thread_event_object (&continue_event_object_type, + py_thr.get ()); } /* Callback function which notifies observers when a continue event occurs. diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index 56003e8785f..96be83b44c5 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -68,9 +68,8 @@ extern gdbpy_ref<> create_event_object (PyTypeObject *py_type); running in non-stop mode then the event is thread specific, otherwise it is process wide. This function returns the currently stopped thread in non-stop mode and - Py_None otherwise. In each case it returns a borrowed reference. */ -extern PyObject *py_get_event_thread (ptid_t ptid) - CPYCHECKER_RETURNS_BORROWED_REF; + Py_None otherwise. */ +extern gdbpy_ref<> py_get_event_thread (ptid_t ptid); extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type, PyObject *thread); diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 1cf37296973..bf8ac75a316 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -306,7 +306,7 @@ find_inferior_object (int pid) return NULL; } -thread_object * +gdbpy_ref<> thread_to_thread_object (thread_info *thr) { gdbpy_ref inf_obj (inferior_to_inferior_object (thr->inf)); @@ -317,7 +317,7 @@ thread_to_thread_object (thread_info *thr) thread != NULL; thread = thread->next) if (thread->thread_obj->thread == thr) - return thread->thread_obj; + return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj); return NULL; } @@ -817,7 +817,7 @@ infpy_is_valid (PyObject *self, PyObject *args) PyObject * infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) { - PyObject *handle_obj, *result; + PyObject *handle_obj; inferior_object *inf_obj = (inferior_object *) self; static const char *keywords[] = { "thread_handle", NULL }; @@ -826,8 +826,6 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) if (! gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &handle_obj)) return NULL; - result = Py_None; - if (!gdbpy_is_value_object (handle_obj)) { PyErr_SetString (PyExc_TypeError, @@ -835,29 +833,27 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) return NULL; } - else + + gdbpy_ref<> result; + TRY + { + struct thread_info *thread_info; + struct value *val = value_object_to_value (handle_obj); + + thread_info = find_thread_by_handle (val, inf_obj->inferior); + if (thread_info != NULL) + result = thread_to_thread_object (thread_info); + } + CATCH (except, RETURN_MASK_ALL) { - TRY - { - struct thread_info *thread_info; - struct value *val = value_object_to_value (handle_obj); - - thread_info = find_thread_by_handle (val, inf_obj->inferior); - if (thread_info != NULL) - { - result = (PyObject *) thread_to_thread_object (thread_info); - if (result != NULL) - Py_INCREF (result); - } - } - CATCH (except, RETURN_MASK_ALL) - { - GDB_PY_HANDLE_EXCEPTION (except); - } - END_CATCH + GDB_PY_HANDLE_EXCEPTION (except); } + END_CATCH - return result; + if (result == NULL) + result = gdbpy_ref<>::new_reference (Py_None); + + return result.release (); } diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 36ae71b6358..4b2705a0af6 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -284,15 +284,7 @@ PyObject * gdbpy_selected_thread (PyObject *self, PyObject *args) { if (inferior_ptid != null_ptid) - { - PyObject *thread_obj - = (PyObject *) thread_to_thread_object (inferior_thread ()); - if (thread_obj != NULL) - { - Py_INCREF (thread_obj); - return thread_obj; - } - } + return thread_to_thread_object (inferior_thread ()).release (); Py_RETURN_NONE; } diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index f6bd207f3b8..cbdf7b7e7e0 100644 --- a/gdb/python/py-stopevent.c +++ b/gdb/python/py-stopevent.c @@ -23,8 +23,8 @@ gdbpy_ref<> create_stop_event_object (PyTypeObject *py_type) { - return create_thread_event_object (py_type, - py_get_event_thread (inferior_ptid)); + gdbpy_ref<> thread = py_get_event_thread (inferior_ptid); + return create_thread_event_object (py_type, thread.get ()); } /* Callback observers when a stop event occurs. This function will create a diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c index 4f822b4ae09..13af1c840ba 100644 --- a/gdb/python/py-threadevent.c +++ b/gdb/python/py-threadevent.c @@ -22,19 +22,19 @@ /* See py-event.h. */ -PyObject * +gdbpy_ref<> py_get_event_thread (ptid_t ptid) { - PyObject *pythread = nullptr; + gdbpy_ref<> pythread; if (non_stop) { thread_info *thread = find_thread_ptid (ptid); if (thread != nullptr) - pythread = (PyObject *) thread_to_thread_object (thread); + pythread = thread_to_thread_object (thread); } else - pythread = Py_None; + pythread = gdbpy_ref<>::new_reference (Py_None); if (pythread == nullptr) { diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index cbba3ff8ef6..dc8d7cdd32a 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -533,8 +533,7 @@ PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw); PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch); thread_object *create_thread_object (struct thread_info *tp); -thread_object *thread_to_thread_object (thread_info *thr) - CPYCHECKER_RETURNS_BORROWED_REF; +gdbpy_ref<> thread_to_thread_object (thread_info *thr);; inferior_object *inferior_to_inferior_object (inferior *inf); const struct block *block_object_to_block (PyObject *obj);