diff options
author | Tom Tromey <tom@tromey.com> | 2022-06-01 15:31:15 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-08-04 13:28:04 -0600 |
commit | cb275538dbddfbb3c2c372a665ac48e6f617ea33 (patch) | |
tree | 7bc54ff4fc92c9b1cee74c2d7b9ae452b5ffec8b /gdb/guile/scm-arch.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.bz2 |
Use registry in gdbarch
gdbarch implements its own registry-like approach. This patch changes
it to instead use registry.h. It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.
The main benefit of this change is that it introduces type safety to
the gdbarch registry. It also removes a bunch of code.
One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup. This
doesn't seem very important to me, though.
Diffstat (limited to 'gdb/guile/scm-arch.c')
-rw-r--r-- | gdb/guile/scm-arch.c | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/gdb/guile/scm-arch.c b/gdb/guile/scm-arch.c index 529043a..4c636aa 100644 --- a/gdb/guile/scm-arch.c +++ b/gdb/guile/scm-arch.c @@ -41,7 +41,10 @@ static const char arch_smob_name[] = "gdb:arch"; /* The tag Guile knows the arch smob by. */ static scm_t_bits arch_smob_tag; -static struct gdbarch_data *arch_object_data = NULL; +/* Use a 'void *' here because it isn't guaranteed that SCM is a + pointer. */ +static const registry<gdbarch>::key<void, gdb::noop_deleter<void>> + arch_object_data; static int arscm_is_arch (SCM); @@ -105,30 +108,28 @@ gdbscm_arch_p (SCM scm) return scm_from_bool (arscm_is_arch (scm)); } -/* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch - post init registration mechanism (gdbarch_data_register_post_init). */ - -static void * -arscm_object_data_init (struct gdbarch *gdbarch) -{ - SCM arch_scm = arscm_make_arch_smob (gdbarch); - - /* This object lasts the duration of the GDB session, so there is no - call to scm_gc_unprotect_object for it. */ - scm_gc_protect_object (arch_scm); - - return (void *) arch_scm; -} - /* Return the <gdb:arch> object corresponding to GDBARCH. The object is cached in GDBARCH so this is simple. */ SCM arscm_scm_from_arch (struct gdbarch *gdbarch) { - SCM a_scm = (SCM) gdbarch_data (gdbarch, arch_object_data); + SCM arch_scm; + void *data = arch_object_data.get (gdbarch); + if (data == nullptr) + { + arch_scm = arscm_make_arch_smob (gdbarch); - return a_scm; + /* This object lasts the duration of the GDB session, so there + is no call to scm_gc_unprotect_object for it. */ + scm_gc_protect_object (arch_scm); + + arch_object_data.set (gdbarch, (void *) arch_scm); + } + else + arch_scm = (SCM) data; + + return arch_scm; } /* Return the <gdb:arch> smob in SELF. @@ -651,11 +652,3 @@ gdbscm_initialize_arches (void) gdbscm_define_functions (arch_functions, 1); } - -void _initialize_scm_arch (); -void -_initialize_scm_arch () -{ - arch_object_data - = gdbarch_data_register_post_init (arscm_object_data_init); -} |