From 5c329e6ab4c7bba9b83155571b150756210001df Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 27 Dec 2018 11:32:01 -0700 Subject: 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 * 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) : Remove. : 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. --- gdb/python/py-varobj.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'gdb/python/py-varobj.c') diff --git a/gdb/python/py-varobj.c b/gdb/python/py-varobj.c index 38da443..274b2de 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -70,14 +70,8 @@ py_varobj_iter_next (struct varobj_iter *self) /* If we got a memory error, just use the text as the item. */ if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error)) { - PyObject *type, *value, *trace; - - PyErr_Fetch (&type, &value, &trace); - gdb::unique_xmalloc_ptr - value_str (gdbpy_exception_to_string (type, value)); - Py_XDECREF (type); - Py_XDECREF (value); - Py_XDECREF (trace); + gdbpy_err_fetch fetched_error; + gdb::unique_xmalloc_ptr value_str = fetched_error.to_string (); if (value_str == NULL) { gdbpy_print_stack (); -- cgit v1.1