[racket] FFI: problems using (_list i _string)

From: keydana at gmx.de (keydana at gmx.de)
Date: Sun Jun 5 02:26:08 EDT 2011

Hi all,

I have a problem with FFI which is certainly due to my lack of experience with c, and would very much appreciate any help.
I am using (_list i _string) to pass an array of strings to a c function, but all that ends up on the other side seems to be "nonsense" / random characters.

The c function is described as

boolean OCI_BindArrayOfStrings(OCI_Statement * stmt, const mtext * name, dtext * data, unsigned int len, unsigned int nbelem)	

where mtext and dtext are aliases for char, the way the library was compiled, the second-but-last argument has to indicate the length of the longest string in the array, and the last argument has to be 0 apart from a special case not applicable here.
I've defined it as

(def-ocilib bindstringarray OCI_BindArrayOfStrings : (stmt_ptr : _pointer) (name : _string) (data : (_list i _string)) (maxstrlen : _uint = (getmaxlength data)) (no : _uint) -> (result : _bool))

where maxstrlen gives the length of the longest list member.
The function does not give any error, only the transmitted strings are random/whatever.

I have a "parallel" function using (_list i _int) to pass an array of ints, and this one works fine. Second,  I have no problem passing a single input string, as in

(def-ocilib bindstring OCI_BindString : (stmt_ptr : _pointer) (name : _string) (data : _string) (len : _int = (string-length data)) -> (result : _bool))

so I think I am using the _list construct itself correctly, and the datatype _string itself works fine, too - but there might be special things to pay attention to when passing arrays of strings, perhaps somehow related to field delimitation...?

By the way, I also have another problem understanding the (varname : (_list mode type)) form. If the varname still refers to the racket side, I should be able to pass it to a racket function, as I do with the
(data : (_list i _string))
in the "misbehaving" function cited above, doing (getmaxlength data),  and it works fine. But I also tried using
(data :  (_list io _string (length data)) 
instead, in order to check the correctness of the input strings, putting them out as part of the functions return values, but for doing (length data) I get the error

length: expects argument of type <proper list>; given #<cpointer>

so here data seems to be a c type, not a racket list anymore...

Many thanks in advance for any help regarding the above problem, and understanding the latter point :-)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110605/9f136730/attachment.html>

Posted on the users mailing list.