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

commit dffbf455591e6b2a0ad74508793dee3998dc99f4
Author: Andy Wingo <wi...@pobox.com>
AuthorDate: Tue Jul 1 15:48:17 2025 +0200

    Rework continuations to be relocatable
    
    * libguile/continuations-internal.h:
    * libguile/continuations.c (scm_i_make_continuation): Allow continuation
    objects to be relocated.
---
 libguile/continuations-internal.h | 10 +++++-----
 libguile/continuations.c          |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libguile/continuations-internal.h 
b/libguile/continuations-internal.h
index 998d3483f..8df441c7e 100644
--- a/libguile/continuations-internal.h
+++ b/libguile/continuations-internal.h
@@ -43,15 +43,15 @@ struct scm_continuation
   SCM root;                 /* continuation root identifier.  */
   struct scm_vm_cont *vm_cont; /* vm's stack and regs */
 
-  /* The offset from the live stack location to this copy.  This is
-     used to adjust pointers from within the copied stack to the stack
-     itself.
+  /* The address of the live stack location from which this copy was
+     taken.  This is used to adjust pointers from within the copied
+     stack to the stack itself.
 
      Thus, when you read a pointer from the copied stack that points
-     into the live stack, you need to add OFFSET so that it points
+     into the live stack, you need to add STACK - BASE so that it points
      into the copy.
   */
-  ptrdiff_t offset;
+  uintptr_t base;
 
   size_t num_stack_items;   /* size of the saved stack.  */
   SCM_STACKITEM stack[];    /* copied stack of size num_stack_items.  */ 
diff --git a/libguile/continuations.c b/libguile/continuations.c
index 46408b406..b516bd0d1 100644
--- a/libguile/continuations.c
+++ b/libguile/continuations.c
@@ -162,7 +162,7 @@ scm_i_make_continuation (scm_thread *thread, struct 
scm_vm_cont *vm_cont)
   src -= stack_size;
 #endif
   memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size);
-  continuation->offset = continuation->stack - src;
+  continuation->base = (uintptr_t) src;
   continuation->num_stack_items = stack_size;
   pin_conservative_roots (thread, continuation->stack,
                           sizeof (SCM_STACKITEM) * stack_size);

Reply via email to