[cffi-devel] with-pointer-to-vector-data

rpgoldman at sift.info rpgoldman at sift.info
Tue Sep 12 12:21:00 UTC 2006


I was trying to use Edi Weitz' drakma http client the other day, and
found that it depends on cl+ssl which, in turn, uses CFFI's
with-pointer-to-vector-data.  

I run ACL, and with-pointer-to-vector-data is commented out in
cffi-allegro.

I *believe* that the following definition is what's needed, but have
not been able to test it well enough to be sure (I don't really know
what might kill it); it was mostly assembled by stumbling through the
Franz FF interface documentation.  IIUC, we needn't do anything to get
a pointer for the C code to use, the important thing is to avoid
having the lisp gc move the byte vector around, which is accomplished
by the use of register-lisp-value.

HTH,
R

for cffi-allegro.lisp:

(defun make-shareable-byte-vector (size)
  "Create a Lisp vector of SIZE bytes that can be passed to
WITH-POINTER-TO-VECTOR-DATA."
  (make-array size :element-type '(unsigned-byte 8)))

;;; this is a crazy whack at trying to make the shared vectors work.
;;; The support functions just make sure that the vector doesn't get
;;; moved around, so we have a stable pointer, and then I think
;;; passing the vector will Just Work\tm.  [2006/09/11:rpg]
(defmacro with-pointer-to-vector-data ((ptr-var vector) &body body)
  "Bind PTR-VAR to a foreign pointer to the data in VECTOR."
  `(unwind-protect
       (progn
         (foreign-functions:register-lisp-value ,vector)
         (let ((,ptr-var ,vector))
           , at body))
     (foreign-functions:unregister-lisp-value ,vector)))



More information about the cffi-devel mailing list