diff options
author | Tom Tromey <tom@tromey.com> | 2018-09-16 08:02:22 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-16 23:36:54 -0600 |
commit | 4a137fec2e1a8a6372da8fca1040ee582c62f78d (patch) | |
tree | 6b99d8cbfba9349e6018200496fbf3d6b515e91c /gdb | |
parent | 8ff03f0bfbf0dc7d125f6ea0b844636c0aba74f6 (diff) | |
download | fsf-binutils-gdb-4a137fec2e1a8a6372da8fca1040ee582c62f78d.zip fsf-binutils-gdb-4a137fec2e1a8a6372da8fca1040ee582c62f78d.tar.gz fsf-binutils-gdb-4a137fec2e1a8a6372da8fca1040ee582c62f78d.tar.bz2 |
Simplify uses of thread_to_thread_object
An review by Simon of an earlier showed a few spots related to
thread_to_thread_object that could be simplified. This also detected
a latent bug, where thread_to_thread_object was inconsistent about
setting the Python exception before a NULL return.
Tested on x86-64 Fedora 28.
gdb/ChangeLog
2018-09-16 Tom Tromey <tom@tromey.com>
* python/py-threadevent.c (py_get_event_thread): Simplify.
* python/py-inferior.c (infpy_thread_from_thread_handle):
Return immediately after calling thread_to_thread_object. Use
Py_RETURN_NONE.
(thread_to_thread_object): Set the exception on a NULL return.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/python/py-inferior.c | 10 | ||||
-rw-r--r-- | gdb/python/py-threadevent.c | 13 |
3 files changed, 14 insertions, 17 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f5c5d21..4f8bd2b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-09-16 Tom Tromey <tom@tromey.com> + + * python/py-threadevent.c (py_get_event_thread): Simplify. + * python/py-inferior.c (infpy_thread_from_thread_handle): + Return immediately after calling thread_to_thread_object. Use + Py_RETURN_NONE. + (thread_to_thread_object): Set the exception on a NULL return. + 2018-09-16 Simon Marchi <simon.marchi@polymtl.ca> * Makefile.in (LIBGDB_OBS): Sort COMMON_OBS. diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 68c4c9d..145f53d 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -319,6 +319,8 @@ thread_to_thread_object (thread_info *thr) if (thread->thread_obj->thread == thr) return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj); + PyErr_SetString (PyExc_SystemError, + _("could not find gdb thread object")); return NULL; } @@ -849,7 +851,6 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) return NULL; } - gdbpy_ref<> result; TRY { struct thread_info *thread_info; @@ -857,7 +858,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) thread_info = find_thread_by_handle (val, inf_obj->inferior); if (thread_info != NULL) - result = thread_to_thread_object (thread_info); + return thread_to_thread_object (thread_info).release (); } CATCH (except, RETURN_MASK_ALL) { @@ -865,10 +866,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw) } END_CATCH - if (result == NULL) - result = gdbpy_ref<>::new_reference (Py_None); - - return result.release (); + Py_RETURN_NONE; } /* Implement repr() for gdb.Inferior. */ diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c index 13af1c8..ea62540 100644 --- a/gdb/python/py-threadevent.c +++ b/gdb/python/py-threadevent.c @@ -25,24 +25,15 @@ gdbpy_ref<> py_get_event_thread (ptid_t ptid) { - gdbpy_ref<> pythread; - if (non_stop) { thread_info *thread = find_thread_ptid (ptid); if (thread != nullptr) - pythread = thread_to_thread_object (thread); - } - else - pythread = gdbpy_ref<>::new_reference (Py_None); - - if (pythread == nullptr) - { + return thread_to_thread_object (thread); PyErr_SetString (PyExc_RuntimeError, "Could not find event thread"); return NULL; } - - return pythread; + return gdbpy_ref<>::new_reference (Py_None); } gdbpy_ref<> |