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
|
@ -240,7 +240,6 @@ objfpy_get_printers (PyObject *o, void *ignore)
|
|||
static int
|
||||
objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
|
||||
{
|
||||
PyObject *tmp;
|
||||
objfile_object *self = (objfile_object *) o;
|
||||
|
||||
if (! value)
|
||||
|
@ -258,10 +257,9 @@ objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
|
|||
}
|
||||
|
||||
/* Take care in case the LHS and RHS are related somehow. */
|
||||
tmp = self->printers;
|
||||
gdbpy_ref<> tmp (self->printers);
|
||||
Py_INCREF (value);
|
||||
self->printers = value;
|
||||
Py_XDECREF (tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -281,7 +279,6 @@ objfpy_get_frame_filters (PyObject *o, void *ignore)
|
|||
static int
|
||||
objfpy_set_frame_filters (PyObject *o, PyObject *filters, void *ignore)
|
||||
{
|
||||
PyObject *tmp;
|
||||
objfile_object *self = (objfile_object *) o;
|
||||
|
||||
if (! filters)
|
||||
|
@ -299,10 +296,9 @@ objfpy_set_frame_filters (PyObject *o, PyObject *filters, void *ignore)
|
|||
}
|
||||
|
||||
/* Take care in case the LHS and RHS are related somehow. */
|
||||
tmp = self->frame_filters;
|
||||
gdbpy_ref<> tmp (self->frame_filters);
|
||||
Py_INCREF (filters);
|
||||
self->frame_filters = filters;
|
||||
Py_XDECREF (tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -323,7 +319,6 @@ objfpy_get_frame_unwinders (PyObject *o, void *ignore)
|
|||
static int
|
||||
objfpy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
|
||||
{
|
||||
PyObject *tmp;
|
||||
objfile_object *self = (objfile_object *) o;
|
||||
|
||||
if (!unwinders)
|
||||
|
@ -341,10 +336,9 @@ objfpy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
|
|||
}
|
||||
|
||||
/* Take care in case the LHS and RHS are related somehow. */
|
||||
tmp = self->frame_unwinders;
|
||||
gdbpy_ref<> tmp (self->frame_unwinders);
|
||||
Py_INCREF (unwinders);
|
||||
self->frame_unwinders = unwinders;
|
||||
Py_XDECREF (tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -376,7 +370,6 @@ objfpy_get_xmethods (PyObject *o, void *ignore)
|
|||
static int
|
||||
objfpy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
|
||||
{
|
||||
PyObject *tmp;
|
||||
objfile_object *self = (objfile_object *) o;
|
||||
|
||||
if (! value)
|
||||
|
@ -394,10 +387,9 @@ objfpy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
|
|||
}
|
||||
|
||||
/* Take care in case the LHS and RHS are related somehow. */
|
||||
tmp = self->type_printers;
|
||||
gdbpy_ref<> tmp (self->type_printers);
|
||||
Py_INCREF (value);
|
||||
self->type_printers = value;
|
||||
Py_XDECREF (tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue