wingo pushed a commit to branch wip-whippet
in repository guile.

commit b6c977995b9aaae045e850a511cdd91540bd1fac
Author: Andy Wingo <wi...@pobox.com>
AuthorDate: Tue Jul 15 12:19:39 2025 +0200

    Trace pointer values conservatively
    
    * libguile/trace.h (scm_trace_pointer): Trace the value.  Either the
    value is managed and is pinned, or it's off-heap; in either case this
    will do the right thing.
    * libguile/foreign.c (scm_procedure_to_pointer): Pin the procedure.
---
 libguile/foreign.c | 4 +++-
 libguile/trace.h   | 7 +++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libguile/foreign.c b/libguile/foreign.c
index 3002ed1e8..2064d5a93 100644
--- a/libguile/foreign.c
+++ b/libguile/foreign.c
@@ -1247,9 +1247,11 @@ SCM_DEFINE (scm_procedure_to_pointer, 
"procedure->pointer", 3, 0, 0,
   void *closure, *executable;
   closure = ffi_closure_alloc (sizeof (ffi_closure), &executable);
 
+  uintptr_t proc_addr = scm_gc_object_address (SCM_I_CURRENT_THREAD, proc);
+
   ffi_status err = ffi_prep_closure_loc ((ffi_closure *) closure, cif,
                                          invoke_closure,
-                                         SCM_UNPACK_POINTER (proc),
+                                         (void *) proc_addr,
                                          executable);
   if (err != FFI_OK)
     {
diff --git a/libguile/trace.h b/libguile/trace.h
index 467989f82..c17b9db84 100644
--- a/libguile/trace.h
+++ b/libguile/trace.h
@@ -300,8 +300,11 @@ scm_trace_pointer (struct scm_pointer *p, TRACE_PARAMS)
   size_t extra_words = scm_pointer_gc_object_count (p);
 
   if (trace)
-    for (size_t i = 0; i < extra_words; i++)
-      TRACE_SLOT (p->gc_objects, i);
+    {
+      scm_trace_field_conservatively (&p->address, TRACE_ARGS);
+      for (size_t i = 0; i < extra_words; i++)
+        TRACE_SLOT (p->gc_objects, i);
+    }
 
   return SIZEOF_WITH_TAIL (p, gc_objects, extra_words);
 }

Reply via email to