Missing GC_PROTECTs in reference implementation Martin Gasbichler 06 May 2003 14:55 UTC

The reference implementation for Scheme 48 lacks some annotations for
the garbage collector. Here is a patch:

--- mrg32k3a-b.c.orig   Tue May  6 16:35:56 2003
+++ mrg32k3a-b.c        Tue May  6 16:40:06 2003
@@ -113,6 +113,9 @@
 s48_value mrg32k3a_pack_state1(s48_value state) {
   s48_value result;
   state_t   s;
+  S48_DECLARE_GC_PROTECT(1);
+
+  S48_GC_PROTECT_1(state); /* s48_extract_integer may GC */

 #define REF(i) (double)s48_extract_integer(S48_VECTOR_REF(state, (long)(i)))

@@ -126,6 +129,8 @@

 #undef REF

+  S48_GC_UNPROTECT();
+
   /* box s into a Scheme object */
   result = S48_MAKE_VALUE(state_t);
   S48_SET_VALUE(result, state_t, s);
@@ -133,9 +138,12 @@
 }

 s48_value mrg32k3a_unpack_state1(s48_value state) {
-  s48_value result;
+  s48_value result = S48_UNSPECIFIC;
   state_t   s;

+  S48_DECLARE_GC_PROTECT(1);
+  S48_GC_PROTECT_1(result);
+
   /* unbox s from the Scheme object */
   s = S48_EXTRACT_VALUE(state, state_t);

@@ -156,6 +164,8 @@
   SET(10, s.x22);

 #undef SET
+
+  S48_GC_UNPROTECT();

   return result;
 }

Unlike documented in the manual, s48_extract_integer may cause a GC (if
Scheme 48 needs a bignum to represent the number).

--
Martin