#! /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-25 13:01:10.000000000 +0800
+++ cffi-20070901/src/cffi-lispworks.lisp	2007-09-25 13:21:52.000000000 +0800
@@ -65,12 +65,14 @@
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (mapc (lambda (feature) (pushnew feature *features*))
         '(;; Backend mis-features.
+          #-lispworks-64bit
           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))
+    #+lispworks-64bit
+    (:long-long       '(:long :long))
+    #+lispworks-64bit
+    (:unsigned-long-long '(:unsigned :long :long))
     (:float           :float)
     (:double          :double)
     (:pointer         :pointer)
@@ -173,9 +179,10 @@
 #+#.(cl:if (cl:find-symbol "FOREIGN-TYPED-AREF" "FLI") '(and) '(or))
 (defun convert-foreign-typed-aref-type (cffi-type)
   (ecase cffi-type
-    ((:char :short :int :long)
+    ((:char :short :int :long #+lispworks-64bit :long-long)
      `(signed-byte ,(* 8 (%foreign-type-size cffi-type))))
-    ((:unsigned-char :unsigned-short :unsigned-int :unsigned-long)
+    ((:unsigned-char :unsigned-short :unsigned-int :unsigned-long
+                     #+lispworks-64bit :unsigned-long-long)
      `(unsigned-byte ,(* 8 (%foreign-type-size cffi-type))))
     (:float 'single-float)
     (:double 'double-float)))
@@ -192,7 +199,10 @@
 (define-compiler-macro %mem-ref (&whole form ptr type &optional (off 0))
   (if (constantp type)
       (let ((type (eval type)))
-        (if (eql type :pointer)
+        (if (or (eql type :pointer)
+                #+(and lispworks-64bit lispworks5.0)
+		(member type '(:long :unsigned-long
+                               :long-long :unsigned-long-long)))
             (let ((fli-type (convert-foreign-type type))
                   (ptr-form (if (eql off 0) ptr `(inc-pointer ,ptr ,off))))
               `(fli:dereference ,ptr-form :type ',fli-type))
@@ -225,7 +235,10 @@
   (if (constantp type)
       (once-only (val)
         (let ((type (eval type)))
-          (if (eql type :pointer)
+          (if (or (eql type :pointer)
+                  #+(and lispworks-64bit lispworks5.0)
+                  (member type '(:long :unsigned-long
+                                 :long-long :unsigned-long-long)))
               (let ((fli-type (convert-foreign-type type))
                     (ptr-form (if (eql off 0) ptr `(inc-pointer ,ptr ,off))))
                 `(setf (fli:dereference ,ptr-form :type ',fli-type) ,val))
