On Thu, Jun 11, 2009 at 8:46 PM, Tobias Rautenkranz<tob...@rautenkranz.ch> wrote: > CLISP returns NIL as null pointer but: > (cffi:pointer-address nil) > gives an error.
I'm considering making %foreign-funcall not return NIL, let me know if the attached patch works for you. -- Luís Oliveira http://student.dei.uc.pt/~lmoliv/
--- old-cffi/src/cffi-clisp.lisp 2009-06-12 00:19:45.000000000 +0100 +++ new-cffi/src/cffi-clisp.lisp 2009-06-12 00:19:45.000000000 +0100 @@ -127,7 +127,7 @@ (defun null-pointer-p (ptr) "Return true if PTR is a null foreign pointer." - (or (null ptr) (zerop (ffi:foreign-address-unsigned ptr)))) + (zerop (ffi:foreign-address-unsigned ptr))) (defun inc-pointer (ptr offset) "Return a pointer pointing OFFSET bytes past PTR." @@ -295,19 +295,22 @@ the function call." (multiple-value-bind (types fargs rettype) (parse-foreign-funcall-args args) - `(funcall - (load-time-value - (handler-case - ,(%foreign-funcall-aux - name - `(ffi:parse-c-type - ',(c-function-type types rettype calling-convention)) - (if (eq library :default) - :default - (library-handle-form library))) - (error (err) - (warn "~A" err)))) - ,@fargs))) + (let ((f `(funcall + (load-time-value + (handler-case + ,(%foreign-funcall-aux + name + `(ffi:parse-c-type + ',(c-function-type types rettype calling-convention)) + (if (eq library :default) + :default + (library-handle-form library))) + (error (err) + (warn "~A" err)))) + ,@fargs))) + (if (eq rettype 'ffi:c-pointer) + `(or ,f (null-pointer)) + f)))) (defmacro %foreign-funcall-pointer (ptr args &key calling-convention) "Similar to %foreign-funcall but takes a pointer instead of a string." --- old-cffi/tests/funcall.lisp 2009-06-12 00:19:45.000000000 +0100 +++ new-cffi/tests/funcall.lisp 2009-06-12 00:19:45.000000000 +0100 @@ -210,4 +218,10 @@ *nil-skipped*) nil) +;;; RT: CLISP returns NIL instead of a null-pointer + +(deftest funcall.pointer-not-nil + (not (null (foreign-funcall "strchr" :string "" :int 1 :pointer))) + t) + ) ;; #-cffi-sys::no-foreign-funcall
_______________________________________________ cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel