diff options
author | Tom Tromey <tom@tromey.com> | 2020-10-18 11:38:10 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-07-28 14:16:50 -0600 |
commit | 08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63 (patch) | |
tree | e1050b58dcebee1150881f43f64c1c186955d240 /gdb/python/py-symbol.c | |
parent | 8f83e7b9262e08fa43ca6e645337511c68ddc52a (diff) | |
download | gdb-08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63.zip gdb-08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63.tar.gz gdb-08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63.tar.bz2 |
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.
Diffstat (limited to 'gdb/python/py-symbol.c')
-rw-r--r-- | gdb/python/py-symbol.c | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 23495b6..e5fe5cf 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -50,7 +50,26 @@ struct symbol_object { } \ } while (0) -static const struct objfile_data *sympy_objfile_data_key; +/* A deleter that is used when an objfile is about to be freed. */ +struct symbol_object_deleter +{ + void operator() (symbol_object *obj) + { + while (obj) + { + symbol_object *next = obj->next; + + obj->symbol = NULL; + obj->next = NULL; + obj->prev = NULL; + + obj = next; + } + } +}; + +static const registry<objfile>::key<symbol_object, symbol_object_deleter> + sympy_objfile_data_key; static PyObject * sympy_str (PyObject *self) @@ -307,11 +326,10 @@ set_symbol (symbol_object *obj, struct symbol *symbol) { struct objfile *objfile = symbol->objfile (); - obj->next = ((symbol_object *) - objfile_data (objfile, sympy_objfile_data_key)); + obj->next = sympy_objfile_data_key.get (objfile); if (obj->next) obj->next->prev = obj; - set_objfile_data (objfile, sympy_objfile_data_key, obj); + sympy_objfile_data_key.set (objfile, obj); } else obj->next = NULL; @@ -350,10 +368,7 @@ sympy_dealloc (PyObject *obj) else if (sym_obj->symbol != NULL && sym_obj->symbol->is_objfile_owned () && sym_obj->symbol->symtab () != NULL) - { - set_objfile_data (sym_obj->symbol->objfile (), - sympy_objfile_data_key, sym_obj->next); - } + sympy_objfile_data_key.set (sym_obj->symbol->objfile (), sym_obj->next); if (sym_obj->next) sym_obj->next->prev = sym_obj->prev; sym_obj->symbol = NULL; @@ -596,38 +611,6 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw) return return_list.release (); } -/* This function is called when an objfile is about to be freed. - Invalidate the symbol as further actions on the symbol would result - in bad data. All access to obj->symbol should be gated by - SYMPY_REQUIRE_VALID which will raise an exception on invalid - symbols. */ -static void -del_objfile_symbols (struct objfile *objfile, void *datum) -{ - symbol_object *obj = (symbol_object *) datum; - while (obj) - { - symbol_object *next = obj->next; - - obj->symbol = NULL; - obj->next = NULL; - obj->prev = NULL; - - obj = next; - } -} - -void _initialize_py_symbol (); -void -_initialize_py_symbol () -{ - /* Register an objfile "free" callback so we can properly - invalidate symbol when an object file that is about to be - deleted. */ - sympy_objfile_data_key - = register_objfile_data_with_cleanup (NULL, del_objfile_symbols); -} - int gdbpy_initialize_symbols (void) { |