aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-block.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-block.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-block.c')
-rw-r--r--gdb/guile/scm-block.c75
1 files changed, 33 insertions, 42 deletions
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index 41954c7..a29c2db 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -76,7 +76,37 @@ static scm_t_bits block_syms_progress_smob_tag;
/* The "next!" block syms iterator method. */
static SCM bkscm_next_symbol_x_proc;
-static const struct objfile_data *bkscm_objfile_data_key;
+/* This is called when an objfile is about to be freed.
+ Invalidate the block as further actions on the block would result
+ in bad data. All access to b_smob->block should be gated by
+ checks to ensure the block is (still) valid. */
+struct bkscm_deleter
+{
+ /* Helper function for bkscm_del_objfile_blocks to mark the block
+ as invalid. */
+
+ static int
+ bkscm_mark_block_invalid (void **slot, void *info)
+ {
+ block_smob *b_smob = (block_smob *) *slot;
+
+ b_smob->block = NULL;
+ b_smob->objfile = NULL;
+ return 1;
+ }
+
+ void operator() (htab_t htab)
+ {
+ if (htab != NULL)
+ {
+ htab_traverse_noresize (htab, bkscm_mark_block_invalid, NULL);
+ htab_delete (htab);
+ }
+ }
+};
+
+static const registry<objfile>::key<htab, bkscm_deleter>
+ bkscm_objfile_data_key;
/* Administrivia for block smobs. */
@@ -108,13 +138,13 @@ bkscm_eq_block_smob (const void *ap, const void *bp)
static htab_t
bkscm_objfile_block_map (struct objfile *objfile)
{
- htab_t htab = (htab_t) objfile_data (objfile, bkscm_objfile_data_key);
+ htab_t htab = bkscm_objfile_data_key.get (objfile);
if (htab == NULL)
{
htab = gdbscm_create_eqable_gsmob_ptr_map (bkscm_hash_block_smob,
bkscm_eq_block_smob);
- set_objfile_data (objfile, bkscm_objfile_data_key, htab);
+ bkscm_objfile_data_key.set (objfile, htab);
}
return htab;
@@ -326,35 +356,6 @@ bkscm_scm_to_block (SCM block_scm, int arg_pos, const char *func_name,
return NULL;
}
-/* Helper function for bkscm_del_objfile_blocks to mark the block
- as invalid. */
-
-static int
-bkscm_mark_block_invalid (void **slot, void *info)
-{
- block_smob *b_smob = (block_smob *) *slot;
-
- b_smob->block = NULL;
- b_smob->objfile = NULL;
- return 1;
-}
-
-/* This function is called when an objfile is about to be freed.
- Invalidate the block as further actions on the block would result
- in bad data. All access to b_smob->block should be gated by
- checks to ensure the block is (still) valid. */
-
-static void
-bkscm_del_objfile_blocks (struct objfile *objfile, void *datum)
-{
- htab_t htab = (htab_t) datum;
-
- if (htab != NULL)
- {
- htab_traverse_noresize (htab, bkscm_mark_block_invalid, NULL);
- htab_delete (htab);
- }
-}
/* Block methods. */
@@ -800,13 +801,3 @@ gdbscm_initialize_blocks (void)
gdbscm_scm_from_c_string ("\
Internal function to assist the block symbols iterator."));
}
-
-void _initialize_scm_block ();
-void
-_initialize_scm_block ()
-{
- /* Register an objfile "free" callback so we can properly
- invalidate blocks when an object file is about to be deleted. */
- bkscm_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, bkscm_del_objfile_blocks);
-}