X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=glib%2Fglib.lisp;h=9fa7dcbe7c9ffb3c1a9ba7296d7a26191d4b9d78;hb=02c0f62d617212f4e51224a2f7e76074dac1378e;hp=df8af72d0c1da46a923cd10ea141ddaff0d43bec;hpb=8db173e3df82074b8ca96d00304c4e63b499f598;p=cl-gtk2.git diff --git a/glib/glib.lisp b/glib/glib.lisp old mode 100644 new mode 100755 index df8af72..9fa7dcb --- a/glib/glib.lisp +++ b/glib/glib.lisp @@ -25,7 +25,14 @@ #:g-idle-add-full #:g-idle-add #:g-timeout-add-full - #:g-source-remove) + #:g-source-remove + #:at-finalize + #:with-g-error + #:with-catching-to-g-error + #:g-error-condition + #:g-error-condition-domain + #:g-error-condition-code + #:g-error-condition-message) (:documentation "Cl-gtk2-glib is wrapper for @a[http://library.gnome.org/devel/glib/]{GLib}.")) @@ -37,12 +44,32 @@ (defun register-initializer (key fn) (unless (gethash key *initializers-table*) (setf (gethash key *initializers-table*) t - *initializers* (nconc *initializers* (list fn)))))) + *initializers* (nconc *initializers* (list fn))))) + (defvar *finalizers-table* (make-hash-table :test 'equalp)) + (defvar *finalizers* nil) + (defun register-finalizer (key fn) + (unless (gethash key *finalizers-table*) + (setf (gethash key *finalizers-table*) t + *finalizers* (nconc *finalizers* (list fn)))))) (defun run-initializers () (iter (for fn in *initializers*) (funcall fn))) +(defun run-finalizers () + (iter (for fn in *finalizers*) + (funcall fn))) + +#+sbcl +(pushnew 'run-initializers sb-ext:*init-hooks*) +#+openmcl +(pushnew 'run-initializers ccl:*restore-lisp-functions*) + +#+sbcl +(pushnew 'run-finalizers sb-ext:*save-hooks*) +#+openmcl +(pushnew 'run-finalizers ccl:*save-exit-functions*) + (defmacro at-init ((&rest keys) &body body) " @arg[keys]{list of expression} @@ -64,16 +91,21 @@ In this example, for every @code{class}, @code{(initialize-gobject-class-g-type `(progn (register-initializer (list ,@keys ',body) (lambda () ,@body)) ,@body)) +(defmacro at-finalize ((&rest keys) &body body) + `(register-finalizer (list ,@keys ',body) (lambda () ,@body))) + (eval-when (:compile-toplevel :load-toplevel :execute) (define-foreign-library glib (:unix (:or "libglib-2.0.so.0" "libglib-2.0.so")) - (t "libglib-2.0"))) + (:windows "libglib-2.0-0.dll") + (t (:default "libglib-2.0")))) (use-foreign-library glib) (eval-when (:compile-toplevel :load-toplevel :execute) (define-foreign-library gthread (:unix (:or "libgthread-2.0.so.0" "libgthread-2.0.so")) + (:windows "libgthread-2.0-0.dll") (t "libgthread-2.0"))) (use-foreign-library gthread) @@ -399,12 +431,11 @@ Adds a function to be called whenever there are no higher priority events pendin (defcfun (g-thread-init "g_thread_init") :void (vtable :pointer)) -(defvar *threads-initialized-p* nil) +(defcfun g-thread-get-initialized :boolean) (at-init () - (unless *threads-initialized-p* - (g-thread-init (null-pointer)) - (setf *threads-initialized-p* t))) + (unless (g-thread-get-initialized) + (g-thread-init (null-pointer)))) (defcenum g-thread-priority :g-thread-priority-low