Rewrite registry.h
This rewrites registry.h, removing all the macros and replacing it with relatively ordinary template classes. The result is less code than the previous setup. It replaces large macros with a relatively straightforward C++ class, and now manages its own cleanup. The existing type-safe "key" class is replaced with the equivalent template class. This approach ended up requiring relatively few changes to the users of the registry code in gdb -- code using the key system just required a small change to the key's declaration. All existing users of the old C-like API are now converted to use the type-safe API. This mostly involved changing explicit deletion functions to be an operator() in a deleter class. The old "save/free" two-phase process is removed, and replaced with a single "free" phase. No existing code used both phases. The old "free" callbacks took a parameter for the enclosing container object. However, this wasn't truly needed and is removed here as well.
This commit is contained in:
parent
8f83e7b926
commit
08b8a139c9
64 changed files with 664 additions and 1052 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue