summaryrefslogtreecommitdiff
path: root/gdb/python/py-type.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/py-type.c')
-rw-r--r--gdb/python/py-type.c59
1 files changed, 26 insertions, 33 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 7cfc8d1623..d14f9e4285 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1109,36 +1109,38 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
-static const struct objfile_data *typy_objfile_data_key;
-
-static void
-save_objfile_types (struct objfile *objfile, void *datum)
+/* Deleter that saves types when an objfile is being destroyed. */
+struct typy_deleter
{
- type_object *obj = (type_object *) datum;
+ void operator() (type_object *obj)
+ {
+ if (!gdb_python_initialized)
+ return;
- if (!gdb_python_initialized)
- return;
+ /* This prevents another thread from freeing the objects we're
+ operating on. */
+ gdbpy_enter enter_py;
- /* This prevents another thread from freeing the objects we're
- operating on. */
- gdbpy_enter enter_py (objfile->arch ());
+ htab_up copied_types = create_copied_types_hash ();
- htab_up copied_types = create_copied_types_hash ();
+ while (obj)
+ {
+ type_object *next = obj->next;
- while (obj)
- {
- type_object *next = obj->next;
+ htab_empty (copied_types.get ());
- htab_empty (copied_types.get ());
+ obj->type = copy_type_recursive (obj->type, copied_types.get ());
- obj->type = copy_type_recursive (obj->type, copied_types.get ());
+ obj->next = NULL;
+ obj->prev = NULL;
- obj->next = NULL;
- obj->prev = NULL;
+ obj = next;
+ }
+ }
+};
- obj = next;
- }
-}
+static const registry<objfile>::key<type_object, typy_deleter>
+ typy_objfile_data_key;
static void
set_type (type_object *obj, struct type *type)
@@ -1149,11 +1151,10 @@ set_type (type_object *obj, struct type *type)
{
struct objfile *objfile = type->objfile_owner ();
- obj->next = ((type_object *)
- objfile_data (objfile, typy_objfile_data_key));
+ obj->next = typy_objfile_data_key.get (objfile);
if (obj->next)
obj->next->prev = obj;
- set_objfile_data (objfile, typy_objfile_data_key, obj);
+ typy_objfile_data_key.set (objfile, obj);
}
else
obj->next = NULL;
@@ -1172,7 +1173,7 @@ typy_dealloc (PyObject *obj)
struct objfile *objfile = type->type->objfile_owner ();
if (objfile)
- set_objfile_data (objfile, typy_objfile_data_key, type->next);
+ typy_objfile_data_key.set (objfile, type->next);
}
if (type->next)
type->next->prev = type->prev;
@@ -1464,14 +1465,6 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
return type_to_type_object (type);
}
-void _initialize_py_type ();
-void
-_initialize_py_type ()
-{
- typy_objfile_data_key
- = register_objfile_data_with_cleanup (save_objfile_types, NULL);
-}
-
int
gdbpy_initialize_types (void)
{