#include "language.h"
#include "build-id.h"
#include "symtab.h"
+#include "py-ref.h"
typedef struct
{
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 *
static PyObject *
objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = { "file_name", NULL };
+ static const char *keywords[] = { "file_name", NULL };
objfile_object *obj = (objfile_object *) self;
const char *file_name;
OBJFPY_REQUIRE_VALID (obj);
- if (!PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
return NULL;
TRY
PyObject *
gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = { "name", "by_build_id", NULL };
+ static const char *keywords[] = { "name", "by_build_id", NULL };
const char *name;
PyObject *by_build_id_obj = NULL;
int by_build_id;
struct objfile *objfile;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
- &name, &PyBool_Type, &by_build_id_obj))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
+ &name, &PyBool_Type, &by_build_id_obj))
return NULL;
by_build_id = 0;
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
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
{ NULL }
};
-static PyGetSetDef objfile_getset[] =
+static gdb_PyGetSetDef objfile_getset[] =
{
{ "__dict__", gdb_py_generic_dict, NULL,
"The __dict__ for this objfile.", &objfile_object_type },