I agree that your change should work, but I don't really like it
because it's not easy to figure when a string will be copied and when
not and this will make the debugging of program really hard.
I don't understand why we do not simply put a NUL at
string.fillp. When string is a simple string, the fillp will anyway
index the char after the end of string.
When string has fillp, lisp seems to print it till the filp pointer
and this printable part is what I expect the C function will get, no
matter how long the string really is.
When we just put the NUL at the end of the (visible) string, the rule
will be very simple to understand and follows the rule of the least
estonishement: any string you feed in the FFI is suceptible to be
modified and this is exactly what any C programmer expects.
Sorry to disturb again... :)
On Tue, Jun 28, 2005 at 04:58:51PM +0200, Juan Jose Garcia Ripoll wrote:
> 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.
> fn:Juan Jose Garcia-Ripoll
> n:Garcia-Ripoll;Juan Jose
> org:Max-Planck-Institut for Quantum Optics;Theory Division
> adr;quoted-printable:;;Hans-Kopfermann-Str. 1;Garching bei M=C3=BCnchen;;85748;Germany