On Fri, Jan 9, 2009 at 12:51 AM, John Fremlin <j...@msi.co.jp> wrote:
>> The page 
>> <http://www.franz.com/support/documentation/8.1/doc/foreign-functions.htm>
>> documents the :FOREIGN-ADDRESS type.
>
> I kept trying to point out that this was being used by cffi as a *Lisp*
> type not a *foreign-type*. It is not a Lisp type.

Oh, yes, that part was clearly broken. But it was being used a foreign
type as well, but even then it doesn't seem to work in all contexts.


> The other change from my patch was about allocating the stack objects in
> a space that will not be moved by the GC.

I've applied that already, thanks! IIUC, :FOREIGN-STATIC-GC is only
relevant when WITH-STACK-FOBJECT fails to stack allocate, in which
case it actually allocates on the heap.

Hmm, now that I read the documentation more carefully, it seems that
if WITH-STACK-FOBJECT allocates on the heap then it won't deallocate
the object and we should be using WITH-STATIC-FOBJECT instead. Does
that sound right? If it does, I'll apply the attached patch during the
weekend or so.


> Is it a necessary according to the CFFI semantics of with-foreign-object?

Indeed.

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
diff -rN -u old-cffi/src/cffi-allegro.lisp new-cffi/src/cffi-allegro.lisp
--- old-cffi/src/cffi-allegro.lisp	2009-01-09 01:43:06.000000000 +0000
+++ new-cffi/src/cffi-allegro.lisp	2009-01-09 01:43:07.000000000 +0000
@@ -130,27 +130,21 @@
 SIZE-VAR is supplied, it will be bound to SIZE during BODY."
   (unless size-var
     (setf size-var (gensym "SIZE")))
-   #+(version>= 8 1)
-   (cond ((and (constantp size) (<= (eval size) ff:*max-stack-fobject-bytes*))
-          ;; stack allocation
-          `(let ((,size-var ,size))
-             (declare (ignorable ,size-var))
-             (ff:with-stack-fobject (,var '(:array :char ,size)
-                                          :allocation :foreign-static-gc)
-               ;; (excl::stack-allocated-p var) => T
-               (let ((,var (ff:fslot-address ,var)))
-                 ,@body))))
-         (t
-          ;; heap allocation
-          `(let ((,size-var ,size))
-             (ff:with-stack-fobject (,var :char :allocation :c :size ,size-var)
-               (unwind-protect
-                    (progn ,@body)
-                 (ff:free-fobject ,var))))))
-   #-(version>= 8 1)
-   `(let ((,size-var ,size))
-      (ff:with-stack-fobject (,var :char :c ,size-var)
-        ,@body)))
+  #+(version>= 8 1)
+  (when (and (constantp size) (<= (eval size) ff:*max-stack-fobject-bytes*))
+    (return-from with-foreign-pointer
+      `(let ((,size-var ,size))
+         (declare (ignorable ,size-var))
+         (ff:with-static-fobject (,var '(:array :char ,size)
+                                       :allocation :foreign-static-gc)
+           ;; (excl::stack-allocated-p var) => T
+           (let ((,var (ff:fslot-address ,var)))
+             ,@body)))))
+  `(let* ((,size-var ,size)
+          (,var (ff:allocate-fobject :char :c ,size-var)))
+     (unwind-protect
+          (progn ,@body)
+       (ff:free-fobject ,var))))
 
 ;;;# Shareable Vectors
 ;;;
_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to