chiark / gitweb /
Added with-gvalue macro
[clg] / glib / gparam.lisp
index 1d90291a8dadd46bf3610cf842c4bd325bf78ed1..4579a3299725631388cf710b7edc326faf34440b 100644 (file)
@@ -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: gparam.lisp,v 1.9 2004-11-06 21:39:58 espen Exp $
+;; $Id: gparam.lisp,v 1.10 2004-11-12 15:01:42 espen Exp $
 
 (in-package "GLIB")
 
@@ -66,6 +66,15 @@ (defun gvalue-set (gvalue value)
    value gvalue +gvalue-value-offset+)
   value)
 
+(defmacro with-gvalue ((gvalue type &optional (value nil value-p)) &body body)
+  `(let ((,gvalue ,(if value-p
+                      `(gvalue-new ',type ,value)
+                    `(gvalue-new ',type ,value))))
+    (unwind-protect
+        (progn
+          ,@body
+          ,(unless value-p `(gvalue-get ,gvalue)))
+      (gvalue-free ,gvalue))))
 
 
 (deftype param-flag-type ()