[cffi-devel] [PATCH] 64-bit support for Allegro, and allocate stack objects in the static area

John Fremlin jf at msi.co.jp
Mon Jan 5 01:02:56 UTC 2009


Happy new year!

On 64-bit Allegro, run

(cffi:defcfun strerror :string (errnum :int))
(strerror 1)

and you will probably get

Received signal number 4 (Illegal instruction)
   [Condition of type EXCL:SYNCHRONOUS-OPERATING-SYSTEM-SIGNAL]

at least if the returned pointer is more than 32-bits.



The problem is that without this patch, cffi-allegro.lisp does not
support 64-bit pointers. Does the patch address the problem properly?
It seems to work for us.

The use of :unsigned-nat instead of :unsigned-long is recommended by
Franz because on Windows 64-bit :unsigned-long is still 32-bits.


--- a/addons/cffi_0.10.3/src/cffi-allegro.lisp
+++ b/addons/cffi_0.10.3/src/cffi-allegro.lisp
@@ -135,7 +135,7 @@ SIZE-VAR is supplied, it will be bound to SIZE during BODY."
           ;; stack allocation pattern
           `(let ((,size-var ,size))
              (declare (ignorable ,size-var))
-             (ff:with-stack-fobject (,var '(:array :char ,size))
+             (ff:with-stack-fobject (,var '(:array :char ,size) :allocation :foreign-static-gc)
                (let ((,var (ff:fslot-address ,var)))
                  ;; (excl::stack-allocated-p var) => T
                  , at body))))
@@ -263,12 +263,12 @@ SIZE-VAR is supplied, it will be bound to SIZE during BODY."
           :unsigned-long) 'integer)
         (:float 'single-float)
         (:double 'double-float)
-        (:foreign-address :foreign-address)
+        (:foreign-address 'integer)
         (:void 'null))))
 
 (defun foreign-allegro-type (type)
   (if (eq type :foreign-address)
-      nil
+      :unsigned-nat
       type))
 
 (defun allegro-type-pair (type)




More information about the cffi-devel mailing list