From db1337cc8300bb44f8ccf9dced3e122b6e50b4c9 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 12 Sep 2018 23:15:48 -0600 Subject: Change thread_to_thread_object to return a new reference This changes thread_to_thread_object to return a new reference and fixes up all the callers. gdb/ChangeLog 2018-09-16 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/python/py-inferior.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'gdb/python/py-inferior.c') diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 512d939..68c4c9d 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; } @@ -832,7 +832,7 @@ infpy_is_valid (PyObject *self, PyObject *args) static 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 }; @@ -841,8 +841,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, @@ -850,29 +848,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 (); } /* Implement repr() for gdb.Inferior. */ -- cgit v1.1