#! /bin/sh /usr/share/dpatch/dpatch-run
## 10_lispworks.dpatch by  <binghe@localhost.localdomain>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad cffi-20070901~/src/cffi-lispworks.lisp cffi-20070901/src/cffi-lispworks.lisp
--- cffi-20070901~/src/cffi-lispworks.lisp	2007-09-22 22:33:06.000000000 +0800
+++ cffi-20070901/src/cffi-lispworks.lisp	2007-09-22 22:35:58.000000000 +0800
@@ -65,12 +65,14 @@
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (mapc (lambda (feature) (pushnew feature *features*))
         '(;; Backend mis-features.
+          #-#.(cl:if (fli::64bit-long-p) '(and) '(or))
           cffi-features:no-long-long
           ;; OS/CPU features.
           #+darwin  cffi-features:darwin
           #+unix    cffi-features:unix
           #+win32   cffi-features:windows
           #+harp::pc386   cffi-features:x86
+          #+harp::amd64   cffi-features:x86-64
           #+harp::powerpc cffi-features:ppc32
           )))
 
@@ -163,6 +165,10 @@
     (:unsigned-int    '(:unsigned :int))
     (:long            :long)
     (:unsigned-long   '(:unsigned :long))
+    #+#.(cl:if (fli::64bit-long-p) '(and) '(or))
+    (:long-long '(:long :long))
+    #+#.(cl:if (fli::64bit-long-p) '(and) '(or))
+    (:unsigned-long-long '(:unsigned :long :long))
     (:float           :float)
     (:double          :double)
     (:pointer         :pointer)
@@ -170,7 +176,8 @@
 
 ;;; Convert a CFFI type keyword to a symbol suitable for passing to
 ;;; FLI:FOREIGN-TYPED-AREF.
-#+#.(cl:if (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI") '(and) '(or))
+#+#.(cl:if (cl:and (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI")
+                   (cl:not (fli::64bit-long-p))) '(and) '(or))
 (defun convert-foreign-typed-aref-type (cffi-type)
   (ecase cffi-type
     ((:char :short :int :long)
@@ -188,7 +195,8 @@
 
 ;;; In LispWorks versions where FLI:FOREIGN-TYPED-AREF is fbound, use
 ;;; it instead of FLI:DEREFERENCE in the optimizer for %MEM-REF.
-#+#.(cl:if (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI") '(and) '(or))
+#+#.(cl:if (cl:and (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI")
+                   (cl:not (fli::64bit-long-p))) '(and) '(or))
 (define-compiler-macro %mem-ref (&whole form ptr type &optional (off 0))
   (if (constantp type)
       (let ((type (eval type)))
@@ -204,7 +212,8 @@
 
 ;;; Open-code the call to FLI:DEREFERENCE when TYPE is constant at
 ;;; macroexpansion time, when FLI:FOREIGN-TYPED-AREF is not available.
-#-#.(cl:if (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI") '(and) '(or))
+#-#.(cl:if (cl:and (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI")
+                   (cl:not (fli::64bit-long-p))) '(and) '(or))
 (define-compiler-macro %mem-ref (&whole form ptr type &optional (off 0))
   (if (constantp type)
       (let ((ptr-form (if (eql off 0) ptr `(inc-pointer ,ptr ,off)))
@@ -220,7 +229,8 @@
 
 ;;; In LispWorks versions where FLI:FOREIGN-TYPED-AREF is fbound, use
 ;;; it instead of FLI:DEREFERENCE in the optimizer for %MEM-SET.
-#+#.(cl:if (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI") '(and) '(or))
+#+#.(cl:if (cl:and (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI")
+                   (cl:not (fli::64bit-long-p))) '(and) '(or))
 (define-compiler-macro %mem-set (&whole form val ptr type &optional (off 0))
   (if (constantp type)
       (once-only (val)
@@ -239,7 +249,8 @@
 
 ;;; Open-code the call to (SETF FLI:DEREFERENCE) when TYPE is constant
 ;;; at macroexpansion time.
-#-#.(cl:if (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI") '(and) '(or))
+#-#.(cl:if (cl:and (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI")
+                   (cl:not (fli::64bit-long-p))) '(and) '(or))
 (define-compiler-macro %mem-set (&whole form val ptr type &optional (off 0))
   (if (constantp type)
       (once-only (val)
