diff options
Diffstat (limited to 'gdb/python/py-utils.c')
-rw-r--r-- | gdb/python/py-utils.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 3579720..bf50e37 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -373,3 +373,23 @@ gdb_py_int_as_long (PyObject *obj, long *result) *result = PyInt_AsLong (obj); return ! (*result == -1 && PyErr_Occurred ()); } + + + +/* Generic implementation of the __dict__ attribute for objects that + have a dictionary. The CLOSURE argument should be the type object. + This only handles positive values for tp_dictoffset. */ + +PyObject * +gdb_py_generic_dict (PyObject *self, void *closure) +{ + PyObject *result; + PyTypeObject *type_obj = closure; + char *raw_ptr; + + raw_ptr = (char *) self + type_obj->tp_dictoffset; + result = * (PyObject **) raw_ptr; + + Py_INCREF (result); + return result; +} |