chiark / gitweb /
New binding GVALUE-P and some other changes
[clg] / glib / gparam.lisp
index 1d90291a8dadd46bf3610cf842c4bd325bf78ed1..1c0473c6f0b83427f596203a3891549d0858b929 100644 (file)
 ;; 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: gparam.lisp,v 1.9 2004-11-06 21:39:58 espen Exp $
+;; $Id: gparam.lisp,v 1.13 2005-01-03 16:42:03 espen Exp $
 
 (in-package "GLIB")
 
 (deftype gvalue () 'pointer)
 
+(register-type 'gvalue "GValue")
+
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
 
@@ -41,11 +43,11 @@ (defun gvalue-init (gvalue type &optional (value nil value-p))
   (when value-p
     (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
 
-(defun gvalue-new (type &optional (value nil value-p))
+(defun gvalue-new (&optional type (value nil value-p))
   (let ((gvalue (allocate-memory +gvalue-size+)))
-    (if value-p
-       (gvalue-init gvalue type value)
-      (gvalue-init gvalue type))
+    (cond
+     (value-p (gvalue-init gvalue type value))
+     (type (gvalue-init gvalue type)))
     gvalue))
 
 (defun gvalue-free (gvalue &optional (unset-p t))
@@ -66,6 +68,18 @@ (defun gvalue-set (gvalue value)
    value gvalue +gvalue-value-offset+)
   value)
 
+(defbinding (gvalue-p "g_type_check_value") () boolean
+  (location pointer))
+
+(defmacro with-gvalue ((gvalue &optional type value) &body body)
+  `(let ((,gvalue ,(if type
+                      `(gvalue-new ,type ,value)
+                    `(gvalue-new))))
+    (unwind-protect
+        (progn
+          ,@body
+          ,(unless type `(gvalue-get ,gvalue)))
+      (gvalue-free ,gvalue))))
 
 
 (deftype param-flag-type ()
@@ -125,12 +139,12 @@ (defclass param (ginstance)
     :allocation :virtual
     :getter "g_param_spec_get_nick"
     :reader param-nickname
-    :type string)
+    :type (copy-of string))
    (documentation
     :allocation :virtual
     :getter "g_param_spec_get_blurb"
     :reader param-documentation
-    :type string))
+    :type (copy-of string)))
   (:metaclass param-spec-class))