diff options
author | Doug Evans <dje@google.com> | 2014-10-13 12:24:54 -0700 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2014-10-13 12:24:54 -0700 |
commit | 4e1bbde013bae26b550a047baa8c6b999d811f23 (patch) | |
tree | 70c101860d545587972bda7864b9e7ff0c53c1f1 /gdb/python/py-objfile.c | |
parent | 5b69e3572d1ee8e8e6e1991fd07f87a96c48746d (diff) | |
download | binutils-4e1bbde013bae26b550a047baa8c6b999d811f23.zip binutils-4e1bbde013bae26b550a047baa8c6b999d811f23.tar.gz binutils-4e1bbde013bae26b550a047baa8c6b999d811f23.tar.bz2 |
Remove some code duplication in py-objfile.c, py-progspace.c.
gdb/ChangeLog:
* py-objfile.c (objfpy_initialize): New function.
(objfpy_new, objfile_to_objfile_object): Call it.
* py-progspace.c (pspy_initialize): New function.
(pspy_new, pspace_to_pspace_object): Call it.
Diffstat (limited to 'gdb/python/py-objfile.c')
-rw-r--r-- | gdb/python/py-objfile.c | 82 |
1 files changed, 32 insertions, 50 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 5d00d62..df29691 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -74,6 +74,33 @@ objfpy_dealloc (PyObject *o) Py_TYPE (self)->tp_free (self); } +/* Initialize an objfile_object. + The result is a boolean indicating success. */ + +static int +objfpy_initialize (objfile_object *self) +{ + self->objfile = NULL; + + self->printers = PyList_New (0); + if (self->printers == NULL) + return 0; + + self->frame_filters = PyDict_New (); + if (self->frame_filters == NULL) + return 0; + + self->type_printers = PyList_New (0); + if (self->type_printers == NULL) + return 0; + + self->xmethods = PyList_New (0); + if (self->xmethods == NULL) + return 0; + + return 1; +} + static PyObject * objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) { @@ -81,36 +108,13 @@ objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) if (self) { - self->objfile = NULL; - - self->printers = PyList_New (0); - if (!self->printers) - { - Py_DECREF (self); - return NULL; - } - - self->frame_filters = PyDict_New (); - if (!self->frame_filters) - { - Py_DECREF (self); - return NULL; - } - - self->type_printers = PyList_New (0); - if (!self->type_printers) - { - Py_DECREF (self); - return NULL; - } - - self->xmethods = PyList_New (0); - if (self->xmethods == NULL) + if (!objfpy_initialize (self)) { Py_DECREF (self); return NULL; } } + return (PyObject *) self; } @@ -280,6 +284,7 @@ py_free_objfile (struct objfile *objfile, void *datum) representing OBJFILE. If the object has already been created, return it. Otherwise, create it. Return NULL and set the Python error on failure. */ + PyObject * objfile_to_objfile_object (struct objfile *objfile) { @@ -291,36 +296,13 @@ objfile_to_objfile_object (struct objfile *objfile) object = PyObject_New (objfile_object, &objfile_object_type); if (object) { - object->objfile = objfile; - - object->printers = PyList_New (0); - if (!object->printers) - { - Py_DECREF (object); - return NULL; - } - - object->frame_filters = PyDict_New (); - if (!object->frame_filters) - { - Py_DECREF (object); - return NULL; - } - - object->type_printers = PyList_New (0); - if (!object->type_printers) - { - Py_DECREF (object); - return NULL; - } - - object->xmethods = PyList_New (0); - if (object->xmethods == NULL) + if (!objfpy_initialize (object)) { Py_DECREF (object); return NULL; } + object->objfile = objfile; set_objfile_data (objfile, objfpy_objfile_data_key, object); } } |