chicken-users
[Top][All Lists]
Advanced

[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


From: felix winkelmann
Subject: Re: [Chicken-users] ffi - the right way to return a list holding integers and strings
Date: Fri, 6 Jul 2007 11:39:36 +0200

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)));"
                   "C_return(C_h_list(1,C_string2(&sstr,str)));"))

This code works as expected.
It does hopefully allso not leak memory.


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));")


cheers,
felix




reply via email to

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