]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix copying and destroying GValue values
authorJürg Billeter <j@bitron.ch>
Fri, 28 Nov 2008 19:17:19 +0000 (19:17 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 28 Nov 2008 19:17:19 +0000 (19:17 +0000)
2008-11-28  Jürg Billeter  <j@bitron.ch>

* gobject/valaccodebasemodule.vala:

Fix copying and destroying GValue values

svn path=/trunk/; revision=2075

ChangeLog
gobject/valaccodebasemodule.vala

index d9f9020d5d257095e79200ea1590ed14600ab2a8..e3d114242d09b4467196c20b89b46cf49c4a4960 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-11-28  Jürg Billeter  <j@bitron.ch>
+
+       * gobject/valaccodebasemodule.vala:
+
+       Fix copying and destroying GValue values
+
 2008-11-28  Jürg Billeter  <j@bitron.ch>
 
        * vapi/glib-2.0.vapi:
index 2d7fc1ac7b87a9cf93b4f8964e03a8f4df846662..107d321231e9da3766122b7232db374201f215bb 100644 (file)
@@ -111,6 +111,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
        public TypeSymbol gstringbuilder_type;
        public TypeSymbol garray_type;
        public DataType gquark_type;
+       public Struct gvalue_type;
        public Struct mutex_type;
        public TypeSymbol type_module_type;
        public Interface list_type;
@@ -533,6 +534,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
                garray_type = (TypeSymbol) glib_ns.scope.lookup ("Array");
 
                gquark_type = new ValueType ((TypeSymbol) glib_ns.scope.lookup ("Quark"));
+               gvalue_type = (Struct) glib_ns.scope.lookup ("Value");
                mutex_type = (Struct) glib_ns.scope.lookup ("StaticRecMutex");
                
                type_module_type = (TypeSymbol) glib_ns.scope.lookup ("TypeModule");
@@ -1629,7 +1631,20 @@ public class Vala.CCodeBaseModule : CCodeModule {
                if (type is ValueType && !type.nullable) {
                        // normal value type, no null check
                        ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
-                       return ccall;
+
+                       if (type.data_type == gvalue_type) {
+                               // g_value_unset must not be called for already unset values
+                               var cisvalid = new CCodeFunctionCall (new CCodeIdentifier ("G_IS_VALUE"));
+                               cisvalid.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
+
+                               var ccomma = new CCodeCommaExpression ();
+                               ccomma.append_expression (ccall);
+                               ccomma.append_expression (new CCodeConstant ("NULL"));
+
+                               return new CCodeConditionalExpression (cisvalid, ccomma, new CCodeConstant ("NULL"));
+                       } else {
+                               return ccall;
+                       }
                }
 
                /* (foo == NULL ? NULL : foo = (unref (foo), NULL)) */
@@ -2249,6 +2264,20 @@ public class Vala.CCodeBaseModule : CCodeModule {
                        copy_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
 
                        var ccomma = new CCodeCommaExpression ();
+
+                       if (st.get_copy_function () == "g_value_copy") {
+                               // GValue requires g_value_init in addition to g_value_copy
+
+                               var value_type_call = new CCodeFunctionCall (new CCodeIdentifier ("G_VALUE_TYPE"));
+                               value_type_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr));
+
+                               var init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_value_init"));
+                               init_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
+                               init_call.add_argument (value_type_call);
+
+                               ccomma.append_expression (init_call);
+                       }
+
                        ccomma.append_expression (copy_call);
                        ccomma.append_expression (ctemp);