]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Assign GValue result of function calls to temp-var on copy_value
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 5 Jul 2019 14:54:19 +0000 (16:54 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 6 Aug 2019 12:00:08 +0000 (14:00 +0200)
Regression of a94a28141e1f222d1da7e72bea4cd2d1e5242f41

Fixes https://gitlab.gnome.org/GNOME/vala/issues/819

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/methods/varargs-gvalue.vala [new file with mode: 0644]

index 57ee13c6509bc050f713145f23a454d7d0bbab1d..ca9a56c74b2af85e8eb14ee23636dff0ee13996d 100644 (file)
@@ -4306,6 +4306,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                if (type is ValueType && !type.nullable) {
                        // normal value type, no null check
 
+                       // use temp-var for upcoming address-of operator
+                       var temp_cvalue = create_temp_value (type, false, node);
+                       store_value (temp_cvalue, value);
+                       cexpr = get_cvalue_ (temp_cvalue);
+
                        var temp_value = create_temp_value (type, true, node, true);
                        var ctemp = get_cvalue_ (temp_value);
 
@@ -4338,7 +4343,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                ccode.add_else ();
 
                                // g_value_init/copy must not be called for uninitialized values
-                               store_value (temp_value, value);
+                               store_value (temp_value, temp_cvalue);
                                ccode.close ();
                        } else {
                                ccode.add_expression (copy_call);
index 332f4b589c2be02114b379341545bcb203da4581..02a34dcf933ad2048ffa7dc034a300458d5b7f12 100644 (file)
@@ -124,6 +124,7 @@ TESTS = \
        methods/printf-invalid.test \
        methods/printf-constructor.vala \
        methods/printf-constructor-invalid.test \
+       methods/varargs-gvalue.vala \
        methods/varargs-out.vala \
        control-flow/assigned-local-variable.vala \
        control-flow/break.vala \
diff --git a/tests/methods/varargs-gvalue.vala b/tests/methods/varargs-gvalue.vala
new file mode 100644 (file)
index 0000000..3160b23
--- /dev/null
@@ -0,0 +1,15 @@
+void foo (int first_arg, ...) {
+       var args = va_list ();
+       Value val = args.arg ();
+
+       assert (first_arg == 42);
+       assert (val.holds (typeof (string)));
+       assert (val.get_string () == "foo");
+}
+
+void main () {
+       Value val = Value (typeof (string));
+       val.set_string ("foo");
+
+       foo (42, val);
+}