Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] gdb/guile: wrap scm-arch.c per-arch data in a structure
@ 2026-02-08 22:04 simon.marchi
  2026-02-08 22:04 ` [PATCH 2/3] gdb/registry: make registry::key::emplace return a reference simon.marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: simon.marchi @ 2026-02-08 22:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

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
---
 gdb/guile/scm-arch.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gdb/guile/scm-arch.c b/gdb/guile/scm-arch.c
index 58cacb6f8d7e..db99be81de4d 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<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.

base-commit: 7619807a1fdea3bf984437c6c8f8f1859b474fd0
-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-02-09 18:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-08 22:04 [PATCH 1/3] gdb/guile: wrap scm-arch.c per-arch data in a structure simon.marchi
2026-02-08 22:04 ` [PATCH 2/3] gdb/registry: make registry::key::emplace return a reference simon.marchi
2026-02-09 16:12   ` Tom Tromey
2026-02-08 22:04 ` [PATCH 3/3] gdb/registry: add registry::key::try_emplace simon.marchi
2026-02-09 16:16   ` Tom Tromey
2026-02-09 18:18     ` Simon Marchi
2026-02-09 18:28       ` Tom Tromey
2026-02-09 16:11 ` [PATCH 1/3] gdb/guile: wrap scm-arch.c per-arch data in a structure Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox