chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] What happens to a (non-simple) Scheme object sent to


From: felix winkelmann
Subject: Re: [Chicken-users] What happens to a (non-simple) Scheme object sent to a foreign function?
Date: Mon, 5 Feb 2007 06:17:36 +0100

On 2/4/07, Thomas Christian Chust <address@hidden> wrote:

the address of the C function wrapping the define-external'ed Scheme
procedure is unproblematic, because it will never change. The pointer to
the C string data may become invalid, though, once the program returns
from the library call. In order to make this safe, you would have to
duplicate the string in the C heap (for example using strdup) or you
would have to create a non-garbage-collected copy of the Scheme string
(for example using object-copy) to pass that to the library routine. In
either case you would have to release the string data later on when it
is no longer needed.


Exactly.

Another option would be to create a GC root (CHICKEN_new_gc_root)
and keep it on the C-side (you have to pass the argument string as
a scheme-object, then create the GC-root from it). Later, you can
access the gc root (CHICKEN_gc_root_ref) and use the string. The
gc root will be updated on every garbage collection. You just have
to make sure you free it eventually (or just reuse it).


cheers,
felix




reply via email to

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