Remove more uses of explicit reference counting in Python
This changes some more place in the Python code to use gdbpy_ref rather than explicit reference counting. While doing this I found a latent bug in typy_fields_items -- it was not checking for errors in one spot. I also changed valpy_dealloc to use Py_XDECREF rather than an explicit "if". gdb/ChangeLog 2019-01-03 Tom Tromey <tom@tromey.com> * python/py-value.c (valpy_dealloc): Use Py_XDECREF. * python/py-type.c (typy_fields_items): Use gdbpy_ref. * python/py-progspace.c (pspy_set_printers): Use gdbpy_ref. (pspy_set_frame_filters, pspy_set_frame_unwinders) (pspy_set_type_printers): Likewise. * python/py-function.c (fnpy_init): Use gdbpy_ref. * python/py-cmd.c (cmdpy_init): Use gdbpy_ref. * python/py-objfile.c (objfpy_set_printers): Use gdbpy_ref. (objfpy_set_frame_filters, objfpy_set_frame_unwinders) (objfpy_set_type_printers): Likewise.
This commit is contained in:
parent
5c329e6ab4
commit
2a3c71d68d
7 changed files with 39 additions and 57 deletions
|
@ -319,7 +319,6 @@ static PyObject *
|
|||
typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
|
||||
{
|
||||
PyObject *py_type = self;
|
||||
PyObject *result = NULL, *iter = NULL;
|
||||
struct type *type = ((type_object *) py_type)->type;
|
||||
struct type *checked_type = type;
|
||||
|
||||
|
@ -333,22 +332,19 @@ typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
|
|||
}
|
||||
END_CATCH
|
||||
|
||||
if (checked_type != type)
|
||||
py_type = type_to_type_object (checked_type);
|
||||
iter = typy_make_iter (py_type, kind);
|
||||
gdbpy_ref<> type_holder;
|
||||
if (checked_type != type)
|
||||
{
|
||||
/* Need to wrap this in braces because Py_DECREF isn't wrapped
|
||||
in a do{}while(0). */
|
||||
Py_DECREF (py_type);
|
||||
}
|
||||
if (iter != NULL)
|
||||
{
|
||||
result = PySequence_List (iter);
|
||||
Py_DECREF (iter);
|
||||
type_holder.reset (type_to_type_object (checked_type));
|
||||
if (type_holder == nullptr)
|
||||
return nullptr;
|
||||
py_type = type_holder.get ();
|
||||
}
|
||||
gdbpy_ref<> iter (typy_make_iter (py_type, kind));
|
||||
if (iter == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return result;
|
||||
return PySequence_List (iter.get ());
|
||||
}
|
||||
|
||||
/* Return a sequence of all fields. Each field is a gdb.Field object. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue