On Fri, Apr 4, 2008 at 5:57 PM, Barry Fishman <[EMAIL PROTECTED]> wrote:
> As of (From the CLISP src/Changelog):
>
>  2006-10-05  Sam Steingold  <[EMAIL PROTECTED]>
>
>         merged LOOKUP-FOREIGN-FUNCTION & FOREIGN-LIBRARY-FUNCTION into
>         FIND-FOREIGN-FUNCTION; LOOKUP-FOREIGN-VARIABLE &
>         FOREIGN-LIBRARY-VARIABLE into FIND-FOREIGN-VARIABLE
>         ...
>
>  This includes CVS releases starting with clisp-2.41.
>
>  FFI::FOREIGN-LIBRARY-FUNCTION and FFI::FOREIGN-LIBRARY-VARIABLE have
>  effectively been made legasy.
>
>  In the current CVS head (but not the last clisp-2.44.1 release) these
>  functions have quietly disappeared.  This causes problems with the CLISP
>  CVS head in cffi-clisp.lisp.

The attached patch should fix that while maintaining backwards
compatibility. Unfortunately, CVS CLISP (my copy of the ChangeLog says
2008-03-25) dumps core on the callback tests. I'm using x86-64. Can
anyone reproduce this behaviour?

[1]> (asdf:oos 'asdf:test-op :cffi)
...
*** - handle_fault error2 ! address = 0x8 not in [0x333a9f000,0x333d4b160) !
SIGSEGV cannot be cured. Fault address = 0x8.
Permanently allocated: 161560 bytes.
Currently in use: 5352408 bytes.
Free space: 324432 bytes.
Segmentation fault (core dumped)

[EMAIL PROTECTED]:~$ clisp --version
GNU CLISP 2.45 (2008-04-04) (built 3415563584) (memory 3415563829)
Software: GNU C 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
gcc -g -O2 -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit
-Wreturn-type -Wmissing-declarations -Wno-sign-compare -O
-falign-functions=4 -DUNICODE -DDYNAMIC_FFI -I. -x none -lreadline
-lncurses -ldl -lavcall -lcallback  -lsigsegv
SAFETY=0 TYPECODES WIDE GENERATIONAL_GC SPVW_BLOCKS SPVW_MIXED TRIVIALMAP_MEMORY
libsigsegv 2.4
libreadline 5.2
Features:
(READLINE REGEXP SYSCALLS I18N LOOP COMPILER CLOS MOP CLISP ANSI-CL COMMON-LISP
 LISP=CL INTERPRETER SOCKETS GENERIC-STREAMS LOGICAL-PATHNAMES SCREEN FFI
 GETTEXT UNICODE BASE-CHAR=CHARACTER PC386 UNIX)
C Modules: (clisp i18n syscalls regexp readline)
Installation directory: /home/luis/Software/lib/clisp-2.45/
User language: ENGLISH
Machine: X86_64 (X86_64) haden [127.0.1.1]

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
--- old-cffi/src/cffi-clisp.lisp	2008-04-05 04:10:45.000000000 +0100
+++ new-cffi/src/cffi-clisp.lisp	2008-04-05 04:10:45.000000000 +0100
@@ -276,6 +276,35 @@
     `(,(find-cffi-symbol '#:foreign-library-handle)
        (,(find-cffi-symbol '#:get-foreign-library) ',name))))
 
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  ;; version 2.40 (CVS 2006-09-03, to be more precise) added a
+  ;; PROPERTIES argument to FFI::FOREIGN-LIBRARY-FUNCTION.
+  (defun post-2.40-ffi-interface-p ()
+    (let ((f-l-f (find-symbol (string '#:foreign-library-function) '#:ffi)))
+      (if (and f-l-f (= (length (ext:arglist f-l-f)) 5))
+          '(:and)
+          '(:or))))
+  ;; FFI::FOREIGN-LIBRARY-FUNCTION and FFI::FOREIGN-LIBRARY-VARIABLE
+  ;; were deprecated in 2.41 and removed in 2.45.
+  (defun post-2.45-ffi-interface-p ()
+    (if (find-symbol (string '#:foreign-library-function) '#:ffi)
+        '(:or)
+        '(:and))))
+
+#+#.(cffi-sys::post-2.45-ffi-interface-p)
+(defun %foreign-funcall-aux (name type library)
+  `(ffi::find-foreign-function ,name ,type nil ,library nil nil))
+
+#-#.(cffi-sys::post-2.45-ffi-interface-p)
+(defun %foreign-funcall-aux (name type library)
+  `(ffi::foreign-library-function
+    ,name ,library nil
+    #+#.(cffi-sys::post-2.40-ffi-interface-p)
+    nil
+    ,type))
+
+;;;;; ADD MACRO FOR (FFI:PARSE-C-TYPE (C-FUNCTION-TYPE ...))
+
 (defmacro %foreign-funcall (name args &key library calling-convention)
   "Invoke a foreign function called NAME, taking pairs of
 foreign-type/value pairs from ARGS.  If a single element is left
@@ -286,21 +315,13 @@
     `(funcall
       (load-time-value
        (handler-case
-           (ffi::foreign-library-function
-            ,name
-            ,(if (eq library :default)
+           ,(%foreign-funcall-aux
+             name
+             `(ffi:parse-c-type
+               ',(c-function-type types rettype calling-convention))
+             (if (eq library :default)
                  :default
-                 (library-handle-form library))
-            nil
-            ;; As of version 2.40 (CVS 2006-09-03, to be more precise),
-            ;; FFI::FOREIGN-LIBRARY-FUNCTION takes an additional
-            ;; 'PROPERTIES' argument.
-            #+#.(cl:if (cl:= (cl:length (ext:arglist
-                                         'ffi::foreign-library-function)) 5)
-                       '(and) '(or))
-            nil
-            (ffi:parse-c-type ',(c-function-type
-                                 types rettype calling-convention)))
+                 (library-handle-form library)))
          (error (err)
            (warn "~A" err))))
       ,@fargs)))
@@ -383,6 +404,9 @@
 (defun %load-foreign-library (name path)
   "Load a foreign library from PATH."
   (declare (ignore name))
+  #+#.(cffi-sys::post-2.45-ffi-interface-p)
+  (ffi:open-foreign-library path)
+  #-#.(cffi-sys::post-2.45-ffi-interface-p)
   (ffi::foreign-library path))
 
 (defun %close-foreign-library (handle)
@@ -398,5 +422,7 @@
   "Returns a pointer to a foreign symbol NAME."
   (prog1 (ignore-errors
            (ffi:foreign-address
-            (ffi::foreign-library-variable
-             name library nil nil)))))
+            #+#.(cffi-sys::post-2.45-ffi-interface-p)
+            (ffi::find-foreign-variable name nil library nil nil)
+            #-#.(cffi-sys::post-2.45-ffi-interface-p)
+            (ffi::foreign-library-variable name library nil nil)))))

_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to