I need to take a Scheme list and pass it to a foreign function, so I
stole the following code from chasen:
#>
char **make_strings(C_word lst)
{
int len, i;
C_word tmp;
char **hlist;
len = C_unfix(C_i_length(lst));
hlist = (char**) malloc(sizeof(char*) * (len + 1));
for(i = 0, tmp = lst; i < len; i++, tmp = C_u_i_cdr(tmp)) {
hlist[i] = C_c_string(C_u_i_car(tmp));
}
hlist[i] = NULL;
}
<#
And I call it like:
(define-external colls_ext c-pointer (make_strings colls))
and then pass colls_ext in my FFI call.
I started seeing artifacts that looked like non-terminated strings
to me, and sure enough:
Note that C_c_string() returns a pointer to the character buffer
of the actual Scheme object and is not zero-terminated.
So I figured, no problem: I'll malloc a new string and strncpy.
Except: Problem: no way to get the length of the Scheme string! I
can't even find documentation for the C_i_length call that the code
I stole uses!
So I have no idea what to do now. Help?
-Robin
--
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
Reason #237 To Learn Lojban: "Homonyms: Their Grate!"
Proud Supporter of the Singularity Institute - http://singinst.org/
_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users