diff options
author | Tom Tromey <tom@tromey.com> | 2017-01-11 16:28:43 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-02-10 12:24:32 -0700 |
commit | 88b6faea9953505e9e8a7a77995c7db5dfb6ac19 (patch) | |
tree | 8c37cbea07dded189647be98286894aa9e172579 /gdb/python/py-objfile.c | |
parent | 7780f18678aeb553778633aeb50f41694f55bf27 (diff) | |
download | gdb-88b6faea9953505e9e8a7a77995c7db5dfb6ac19.zip gdb-88b6faea9953505e9e8a7a77995c7db5dfb6ac19.tar.gz gdb-88b6faea9953505e9e8a7a77995c7db5dfb6ac19.tar.bz2 |
Use gdbpy_ref to simplify some logic
This uses the new gdbpy_ref template to simplify logic in various
parts of the Python layer; for example removing repeated error code or
removing gotos.
gdb/ChangeLog
2017-02-10 Tom Tromey <tom@tromey.com>
* python/py-cmd.c (cmdpy_destroyer): Use gdbpy_ref.
* python/py-breakpoint.c (gdbpy_breakpoint_deleted): Use
gdbpy_ref.
* python/py-type.c (field_new): Use gdbpy_ref.
* python/py-symtab.c (symtab_and_line_to_sal_object): Use
gdbpy_ref.
* python/py-progspace.c (pspy_new): Use gdbpy_ref.
(py_free_pspace): Likewise.
(pspace_to_pspace_object): Likewise.
* python/py-objfile.c (objfpy_new): Use gdbpy_ref.
(py_free_objfile): Likewise.
(objfile_to_objfile_object): Likewise.
* python/py-inferior.c (delete_thread_object): Use
gdbpy_ref.
(infpy_read_memory): Likewise.
(py_free_inferior): Likewise.
* python/py-evtregistry.c (create_eventregistry_object): Use
gdbpy_ref.
* python/py-event.c (create_event_object): Use gdbpy_ref.
Diffstat (limited to 'gdb/python/py-objfile.c')
-rw-r--r-- | gdb/python/py-objfile.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 694fa09..105d88a 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -24,6 +24,7 @@ #include "language.h" #include "build-id.h" #include "symtab.h" +#include "py-ref.h" typedef struct { @@ -227,18 +228,15 @@ objfpy_initialize (objfile_object *self) static PyObject * objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) { - objfile_object *self = (objfile_object *) type->tp_alloc (type, 0); + gdbpy_ref<objfile_object> self ((objfile_object *) type->tp_alloc (type, 0)); - if (self) + if (self != NULL) { - if (!objfpy_initialize (self)) - { - Py_DECREF (self); - return NULL; - } + if (!objfpy_initialize (self.get ())) + return NULL; } - return (PyObject *) self; + return (PyObject *) self.release (); } PyObject * @@ -612,11 +610,9 @@ gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw) static void py_free_objfile (struct objfile *objfile, void *datum) { - objfile_object *object = (objfile_object *) datum; - gdbpy_enter enter_py (get_objfile_arch (objfile), current_language); + gdbpy_ref<objfile_object> object ((objfile_object *) datum); object->objfile = NULL; - Py_DECREF ((PyObject *) object); } /* Return a borrowed reference to the Python object of type Objfile @@ -627,26 +623,22 @@ py_free_objfile (struct objfile *objfile, void *datum) PyObject * objfile_to_objfile_object (struct objfile *objfile) { - objfile_object *object; - - object = (objfile_object *) objfile_data (objfile, objfpy_objfile_data_key); - if (!object) + gdbpy_ref<objfile_object> object + ((objfile_object *) objfile_data (objfile, objfpy_objfile_data_key)); + if (object == NULL) { - object = PyObject_New (objfile_object, &objfile_object_type); - if (object) + object.reset (PyObject_New (objfile_object, &objfile_object_type)); + if (object != NULL) { - if (!objfpy_initialize (object)) - { - Py_DECREF (object); - return NULL; - } + if (!objfpy_initialize (object.get ())) + return NULL; object->objfile = objfile; - set_objfile_data (objfile, objfpy_objfile_data_key, object); + set_objfile_data (objfile, objfpy_objfile_data_key, object.get ()); } } - return (PyObject *) object; + return (PyObject *) object.release (); } int |