[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Chicken C interface
From: |
Felix |
Subject: |
Re: [Chicken-users] Chicken C interface |
Date: |
Wed, 05 Jun 2013 23:39:11 +0200 (CEST) |
From: "pluijzer ." <address@hidden>
Subject: [Chicken-users] Chicken C interface
Date: Wed, 5 Jun 2013 17:10:41 +0200
> Hello everybody,
>
> I was planning to use Chicken Scheme in a fashion more similar to Guile and
> Lua. i.e. passing Scheme Data Objects from Chicken to C and back using the
> C interface.
>
> I am a little confused though as how to have a C function return a Scheme
> List that is seen by the garbage collector.
>
> For example, is the code below correct, will the list be seen by the
> garbage collector? And if not, is there correct way to do this.
>
> #>
> C_word give_12()
> {
> C_word *mem = C_alloc(C_SIZEOF_LIST(2));
> C_word list = C_list(&mem, 2, C_fix(1), C_fix(2));
> return list;
> }
> <#
> (print ((foreign-lambda scheme-object "give_12")))
As written in the other message: C_alloc is just a wrapper around alloca(3),
so returning from the function invalidates or overwrites the data. A later
(minor) garbage collection may actually recover the data, but it is not
certain that it happens. See
http://api.call-cc.org/doc/foreign/access/foreign-primitive
for a variant that allows stack-allocation.
cheers,
felix
- Re: [Chicken-users] Chicken C interface, (continued)
- Re: [Chicken-users] Chicken C interface, Dan Leslie, 2013/06/06
- Re: [Chicken-users] Chicken C interface, Felix, 2013/06/06
- Re: [Chicken-users] Chicken C interface, Felix, 2013/06/06
- Re: [Chicken-users] Chicken C interface, Thomas Chust, 2013/06/06
- Re: [Chicken-users] Chicken C interface, Felix, 2013/06/06
- Re: [Chicken-users] Chicken C interface, Thomas Chust, 2013/06/06
Re: [Chicken-users] Chicken C interface,
Felix <=
Re: [Chicken-users] Chicken C interface, Kristian Lein-Mathisen, 2013/06/05
Re: [Chicken-users] Chicken C interface, db05, 2013/06/05