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:
Tom Tromey 2018-09-16 08:02:22 -06:00
parent 8ff03f0bfb
commit 4a137fec2e
3 changed files with 14 additions and 17 deletions

View file

@ -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<>