mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-28 14:08:09 +08:00
Use a wrapper for PyErr_Fetch
This introduces a new class that wraps PyErr_Fetch and PyErr_Restore, and then changes all the callers in gdb to use it. This reduces the amount of explicit reference counting that is done in the Python code. I also found and fixed a latent bug in gdbpy_print_stack -- it was not correctly checking some error conditions, nor clearing the exception when needed. gdb/ChangeLog 2019-01-03 Tom Tromey <tom@tromey.com> * python/python.c (gdbpy_enter, ~gdbpy_enter): Update. (gdbpy_print_stack): Use gdbpy_err_fetch. * python/python-internal.h (class gdbpy_err_fetch): New class. (class gdbpy_enter) <m_error_type, m_error_value, m_error_traceback>: Remove. <m_error>: New member. (gdbpy_exception_to_string): Don't declare. * python/py-varobj.c (py_varobj_iter_next): Use gdbpy_err_fetch. * python/py-value.c (convert_value_from_python): Use gdbpy_err_fetch. * python/py-utils.c (gdbpy_err_fetch::to_string): Rename from gdbpy_exception_to_string. (gdbpy_handle_exception): Use gdbpy_err_fetch. * python/py-prettyprint.c (print_stack_unless_memory_error): Use gdbpy_err_fetch.
This commit is contained in:
@ -259,16 +259,8 @@ print_stack_unless_memory_error (struct ui_file *stream)
|
||||
{
|
||||
if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
|
||||
{
|
||||
PyObject *type, *value, *trace;
|
||||
|
||||
PyErr_Fetch (&type, &value, &trace);
|
||||
|
||||
gdbpy_ref<> type_ref (type);
|
||||
gdbpy_ref<> value_ref (value);
|
||||
gdbpy_ref<> trace_ref (trace);
|
||||
|
||||
gdb::unique_xmalloc_ptr<char>
|
||||
msg (gdbpy_exception_to_string (type, value));
|
||||
gdbpy_err_fetch fetched_error;
|
||||
gdb::unique_xmalloc_ptr<char> msg = fetched_error.to_string ();
|
||||
|
||||
if (msg == NULL || *msg == '\0')
|
||||
fprintf_filtered (stream, _("<error reading variable>"));
|
||||
|
Reference in New Issue
Block a user