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/guile/scm-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/guile/scm-symbol.c')
-rw-r--r-- | gdb/guile/scm-symbol.c | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c index 55eac3c..0b96e5a 100644 --- a/gdb/guile/scm-symbol.c +++ b/gdb/guile/scm-symbol.c @@ -49,7 +49,37 @@ static SCM block_keyword; static SCM domain_keyword; static SCM frame_keyword; -static const struct objfile_data *syscm_objfile_data_key; +/* This 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 s_smob->symbol should be gated by + syscm_get_valid_symbol_smob_arg_unsafe which will raise an exception on + invalid symbols. */ +struct syscm_deleter +{ + /* Helper function for syscm_del_objfile_symbols to mark the symbol + as invalid. */ + + static int + syscm_mark_symbol_invalid (void **slot, void *info) + { + symbol_smob *s_smob = (symbol_smob *) *slot; + + s_smob->symbol = NULL; + return 1; + } + + void operator() (htab_t htab) + { + if (htab != NULL) + { + htab_traverse_noresize (htab, syscm_mark_symbol_invalid, NULL); + htab_delete (htab); + } + } +}; + +static const registry<objfile>::key<htab, syscm_deleter> + syscm_objfile_data_key; static struct gdbarch_data *syscm_gdbarch_data_key; struct syscm_gdbarch_data @@ -105,12 +135,12 @@ syscm_get_symbol_map (struct symbol *symbol) { struct objfile *objfile = symbol->objfile (); - htab = (htab_t) objfile_data (objfile, syscm_objfile_data_key); + htab = syscm_objfile_data_key.get (objfile); if (htab == NULL) { htab = gdbscm_create_eqable_gsmob_ptr_map (syscm_hash_symbol_smob, syscm_eq_symbol_smob); - set_objfile_data (objfile, syscm_objfile_data_key, htab); + syscm_objfile_data_key.set (objfile, htab); } } else @@ -291,35 +321,6 @@ syscm_get_valid_symbol_arg_unsafe (SCM self, int arg_pos, return s_smob->symbol; } -/* Helper function for syscm_del_objfile_symbols to mark the symbol - as invalid. */ - -static int -syscm_mark_symbol_invalid (void **slot, void *info) -{ - symbol_smob *s_smob = (symbol_smob *) *slot; - - s_smob->symbol = NULL; - return 1; -} - -/* 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 s_smob->symbol should be gated by - syscm_get_valid_symbol_smob_arg_unsafe which will raise an exception on - invalid symbols. */ - -static void -syscm_del_objfile_symbols (struct objfile *objfile, void *datum) -{ - htab_t htab = (htab_t) datum; - - if (htab != NULL) - { - htab_traverse_noresize (htab, syscm_mark_symbol_invalid, NULL); - htab_delete (htab); - } -} /* Symbol methods. */ @@ -823,11 +824,6 @@ void _initialize_scm_symbol (); void _initialize_scm_symbol () { - /* Register an objfile "free" callback so we can properly - invalidate symbols when an object file is about to be deleted. */ - syscm_objfile_data_key - = register_objfile_data_with_cleanup (NULL, syscm_del_objfile_symbols); - /* Arch-specific symbol data. */ syscm_gdbarch_data_key = gdbarch_data_register_post_init (syscm_init_arch_symbols); |