[cffi-devel] must cffi-sys::with-pointer-to-vector-data go?
Martin Simmons
martin at lispworks.com
Thu Jan 26 09:52:57 UTC 2006
>>>>> On Wed, 25 Jan 2006 11:30:33 -0800, James Bielman <jamesjb at jamesjb.com> said:
>
> "Hoehle, Joerg-Cyril" <Joerg-Cyril.Hoehle at t-systems.com> writes:
>
> > cffi-sys::with-pointer-to-vector-data, as is, is highly problematic.
> > Trying to get the base address of a Lisp vector in memory is
> > unportable and subject to subtle errors with a moving GC. I'll try
> > and suggest a better API below.
>
> I think you make a lot of good points here, and I mostly agree with
> your conclusions about using the block interface instead.
>
> I had another idea though---what if, instead of WITH-SHAREABLE-VECTOR
> or whatever, there was a CFFI VECTOR foreign type with an appropriate
> type translator to allow passing a Lisp vector as a pointer to a C
> function? Something like (just making up syntax as I go along here):
>
> (defcfun ("read" unix-read) :int
> (fd :int)
> (buffer (vector (unsigned-byte 8) :out))
> (bufsize :long))
>
> The VECTOR type translator would now have enough information to safely
> disable the GC, pin the vector, or whatever is necessary only during
> the duration of the foreign function call.
This design interacts badly with multithreading if it has to disable the GC.
__Martin
More information about the cffi-devel
mailing list