[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] ffi - the right way to return a list holding integer
Re: [Chicken-users] ffi - the right way to return a list holding integers and strings
Fri, 6 Jul 2007 12:40:11 -0500
hostinfo egg also contains an example array0->string-vector which
takes a NULL-terminated array of char* and returns a vector of scheme
strings. It also points you to how to construct a list instead.
Drawback is you have to be careful that you don't allocate too much
data or you'll overflow the nursery.
On 7/6/07, felix winkelmann <address@hidden> wrote:
On 7/6/07, foobar <address@hidden> wrote:
> Great thanks. Just to be sure i've done it correctly.
> Here is an example on how i would return a list of one string element.
> (define return-a-list-with-string-elt
> (foreign-primitive scheme-object ()
> "char str = \"hallo\";"
> "C_word *sstr = C_alloc(C_SIZEOF_STRING(strlen(str)));"
I'd perhaps do it this way:
(foreign-primitive scheme-object ()
"char *str = \"hallo\";"
"C_word *buf = C_alloc(C_SIZEOF_STRING(strlen(str)) + C_SIZEOF_PAIR);"
"C_word str = C_string2(&buf, str);"
"C_return(C_a_i_list(&buf, 1, str));")