mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-30 15:56:36 +08:00
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.
This commit is contained in:
@ -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>
|
2018-09-16 Simon Marchi <simon.marchi@polymtl.ca>
|
||||||
|
|
||||||
* Makefile.in (LIBGDB_OBS): Sort COMMON_OBS.
|
* Makefile.in (LIBGDB_OBS): Sort COMMON_OBS.
|
||||||
|
@ -319,6 +319,8 @@ thread_to_thread_object (thread_info *thr)
|
|||||||
if (thread->thread_obj->thread == thr)
|
if (thread->thread_obj->thread == thr)
|
||||||
return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj);
|
return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj);
|
||||||
|
|
||||||
|
PyErr_SetString (PyExc_SystemError,
|
||||||
|
_("could not find gdb thread object"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,7 +851,6 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdbpy_ref<> result;
|
|
||||||
TRY
|
TRY
|
||||||
{
|
{
|
||||||
struct thread_info *thread_info;
|
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);
|
thread_info = find_thread_by_handle (val, inf_obj->inferior);
|
||||||
if (thread_info != NULL)
|
if (thread_info != NULL)
|
||||||
result = thread_to_thread_object (thread_info);
|
return thread_to_thread_object (thread_info).release ();
|
||||||
}
|
}
|
||||||
CATCH (except, RETURN_MASK_ALL)
|
CATCH (except, RETURN_MASK_ALL)
|
||||||
{
|
{
|
||||||
@ -865,10 +866,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
}
|
}
|
||||||
END_CATCH
|
END_CATCH
|
||||||
|
|
||||||
if (result == NULL)
|
Py_RETURN_NONE;
|
||||||
result = gdbpy_ref<>::new_reference (Py_None);
|
|
||||||
|
|
||||||
return result.release ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implement repr() for gdb.Inferior. */
|
/* Implement repr() for gdb.Inferior. */
|
||||||
|
@ -25,24 +25,15 @@
|
|||||||
gdbpy_ref<>
|
gdbpy_ref<>
|
||||||
py_get_event_thread (ptid_t ptid)
|
py_get_event_thread (ptid_t ptid)
|
||||||
{
|
{
|
||||||
gdbpy_ref<> pythread;
|
|
||||||
|
|
||||||
if (non_stop)
|
if (non_stop)
|
||||||
{
|
{
|
||||||
thread_info *thread = find_thread_ptid (ptid);
|
thread_info *thread = find_thread_ptid (ptid);
|
||||||
if (thread != nullptr)
|
if (thread != nullptr)
|
||||||
pythread = thread_to_thread_object (thread);
|
return thread_to_thread_object (thread);
|
||||||
}
|
|
||||||
else
|
|
||||||
pythread = gdbpy_ref<>::new_reference (Py_None);
|
|
||||||
|
|
||||||
if (pythread == nullptr)
|
|
||||||
{
|
|
||||||
PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
|
PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return gdbpy_ref<>::new_reference (Py_None);
|
||||||
return pythread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gdbpy_ref<>
|
gdbpy_ref<>
|
||||||
|
Reference in New Issue
Block a user