[Ecls-list] C-STRINGs and lisp strings

dan at sof.ch dan at sof.ch
Tue Jun 28 10:02:18 UTC 2005


> Well, it depends on what you mean by the "least astonishment". If we are 
> to follow UFFI (http://uffi.b9.com/manual/strings.html) you should only 
> use C-STRINGs or foreign strings (i.e. arrays of characters as provided 
> by the ffi)

Damned! Now you know that english is not my mother's language...
> 
> "UFFI has functions to two types of C-compatible strings: cstring and 
> foreign strings. cstrings are used only as parameters to and from 
> functions. In some implementations a cstring is not a foreign type but 
> rather the Lisp string itself. On other platforms a cstring is a newly 
> allocated foreign vector for storing characters. The following is an 
> example of using cstrings to both send and return a value."
> 
> "In contrast, foreign strings are always a foreign vector of characters 
> which have memory allocated. Thus, if you need to allocate memory to 
> hold the return value of a string, you must use a foreign string and not 
> a cstring. The following is an example of using a foreign string for a 
> return value."
> 
> So the rules are simple
>    - only use c-strings and arrays of characters when calling C functions
>    - convert explicitely c-strings to lisp ones and viceversa
>    - never pass lisp strings directly.
>    - anything else may or may not work as expected.
>    - if the C function has allocated the string for you, use a (char *) 
> type
>    - if the C function expects a malloced string, use also (char *)
> 
> This guarantees portable code. And sorry for being so picky, but I would 
> not like ECL to be incompatible with the rest of the lisp world.
> 

Let say I did not say anything :). I should have better read the UFFI
specs.

BTW have you heard of the HelloC fork of UFFI ?

http://www.alphageeksinc.com/cgi-bin/lispnyc.cgi?HelloC

The callback interface may be something interesting to have...

Best regards.


-- 
Courage, fuyons...




More information about the ecl-devel mailing list