/* Python interface to objfiles.
- Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
This file is part of GDB.
objfpy_get_filename (PyObject *self, void *closure)
{
objfile_object *obj = (objfile_object *) self;
- if (obj->objfile && obj->objfile->name)
+
+ if (obj->objfile)
return PyString_Decode (obj->objfile->name, strlen (obj->objfile->name),
host_charset (), NULL);
Py_RETURN_NONE;
objfpy_dealloc (PyObject *o)
{
objfile_object *self = (objfile_object *) o;
+
Py_XDECREF (self->printers);
self->ob_type->tp_free ((PyObject *) self);
}
objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
{
objfile_object *self = (objfile_object *) type->tp_alloc (type, 0);
+
if (self)
{
self->objfile = NULL;
objfpy_get_printers (PyObject *o, void *ignore)
{
objfile_object *self = (objfile_object *) o;
+
Py_INCREF (self->printers);
return self->printers;
}
{
PyObject *tmp;
objfile_object *self = (objfile_object *) o;
+
if (! value)
{
PyErr_SetString (PyExc_TypeError,
- "cannot delete the pretty_printers attribute");
+ _("Cannot delete the pretty_printers attribute."));
return -1;
}
if (! PyList_Check (value))
{
PyErr_SetString (PyExc_TypeError,
- "the pretty_printers attribute must be a list");
+ _("The pretty_printers attribute must be a list."));
return -1;
}
return 0;
}
+/* Implementation of gdb.Objfile.is_valid (self) -> Boolean.
+ Returns True if this object file still exists in GDB. */
+
+static PyObject *
+objfpy_is_valid (PyObject *self, PyObject *args)
+{
+ objfile_object *obj = (objfile_object *) self;
+
+ if (! obj->objfile)
+ Py_RETURN_FALSE;
+
+ Py_RETURN_TRUE;
+}
+
\f
/* Clear the OBJFILE pointer in an Objfile object and remove the
reference. */
static void
-clean_up_objfile (struct objfile *objfile, void *datum)
+py_free_objfile (struct objfile *objfile, void *datum)
{
struct cleanup *cleanup;
objfile_object *object = datum;
object = PyObject_New (objfile_object, &objfile_object_type);
if (object)
{
- PyObject *dict;
-
object->objfile = objfile;
object->printers = PyList_New (0);
gdbpy_initialize_objfile (void)
{
objfpy_objfile_data_key
- = register_objfile_data_with_cleanup (clean_up_objfile);
+ = register_objfile_data_with_cleanup (NULL, py_free_objfile);
if (PyType_Ready (&objfile_object_type) < 0)
return;
Py_INCREF (&objfile_object_type);
- PyModule_AddObject (gdb_module, "Objfile", (PyObject *) &objfile_object_type);
+ PyModule_AddObject (gdb_module, "Objfile",
+ (PyObject *) &objfile_object_type);
}
\f
+static PyMethodDef objfile_object_methods[] =
+{
+ { "is_valid", objfpy_is_valid, METH_NOARGS,
+ "is_valid () -> Boolean.\n\
+Return true if this object file is valid, false if not." },
+
+ { NULL }
+};
+
static PyGetSetDef objfile_getset[] =
{
{ "filename", objfpy_get_filename, NULL,
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- 0, /* tp_methods */
+ objfile_object_methods, /* tp_methods */
0, /* tp_members */
objfile_getset, /* tp_getset */
0, /* tp_base */