diff options
Diffstat (limited to 'gdb/python/py-progspace.c')
-rw-r--r-- | gdb/python/py-progspace.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index e4b029b..c1b1cac 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -34,6 +34,9 @@ typedef struct /* The pretty-printer list of functions. */ PyObject *printers; + + /* The type-printer list. */ + PyObject *type_printers; } pspace_object; static PyTypeObject pspace_object_type; @@ -66,6 +69,7 @@ pspy_dealloc (PyObject *self) pspace_object *ps_self = (pspace_object *) self; Py_XDECREF (ps_self->printers); + Py_XDECREF (ps_self->type_printers); self->ob_type->tp_free (self); } @@ -84,6 +88,13 @@ pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) Py_DECREF (self); return NULL; } + + self->type_printers = PyList_New (0); + if (!self->type_printers) + { + Py_DECREF (self); + return NULL; + } } return (PyObject *) self; } @@ -126,6 +137,48 @@ pspy_set_printers (PyObject *o, PyObject *value, void *ignore) return 0; } +/* Get the 'type_printers' attribute. */ + +static PyObject * +pspy_get_type_printers (PyObject *o, void *ignore) +{ + pspace_object *self = (pspace_object *) o; + + Py_INCREF (self->type_printers); + return self->type_printers; +} + +/* Set the 'type_printers' attribute. */ + +static int +pspy_set_type_printers (PyObject *o, PyObject *value, void *ignore) +{ + PyObject *tmp; + pspace_object *self = (pspace_object *) o; + + if (! value) + { + PyErr_SetString (PyExc_TypeError, + "cannot delete the type_printers attribute"); + return -1; + } + + if (! PyList_Check (value)) + { + PyErr_SetString (PyExc_TypeError, + "the type_printers attribute must be a list"); + return -1; + } + + /* Take care in case the LHS and RHS are related somehow. */ + tmp = self->type_printers; + Py_INCREF (value); + self->type_printers = value; + Py_XDECREF (tmp); + + return 0; +} + /* Clear the PSPACE pointer in a Pspace object and remove the reference. */ @@ -168,6 +221,13 @@ pspace_to_pspace_object (struct program_space *pspace) return NULL; } + object->type_printers = PyList_New (0); + if (!object->type_printers) + { + Py_DECREF (object); + return NULL; + } + set_program_space_data (pspace, pspy_pspace_data_key, object); } } @@ -197,6 +257,8 @@ static PyGetSetDef pspace_getset[] = "The progspace's main filename, or None.", NULL }, { "pretty_printers", pspy_get_printers, pspy_set_printers, "Pretty printers.", NULL }, + { "type_printers", pspy_get_type_printers, pspy_set_type_printers, + "Type printers.", NULL }, { NULL } }; |