[vala/0.44] codegen: Assign GValue result of function calls to temp-var on copy_value



commit bbe6d9666a150583b12471287d152e6fd1365d79
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Jul 5 16:54:19 2019 +0200

    codegen: Assign GValue result of function calls to temp-var on copy_value
    
    Regression of a94a28141e1f222d1da7e72bea4cd2d1e5242f41
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/819

 codegen/valaccodebasemodule.vala  |  7 ++++++-
 tests/Makefile.am                 |  1 +
 tests/methods/varargs-gvalue.vala | 15 +++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4d4eec34e..d80bcb585 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4397,6 +4397,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, node.source_reference);
+                       cexpr = get_cvalue_ (temp_cvalue);
+
                        var temp_value = create_temp_value (type, true, node, true);
                        var ctemp = get_cvalue_ (temp_value);
 
@@ -4429,7 +4434,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, node.source_reference);
+                               store_value (temp_value, temp_cvalue, node.source_reference);
                                ccode.close ();
                        } else {
                                ccode.add_expression (copy_call);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 88d725a63..c3346ebe8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -146,6 +146,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
index 000000000..3160b2356
--- /dev/null
+++ b/tests/methods/varargs-gvalue.vala
@@ -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);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]