From 2a3c71d68d452bb6b06d199d0eb7bc0cbc2b9b25 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 27 Dec 2018 11:53:20 -0700 Subject: 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 * 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. --- gdb/python/py-function.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'gdb/python/py-function.c') diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c index b254ab7..dbd5649 100644 --- a/gdb/python/py-function.c +++ b/gdb/python/py-function.c @@ -109,7 +109,8 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds) if (! PyArg_ParseTuple (args, "s", &name)) return -1; - Py_INCREF (self); + + gdbpy_ref<> self_ref = gdbpy_ref<>::new_reference (self); if (PyObject_HasAttrString (self, "__doc__")) { @@ -120,17 +121,15 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds) { docstring = python_string_to_host_string (ds_obj.get ()); if (docstring == NULL) - { - Py_DECREF (self); - return -1; - } + return -1; } } } if (! docstring) docstring.reset (xstrdup (_("This function is not documented."))); - add_internal_function (name, docstring.release (), fnpy_call, self); + add_internal_function (name, docstring.release (), fnpy_call, + self_ref.release ()); return 0; } -- cgit v1.1