chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] GC root gets garbage collected


From: Christopher Collins
Subject: [Chicken-users] GC root gets garbage collected
Date: Thu, 19 Mar 2015 12:21:47 -0700

Hello Chicken users,

I'm struggling with an issue where a scheme object is being unexpectedly
garbage collected.

To provide some context: my program's main() is in C, and the C code calls out
to scheme procedures.  One of these scheme procedures makes and returns a
struct (via the defstruct extension).  I attempt to store the resulting struct
in a gc root, but the struct gets garbage collected anyway, at some
indeterminate time in the future.  Here is what my code (basically) looks like:

;;;; mystruct.scm

(require-extension defstruct)
(defstruct mystruct foo)

(define-external (new_mystruct ()) scheme-object
  (make-mystruct))

/* mystruct.c */

void *
build_mystruct(void)
{
    C_word mystruct;
    void *root;

    root = CHICKEN_new_gc_root();
    mystruct = new_mystruct();
    CHICKEN_gc_root_set(root, mystruct);
    return root;
}

The way I understood it, the returned "mystruct" instance would never get
garbage collected until I explicitly call CHICKEN_delete_gc_root().  I never
actually delete the root (I set a breakpoint on CHICKEN_delete_gc_root in gdb,
just to be sure), but the object gets garbage collected anyway.  The next time
I try to pass the instance of mystruct to a scheme procedure, the procedure
fails because the argument is not of the expected type (when I print the
argument, I see " #<invalid forwarded object>").

I must be confused about how gc roots work.  Am I doing anything that is
obviously wrong?  I can try to post some real code if that would help.

All responses appreciated.

Thanks,
Chris



reply via email to

[Prev in Thread] Current Thread [Next in Thread]