[vala/0.36] codegen: Assign GValue result of function calls to temp-var on copy_value
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.36] codegen: Assign GValue result of function calls to temp-var on copy_value
- Date: Tue, 13 Aug 2019 15:21:29 +0000 (UTC)
commit b91bd576b0e59be39ddb3254d9337c39e52bf3c8
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 57ee13c65..ca9a56c74 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 332f4b589..02a34dcf9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
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]