From: Rico Tzschichholz Date: Fri, 5 Jul 2019 14:54:19 +0000 (+0200) Subject: codegen: Assign GValue result of function calls to temp-var on copy_value X-Git-Tag: 0.45.3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8c7e265ee6b0db3b3301a50cd144f6a58c6b717;p=thirdparty%2Fvala.git 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 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index af1b761ca..bef379bf1 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -4383,6 +4383,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); @@ -4415,7 +4420,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 3439c786f..a01fd8f68 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -148,6 +148,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); +}