[Ecls-list] :CSTRING cannot be used anymore as FFI argument(sockets.lisp does not compile)
Goffioul Michael
goffioul at imec.be
Mon Oct 10 04:53:11 UTC 2005
> On Mon, 2005-10-10 at 11:30 +0200, Goffioul Michael wrote:
> > However, I'm not sure this is the right way to do it.
> Especially, the WITH-CSTRING
> > is compiled into a funcall to WITH-CSTRING function; in
> other words, the WITH-CSTRING
> > macro is not expanded before compilation. Juanjo?
>
> The FFI package is not imported into the compiler package. Using
> FFI::WITH-CSTRING seems to do the job.
>
> > Side note: the change in :CSTRING argument handling forbids
> to use such an argument
> > type for an output buffer of the C function (ex:
> gethostname function). So I have no
> > idea is the sockets code is still functional, this needs to
> be checked.
>
> Well, the code should work just as before: if the buffer you
> supply has
> a fill pointer, it will be duplicated and the routine will get the
> pointer to the copy.
OK, but I was talking about the case where the calling routine gave
a :CSTRING argument to the function, expecting the C function to fill
it in with some value. As the C function gets a copy of the argument,
the original one is left untouched, which might not be what the calling
routine expects.
For example:
(def-function ("gethostname" gethostname) ((buf :cstring) (len :int)) :returning :int)
(let ((c (make-some-non-simple-string-of-length 256)))
(gethostbyname c)
;; c does not contain the expected value because gethostname received a copy
)
Clearly, the DEF-FUNCTION call should use (* :char) as argument type,
but I don't know if the sockets module is immune to this problem.
Michael.
More information about the ecl-devel
mailing list