[plt-scheme] Variable-length C structures in MzScheme
Sorry for the delay --- I didn't see this message until just now.
At Wed, 11 Aug 2004 16:06:37 +0900, Daniel Silva wrote:
> You would insert objects with array_insert:
>
> Scheme_Object* array_insert(int argc, Scheme_Object* argv[])
> {
> MySchemeArrayType* arr = (MySchemeArrayType*)
> arr->items = scheme_realloc(arr->items,
> (arr->len + 1) * sizeof(Scheme_Object*));
> arr->items[arr->len] = argv[0];
> arr->len++;
> return scheme_void;
> }
>
> The scheme_realloc function uses memcpy to fill in old values in the
> new, larger items C array.
>
> I have a situation like this and after some time (and I guess a few GC
> runs), the pointers in items[] point to invalid memory addresses. Is
> it that the GC thinks the array object is smaller than it really is,
> and is then not seeing the pointers in items[]?
No, I don't think that could happen.
Is this still an issue? If so, I think I'd like to see the real code,
including scheme_realloc(), because so many little things can go wrong
in C.
Or, if the code above is the real code, then I think the bug is in the
initialization of arr. It looks like you meant to end the line with
"argv[1];", or something like that.
Matthew