After some internal discussion, we have come up with this patch, which brings back the foreign-address keyword. The keyword is not a foreign-type and is not used as one.
Pointers passed to or returned from foreign functions use :foreign-address, and there is no second Lisp type. (The original unpatched CFFI incorrectly uses nil as the foreign-type and :foreign-address as the Lisp type.)
This means that you can pass either and address or a Lisp array directly as the pointer.
Note that there cannot be a second type in the pair after the foreign-address keyword, if we want to use this functionality,
It should be safer than the ff:allocate-object method and it looks nicer too.
John Fremlin jf@msi.co.jp writes:
Any idea how safe or not this is? I am going to ask support at Franz.
(defun make-shareable-byte-vector (size) "Create a Lisp vector of SIZE bytes can passed to ;WITH-POINTER-TO-VECTOR-DATA." (ff:allocate-fobject :unsigned-char :lisp size)) ; (defmacro with-pointer-to-vector-data ((ptr-var vector) &body body) "Bind PTR-VAR to a foreign pointer to the data in VECTOR." `(let ((,ptr-var (ff:fslot-address-typed :unsigned-char :lisp ,vector))) ,@body))
cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel