]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/guile: wrap scm-arch.c per-arch data in a structure
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 8 Feb 2026 22:04:09 +0000 (17:04 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 9 Feb 2026 17:48:35 +0000 (12:48 -0500)
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<gdbarch>::key<void, gdb::noop_deleter<void>>
         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 <tom@tromey.com>
gdb/guile/scm-arch.c

index 58cacb6f8d7e1768d7b0f482ac1eeb2599e1dca1..db99be81de4d20e5ef4751a0bc1c492c1fbe6698 100644 (file)
@@ -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<gdbarch>::key<void, gdb::noop_deleter<void>>
-     arch_object_data;
+struct arch_object_data_type
+{
+  SCM arch_scm;
+};
+
+static const registry<gdbarch>::key<arch_object_data_type> arch_object_data;
 
 static int arscm_is_arch (SCM);
 \f
@@ -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 <gdb:arch> smob in SELF.