[Ecls-list] C-STRINGs and lisp strings

Juan Jose Garcia Ripoll jlr at mpq.mpg.de
Tue Jun 28 07:59:26 UTC 2005


Goffioul Michael wrote:

>I'm not sure about your last change on ffi.d. If I'm right, the C function
>will be passed a copy of the char array representing the LISP string (at
>least for non-simple string). This means that you can't pass a buffer that
>is intended to be filled by the C function, but this is a pattern that is
>widely used in C API's (or maybe then that C function should be declared
>with (* :char) instead of :cstring argument).
>
Not really. The change is as follows: let us say we have declared 
function "f" to get a :cstring.

1) The user may call the function with a lisp string. Then the should 
not expect to be able to retreive data from the string. Function "f" may 
or may not get a pointer to the lisp string, depending on whether it has 
a fill pointer or not.

2) The user creates a c-string, as mandated by UFFI. Then the routine 
ecl_string_safe_pointer() will do nothing because the array it gets is a 
simple one (i.e. no fill pointer). The function "f" gets then a pointer 
to the c-string, it is free to write on the string and the user will see 
those changes.

Regards,

Juanjo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jlr.vcf
Type: text/x-vcard
Size: 402 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20050628/88b3c49e/attachment.vcf>


More information about the ecl-devel mailing list