From: Simon Marchi Date: Sun, 8 Feb 2026 22:04:09 +0000 (-0500) Subject: gdb/guile: wrap scm-arch.c per-arch data in a structure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efc9a57e40624d209867620779453759fe619f20;p=thirdparty%2Fbinutils-gdb.git gdb/guile: wrap scm-arch.c per-arch data in a structure scm-arch.c uses "void" as a registry data type here: /* Use a 'void *' here because it isn't guaranteed that SCM is a pointer. */ static const registry::key> arch_object_data; This conflicts with my subsequent patch that makes the emplace method return a reference because it's not valid to have `void &`. Circumvent the problem by defining a structure type to use in the registry, instead of storing the SCM directly. I think that makes the code more straightforward and less hacky anyway (at the cost of one extra allocate per gdbarch that you would use in your Guile code...). Change-Id: I8d92234a9b0384098fa066dc79a42195dee7ca04 Approved-By: Tom Tromey --- diff --git a/gdb/guile/scm-arch.c b/gdb/guile/scm-arch.c index 58cacb6f8d7..db99be81de4 100644 --- a/gdb/guile/scm-arch.c +++ b/gdb/guile/scm-arch.c @@ -40,10 +40,12 @@ static const char arch_smob_name[] = "gdb:arch"; /* The tag Guile knows the arch smob by. */ static scm_t_bits arch_smob_tag; -/* Use a 'void *' here because it isn't guaranteed that SCM is a - pointer. */ -static const registry::key> - arch_object_data; +struct arch_object_data_type +{ + SCM arch_scm; +}; + +static const registry::key arch_object_data; static int arscm_is_arch (SCM); @@ -113,22 +115,20 @@ gdbscm_arch_p (SCM scm) SCM arscm_scm_from_arch (struct gdbarch *gdbarch) { - SCM arch_scm; - void *data = arch_object_data.get (gdbarch); + arch_object_data_type *data = arch_object_data.get (gdbarch); if (data == nullptr) { - arch_scm = arscm_make_arch_smob (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); - arch_object_data.set (gdbarch, (void *) arch_scm); + data = arch_object_data.emplace (gdbarch); + data->arch_scm = arch_scm; } - else - arch_scm = (SCM) data; - return arch_scm; + return data->arch_scm; } /* Return the smob in SELF.