chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objec


From: felix winkelmann
Subject: Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objects
Date: Thu, 18 Dec 2008 08:53:30 +0100

On Mon, Dec 15, 2008 at 10:34 PM, Alejandro Forero Cuervo
<address@hidden> wrote:
>
> One idea I had was to do the following (plus tweaks to call_the_proc
> to de-ref the GC root):
>
>  (define create-closure
>    (let ((obj ((foreign-lambda* c-closure ((scheme-object proc))
>  #<<EOF
>       void *root = CHICKEN_new_gc_root();
>       CHICKEN_gc_root_set(root, proc);
>       return(create_closure(root, call_the_proc));
>  EOF
>                ) proc)))
>      (set-finalizer! (c-closure-ptr obj)
>        (foreign-lambda* void ((c-closure obj))
>          "CHICKEN_delete_gc_root(obj->data);"))
>      obj))
>
> I actually don't think this would work: there could be loops if the
> Scheme-level closure depends on an object that is eventually modified
> to depend on the C-level closure object (the object returned by
> create-closure) so even if there are no other references to these
> objects, they won't be GCed.
>
> So how should I solve this problem?
>

I'm not sure that I can follow this - the interdependencies are confusing
(for me). To retain a safe reference to a Scheme-level object from C
can only be done via GC-roots, otherwise the reference will be lost on
the next GC. You also have to make sure to use `foreign-safe-lambda[*]'
for the C function that does or may invoke a callback. Of course, any
references to C data (which may refer to Scheme data via GC-roots)
are not seen by the GC or finalization mechanism, so will not "loop"
into that direction. A maximal simplified working piece of code would
be helpful to make it easier to understand (for me).


cheers,
felix




reply via email to

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