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.

diff --git a/addons/cffi/src/cffi-allegro.lisp b/addons/cffi/src/cffi-allegro.lisp
index a900222..da62471 100644
--- a/addons/cffi/src/cffi-allegro.lisp
+++ b/addons/cffi/src/cffi-allegro.lisp
@@ -155,11 +155,11 @@ SIZE-VAR is supplied, it will be bound to SIZE during BODY."
 (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))
+  (make-array size :element-type '(unsigned-byte 8) :allocation :static-reclaimable))
 
 (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)))
+  `(let ((,ptr-var ,vector))
      ,@body))
 
 ;;;# Dereferencing
@@ -250,8 +250,16 @@ SIZE-VAR is supplied, it will be bound to SIZE during BODY."
     (:void 'null)))
 
 (defun allegro-type-pair (cffi-type)
-  (let ((ftype (convert-foreign-type cffi-type)))
-    (list ftype (convert-to-lisp-type ftype))))
+  (case cffi-type
+    (:pointer (list :foreign-address
+                                        ; special magic :foreign-address
+                                        ; keyword for arguments to
+                                        ; functions, so that we can pass
+                                        ; either an address or an array
+                    ))
+    (t
+     (let ((ftype (convert-foreign-type cffi-type)))
+       (list ftype (convert-to-lisp-type ftype))))))
 
 #+ignore
 (defun note-named-foreign-function (symbol name types rettype)


John Fremlin <j...@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
_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to