diff options
author | Tom Tromey <tom@tromey.com> | 2018-12-27 11:32:01 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-01-03 14:49:18 -0700 |
commit | 5c329e6ab4c7bba9b83155571b150756210001df (patch) | |
tree | 35725c6442fabe48ff6f0b573eb6d4985f215618 /gdb/python/py-value.c | |
parent | 169bb27bce3dc43b2bb5f6abf7fc21c19de5454a (diff) | |
download | gdb-5c329e6ab4c7bba9b83155571b150756210001df.zip gdb-5c329e6ab4c7bba9b83155571b150756210001df.tar.gz gdb-5c329e6ab4c7bba9b83155571b150756210001df.tar.bz2 |
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.
Diffstat (limited to 'gdb/python/py-value.c')
-rw-r--r-- | gdb/python/py-value.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 74835e9..9cc56e6 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1661,9 +1661,7 @@ convert_value_from_python (PyObject *obj) ULONGEST instead. */ if (PyErr_ExceptionMatches (PyExc_OverflowError)) { - PyObject *etype, *evalue, *etraceback; - - PyErr_Fetch (&etype, &evalue, &etraceback); + gdbpy_err_fetch fetched_error; gdbpy_ref<> zero (PyInt_FromLong (0)); /* Check whether obj is positive. */ @@ -1676,8 +1674,10 @@ convert_value_from_python (PyObject *obj) value = value_from_ulongest (builtin_type_upylong, ul); } else - /* There's nothing we can do. */ - PyErr_Restore (etype, evalue, etraceback); + { + /* There's nothing we can do. */ + fetched_error.restore (); + } } } else |