X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/clg/blobdiff_plain/73572c12ccd49c661d06287903bfa725f5fd93a5..c96c452a4938c33e24bb9736810b0c7bd9e7940d:/glib/ffi.lisp diff --git a/glib/ffi.lisp b/glib/ffi.lisp index 36d0e7b..759f43d 100644 --- a/glib/ffi.lisp +++ b/glib/ffi.lisp @@ -15,7 +15,7 @@ ;; License along with this library; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -;; $Id: ffi.lisp,v 1.13 2005-02-03 23:09:03 espen Exp $ +;; $Id: ffi.lisp,v 1.16 2005-02-22 17:27:25 espen Exp $ (in-package "GLIB") @@ -128,8 +128,10 @@ (defun %defbinding (foreign-name lisp-name lambda-list return-type docs args) (alien-parameters `(addr ,var)) (alien-bindings `(,var ,declaration - ,@(when (eq style :in-out) - (list (to-alien-form expr type))))) + ,@(cond + ((eq style :in-out) (list (to-alien-form expr type))) + ((eq declaration 'system-area-pointer) + (list '(make-pointer 0)))))) (return-values (from-alien-form var type))) ((eq style :return) (alien-types declaration) @@ -807,3 +809,56 @@ (defmethod reader-function ((type (eql 'copy-of)) &rest args) (defmethod writer-function ((type (eql 'copy-of)) &rest args) (declare (ignore type)) (writer-function (first args))) + + +(defmethod alien-type ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + (alien-type 'pointer)) + +(defmethod size-of ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + (size-of 'pointer)) + +(defmethod to-alien-form (callback (type (eql 'callback)) &rest args) + (declare (ignore type args)) + #+cmu `(callback ,callback) + #+sbcl `(sb-alien:alien-function-sap ,callback)) + +(defmethod to-alien-function ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + #+cmu #'(lambda (callback) (callback callback)) + #+sbcl #'sb-alien:alien-function-sap) + +#+cmu +(defun find-callback (pointer) + (find pointer alien::*callbacks* :key #'callback-trampoline :test #'sap=)) + +(defmethod from-alien-form (pointer (type (eql 'callback)) &rest args) + (declare (ignore type args)) + #+cmu `(find-callback ,pointer) + #+sbcl `(sb-alien::%find-alien-function ,pointer)) + +(defmethod from-alien-function ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + #+cmu #'find-callback + #+sbcl #'sb-alien::%find-alien-function) + +(defmethod writer-function ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + (let ((writer (writer-function 'pointer)) + (to-alien (to-alien-function 'callback))) + #'(lambda (callback location &optional (offset 0)) + (funcall writer (funcall to-alien callback) location offset)))) + +(defmethod reader-function ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + (let ((reader (reader-function 'pointer)) + (from-alien (from-alien-function 'callback))) + #'(lambda (location &optional (offset 0)) + (let ((pointer (funcall reader location offset))) + (unless (null-pointer-p pointer) + (funcall from-alien pointer)))))) + +(defmethod unbound-value ((type (eql 'callback)) &rest args) + (declare (ignore type args)) + (values t nil))