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-objfile.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-objfile.c')
-rw-r--r-- | gdb/guile/scm-objfile.c | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/gdb/guile/scm-objfile.c b/gdb/guile/scm-objfile.c index 760d5aa..1a87dcf 100644 --- a/gdb/guile/scm-objfile.c +++ b/gdb/guile/scm-objfile.c @@ -49,7 +49,18 @@ static const char objfile_smob_name[] = "gdb:objfile"; /* The tag Guile knows the objfile smob by. */ static scm_t_bits objfile_smob_tag; -static const struct objfile_data *ofscm_objfile_data_key; +/* Objfile registry cleanup handler for when an objfile is deleted. */ +struct ofscm_deleter +{ + void operator() (objfile_smob *o_smob) + { + o_smob->objfile = NULL; + scm_gc_unprotect_object (o_smob->containing_scm); + } +}; + +static const registry<objfile>::key<objfile_smob, ofscm_deleter> + ofscm_objfile_data_key; /* Return the list of pretty-printers registered with O_SMOB. */ @@ -101,27 +112,6 @@ ofscm_make_objfile_smob (void) return o_scm; } -/* Clear the OBJFILE pointer in O_SMOB and unprotect the object from GC. */ - -static void -ofscm_release_objfile (objfile_smob *o_smob) -{ - o_smob->objfile = NULL; - scm_gc_unprotect_object (o_smob->containing_scm); -} - -/* Objfile registry cleanup handler for when an objfile is deleted. */ - -static void -ofscm_handle_objfile_deleted (struct objfile *objfile, void *datum) -{ - objfile_smob *o_smob = (objfile_smob *) datum; - - gdb_assert (o_smob->objfile == objfile); - - ofscm_release_objfile (o_smob); -} - /* Return non-zero if SCM is a <gdb:objfile> object. */ static int @@ -147,7 +137,7 @@ ofscm_objfile_smob_from_objfile (struct objfile *objfile) { objfile_smob *o_smob; - o_smob = (objfile_smob *) objfile_data (objfile, ofscm_objfile_data_key); + o_smob = ofscm_objfile_data_key.get (objfile); if (o_smob == NULL) { SCM o_scm = ofscm_make_objfile_smob (); @@ -155,7 +145,7 @@ ofscm_objfile_smob_from_objfile (struct objfile *objfile) o_smob = (objfile_smob *) SCM_SMOB_DATA (o_scm); o_smob->objfile = objfile; - set_objfile_data (objfile, ofscm_objfile_data_key, o_smob); + ofscm_objfile_data_key.set (objfile, o_smob); scm_gc_protect_object (o_smob->containing_scm); } @@ -424,11 +414,3 @@ gdbscm_initialize_objfiles (void) gdbscm_define_functions (objfile_functions, 1); } - -void _initialize_scm_objfile (); -void -_initialize_scm_objfile () -{ - ofscm_objfile_data_key - = register_objfile_data_with_cleanup (NULL, ofscm_handle_objfile_deleted); -} |