aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-progspace.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-10-18 11:38:10 -0600
committerTom Tromey <tom@tromey.com>2022-07-28 14:16:50 -0600
commit08b8a139c9e8adcb4ec12a8a17e5836b8b5acb63 (patch)
treee1050b58dcebee1150881f43f64c1c186955d240 /gdb/guile/scm-progspace.c
parent8f83e7b9262e08fa43ca6e645337511c68ddc52a (diff)
downloadgdb-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-progspace.c')
-rw-r--r--gdb/guile/scm-progspace.c47
1 files changed, 14 insertions, 33 deletions
diff --git a/gdb/guile/scm-progspace.c b/gdb/guile/scm-progspace.c
index c48da76..7a197d7 100644
--- a/gdb/guile/scm-progspace.c
+++ b/gdb/guile/scm-progspace.c
@@ -52,7 +52,18 @@ static const char pspace_smob_name[] = "gdb:progspace";
/* The tag Guile knows the pspace smob by. */
static scm_t_bits pspace_smob_tag;
-static const struct program_space_data *psscm_pspace_data_key;
+/* Progspace registry cleanup handler for when a progspace is deleted. */
+struct psscm_deleter
+{
+ void operator() (pspace_smob *p_smob)
+ {
+ p_smob->pspace = NULL;
+ scm_gc_unprotect_object (p_smob->containing_scm);
+ }
+};
+
+static const registry<program_space>::key<pspace_smob, psscm_deleter>
+ psscm_pspace_data_key;
/* Return the list of pretty-printers registered with P_SMOB. */
@@ -111,27 +122,6 @@ psscm_make_pspace_smob (void)
return p_scm;
}
-/* Clear the progspace pointer in P_SMOB and unprotect the object from GC. */
-
-static void
-psscm_release_pspace (pspace_smob *p_smob)
-{
- p_smob->pspace = NULL;
- scm_gc_unprotect_object (p_smob->containing_scm);
-}
-
-/* Progspace registry cleanup handler for when a progspace is deleted. */
-
-static void
-psscm_handle_pspace_deleted (struct program_space *pspace, void *datum)
-{
- pspace_smob *p_smob = (pspace_smob *) datum;
-
- gdb_assert (p_smob->pspace == pspace);
-
- psscm_release_pspace (p_smob);
-}
-
/* Return non-zero if SCM is a <gdb:progspace> object. */
static int
@@ -157,7 +147,7 @@ psscm_pspace_smob_from_pspace (struct program_space *pspace)
{
pspace_smob *p_smob;
- p_smob = (pspace_smob *) program_space_data (pspace, psscm_pspace_data_key);
+ p_smob = psscm_pspace_data_key.get (pspace);
if (p_smob == NULL)
{
SCM p_scm = psscm_make_pspace_smob ();
@@ -165,7 +155,7 @@ psscm_pspace_smob_from_pspace (struct program_space *pspace)
p_smob = (pspace_smob *) SCM_SMOB_DATA (p_scm);
p_smob->pspace = pspace;
- set_program_space_data (pspace, psscm_pspace_data_key, p_smob);
+ psscm_pspace_data_key.set (pspace, p_smob);
scm_gc_protect_object (p_smob->containing_scm);
}
@@ -418,12 +408,3 @@ gdbscm_initialize_pspaces (void)
gdbscm_define_functions (pspace_functions, 1);
}
-
-void _initialize_scm_progspace ();
-void
-_initialize_scm_progspace ()
-{
- psscm_pspace_data_key
- = register_program_space_data_with_cleanup (NULL,
- psscm_handle_pspace_deleted);
-}