aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-objfile.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-12 23:06:09 -0600
committerTom Tromey <tom@tromey.com>2018-09-16 07:25:56 -0600
commit0a9db5ad8a6c49cec7adb7e3ef29c558fcfbf11b (patch)
tree93925dced92f15d3b5e3986ba75f023896f64512 /gdb/python/py-objfile.c
parent3c7aa30778a1615d88c13508c04138ef2499112d (diff)
downloadfsf-binutils-gdb-0a9db5ad8a6c49cec7adb7e3ef29c558fcfbf11b.zip
fsf-binutils-gdb-0a9db5ad8a6c49cec7adb7e3ef29c558fcfbf11b.tar.gz
fsf-binutils-gdb-0a9db5ad8a6c49cec7adb7e3ef29c558fcfbf11b.tar.bz2
Change objfile_to_objfile_object to return a new reference
This changes objfile_to_objfile_object to return a new references and fixes up all the uses. gdb/ChangeLog 2018-09-16 Tom Tromey <tom@tromey.com> * python/py-progspace.c (pspy_get_objfiles): Update. * python/python-internal.h (objfile_to_objfile_object): Change return type. * python/py-newobjfileevent.c (create_new_objfile_event_object): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/python.c (gdbpy_get_current_objfile): Update. (gdbpy_objfiles): Update. * python/py-objfile.c (objfpy_get_owner, gdbpy_lookup_objfile): Update. (objfile_to_objfile_object): Return a new reference. * python/py-symtab.c (stpy_get_objfile): Update. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Update.
Diffstat (limited to 'gdb/python/py-objfile.c')
-rw-r--r--gdb/python/py-objfile.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 722c9b0..2e24d0f 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -115,12 +115,7 @@ objfpy_get_owner (PyObject *self, void *closure)
owner = objfile->separate_debug_objfile_backlink;
if (owner != NULL)
- {
- PyObject *result = objfile_to_objfile_object (owner);
-
- Py_XINCREF (result);
- return result;
- }
+ return objfile_to_objfile_object (owner).release ();
Py_RETURN_NONE;
}
@@ -602,12 +597,7 @@ gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
objfile = objfpy_lookup_objfile_by_name (name);
if (objfile != NULL)
- {
- PyObject *result = objfile_to_objfile_object (objfile);
-
- Py_XINCREF (result);
- return result;
- }
+ return objfile_to_objfile_object (objfile).release ();
PyErr_SetString (PyExc_ValueError, _("Objfile not found."));
return NULL;
@@ -625,30 +615,31 @@ py_free_objfile (struct objfile *objfile, void *datum)
object->objfile = NULL;
}
-/* Return a borrowed reference to the Python object of type Objfile
+/* Return a new reference to the Python object of type Objfile
representing OBJFILE. If the object has already been created,
return it. Otherwise, create it. Return NULL and set the Python
error on failure. */
-PyObject *
+gdbpy_ref<>
objfile_to_objfile_object (struct objfile *objfile)
{
- gdbpy_ref<objfile_object> object
- ((objfile_object *) objfile_data (objfile, objfpy_objfile_data_key));
- if (object == NULL)
+ PyObject *result
+ = ((PyObject *) objfile_data (objfile, objfpy_objfile_data_key));
+ if (result == NULL)
{
- object.reset (PyObject_New (objfile_object, &objfile_object_type));
- if (object != NULL)
- {
- if (!objfpy_initialize (object.get ()))
- return NULL;
+ gdbpy_ref<objfile_object> object
+ ((objfile_object *) PyObject_New (objfile_object, &objfile_object_type));
+ if (object == NULL)
+ return NULL;
+ if (!objfpy_initialize (object.get ()))
+ return NULL;
- object->objfile = objfile;
- set_objfile_data (objfile, objfpy_objfile_data_key, object.get ());
- }
+ object->objfile = objfile;
+ set_objfile_data (objfile, objfpy_objfile_data_key, object.get ());
+ result = (PyObject *) object.release ();
}
- return (PyObject *) object.release ();
+ return gdbpy_ref<>::new_reference (result);
}
int