[plt-scheme] Documentation Question/Fix for Section 3.1.2 of Inside PLT MzScheme

From: Will M. Farr (farr at MIT.EDU)
Date: Tue Nov 15 19:56:11 EST 2005

Hello all,

The documentation for the hoops to jump through for the 3m collector 
(section 3.1.2 of Inside PLT MzScheme) states:

.
.
.
The MZ_GC_DECL_REG macro expands to a local-variable declaration to 
hold information for the garbage collector. The argument is the number 
of slots to provide for registration. Registering a simple pointer 
requires a single slot, whereas registering an array of pointers 
requires three slots. For example, to register a pointer tmp and an 
array of 10 char *s:

   {
     Scheme_Object *tmp1 = NULL;
     char *a[10];
     int i;
     MZ_GC_DECL_REG(2);

     MZ_GC_ARRAY_VAR_IN_REG(0, a, 10);
     MZ_GC_VAR_IN_REG(3, tmp1);
     /* Clear a before a potential GC: */
     for (i = 0; i < 10; i++) a[i] = NULL;
     ...
     f(a);
     ...
   }

The MZ_GC_ARRAY_VAR_IN_REG macro registers a local array given a 
starting slot, the array variable, and an array size. The 
MZ_GC_VAR_IN_REG takes a slot and simple pointer variable. A local 
variable must not be registered multiple times.

In the above example, the first argument to MZ_GC_VAR_IN_REG is 3 
because the information for a uses the first three slots. Even if a is 
not used after the call to f, a must be registered with the collector 
during the entire call to f, because f presumably uses a until it 
returns.
.
.
.

It clearly takes three registers to hold the GC information for the "a" 
array, so why is the argument to MZ_GC_DECL_REG 2 rather than 4 (3 for 
the array + 1 for tmp)?  Is this a bug in the documentation, or am I 
missing something crucial?

Thanks!
Will



Posted on the users mailing list.