Thanks, Peter. The C code always uses CHICKEN_gc_root_ref() to obtain the reference that it passes to the scheme code.
Also, something that I didn't make very clear: after creating the root as paraphrased in my previous email, the C code successfully passes the struct reference to a scheme procedure several hundred times. But, eventually, immediately after the garbage collector runs, the next call to the scheme function fails. I can see the relative timing of the garbage collector via a call to (set-gc-report! #t). I am not enabling symbol garbage collection, so I don't think that bug you referenced is the problem. Anyway, I just mention the above as clarification. I will do some more investigation and work on coming up with a self-contained example. Thanks a lot for the quick response. Chris On Thu, Mar 19, 2015 at 12:45 PM, Peter Bex <pe...@more-magic.net> wrote: > On Thu, Mar 19, 2015 at 12:21:47PM -0700, Christopher Collins wrote: >> 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>"). > > Hello Christopher, > > How are you accessing the object? If it's from C, you need to use GC_root_ref > to obtain a fresh reference to the object; you can't use a stale reference > to the object you saved in the GC root. > >> 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. > > It would certainly help if you posted a minimal example of the failing > situation. I don't immediately saw anything wrong with the bit you > posted, but it only showed how you saved the object, not how the rest > of the code uses it. > > Also, please be aware of http://bugs.call-cc.org/ticket/1173; you'll only > run into that if you enable symbol GC though, which happens when you > pass -:w to a CHICKEN program or set C_enable_gcweak to nonzero. > > Cheers, > Peter _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users