X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/clg/blobdiff_plain/56ccd5b731e30f2d195cefc4cbf0b8640fac2c92..f86d1eb7db9bb09e2e0d76b1121405e3ee9ab37f:/glib/gcallback.lisp?ds=sidebyside diff --git a/glib/gcallback.lisp b/glib/gcallback.lisp index 0598e44..6fdf198 100644 --- a/glib/gcallback.lisp +++ b/glib/gcallback.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: gcallback.lisp,v 1.30 2006-02-19 19:31:14 espen Exp $ +;; $Id: gcallback.lisp,v 1.34 2006-04-25 21:57:44 espen Exp $ (in-package "GLIB") @@ -29,6 +29,9 @@ (use-prefix "g") ;;;; Callback invokation +(deftype gclosure () 'pointer) +(register-type 'gclosure '|g_closure_get_type|) + (defun register-callback-function (function) (check-type function (or null symbol function)) (register-user-data function)) @@ -45,6 +48,7 @@ (define-callback closure-marshal nil (define-callback signal-emission-hook nil ((invocation-hint pointer) (n-params unsigned-int) (param-values pointer) (callback-id unsigned-int)) + (declare (ignore invocation-hint)) (callback-trampoline callback-id n-params param-values)) (defun callback-trampoline (callback-id n-params param-values &optional @@ -54,14 +58,16 @@ (defun callback-trampoline (callback-id n-params param-values &optional (args (loop for n from 0 below n-params for offset from 0 by +gvalue-size+ - collect (gvalue-get (sap+ param-values offset) t)))) + collect (gvalue-peek (pointer+ param-values offset))))) (unwind-protect (let ((result (apply #'invoke-callback callback-id return-type args))) (when return-type (gvalue-set return-value result))) + ;; TODO: this should be made more general, by adding a type + ;; method to return invalidate functions. (loop for arg in args - when (typep arg 'proxy) + when (typep arg 'struct) do (invalidate-instance arg))))) @@ -161,7 +167,7 @@ (defclass signal-query (struct) (defbinding signal-query (signal-id &optional (signal-query (make-instance 'signal-query))) nil (signal-id unsigned-int) - (signal-query signal-query :return)) + (signal-query signal-query :in/return)) (defun signal-param-types (info) (with-slots (n-params param-types) info @@ -221,7 +227,7 @@ (defun %call-next-handler (n-params types args return-type) for arg in args for type in types for offset from 0 by +gvalue-size+ - do (gvalue-init (sap+ params offset) type arg)) + do (gvalue-init (pointer+ params offset) type arg)) (unwind-protect (if return-type @@ -232,7 +238,7 @@ (defun %call-next-handler (n-params types args return-type) (loop repeat n-params for offset from 0 by +gvalue-size+ - do (gvalue-unset (sap+ params offset))) + do (gvalue-unset (pointer+ params offset))) (deallocate-memory params))))) @@ -317,9 +323,6 @@ (defbinding signal-handler-is-connected-p () boolean (instance ginstance) (handler-id unsigned-int)) -(deftype gclosure () 'pointer) -(register-type 'gclosure '|g_closure_get_type|) - (defbinding (callback-closure-new "clg_callback_closure_new") () gclosure (callback-id unsigned-int) (callback callback) @@ -413,7 +416,7 @@ (defun create-signal-emit-function (signal-id) (loop for arg in (cons object args) for type in param-types - as tmp = params then (sap+ tmp +gvalue-size+) + as tmp = params then (pointer+ tmp +gvalue-size+) do (gvalue-init tmp type arg) finally (if return-type @@ -423,7 +426,7 @@ (defun create-signal-emit-function (signal-id) (%signal-emitv params signal-id detail (make-pointer 0)))) (loop repeat n-params - as tmp = params then (sap+ tmp +gvalue-size+) + as tmp = params then (pointer+ tmp +gvalue-size+) while (gvalue-p tmp) do (gvalue-unset tmp))))))) @@ -469,14 +472,10 @@ (defmacro define-callback-marshal (name return-type args &key (callback-id :last (:first `((callback-id unsigned-int) ,@(mapcar #'list names types))) (:last `(,@(mapcar #'list names types) (callback-id unsigned-int)))) (declare (ignore ,@ignore)) - (invoke-callback callback-id ',return-type ,@params)))) + (invoke-callback callback-id ',return-type ,@(nreverse params))))) (defmacro with-callback-function ((id function) &body body) `(let ((,id (register-callback-function ,function))) (unwind-protect (progn ,@body) (destroy-user-data ,id)))) - -;; For backward compatibility -(defmacro def-callback-marshal (name (return-type &rest args)) - `(define-callback-marshal ,name ,return-type ,args))