[vala] codegen: Assign to temp varable when passing a nullable struct argument
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Assign to temp varable when passing a nullable struct argument
- Date: Tue, 16 Aug 2011 21:24:23 +0000 (UTC)
commit 94d4b1e91a437f739b42f0ac4021faf5e9aa664c
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Aug 16 22:37:58 2011 +0200
codegen: Assign to temp varable when passing a nullable struct argument
Assign possible (*expr) to a temp variable to ensure copying the struct.
Fixes bug 656693.
codegen/valaccodebasemodule.vala | 5 +----
tests/Makefile.am | 1 +
tests/structs/bug656693.vala | 13 +++++++++++++
3 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2a2ee26..b6e2ce1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4388,10 +4388,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// we already use a reference for arguments of ref, out, and nullable parameters
if (!(unary != null && (unary.operator == UnaryOperator.OUT || unary.operator == UnaryOperator.REF)) && !type.nullable) {
var cunary = cexpr as CCodeUnaryExpression;
- if (cunary != null && cunary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
- // *expr => expr
- return cunary.inner;
- } else if (cexpr is CCodeIdentifier || cexpr is CCodeMemberAccess) {
+ if (cexpr is CCodeIdentifier || cexpr is CCodeMemberAccess) {
return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
} else {
// if cexpr is e.g. a function call, we can't take the address of the expression
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0beb76f..d1b1491 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -72,6 +72,7 @@ TESTS = \
structs/bug651441.vala \
structs/bug654646.vala \
structs/bug654753.vala \
+ structs/bug656693.vala \
delegates/delegates.vala \
delegates/bug539166.vala \
delegates/bug595610.vala \
diff --git a/tests/structs/bug656693.vala b/tests/structs/bug656693.vala
new file mode 100644
index 0000000..86d90e5
--- /dev/null
+++ b/tests/structs/bug656693.vala
@@ -0,0 +1,13 @@
+struct Foo {
+ int bar;
+}
+
+void baz (Foo foo) {
+ foo.bar = 3;
+}
+
+void main () {
+ Foo? foo = Foo ();
+ baz (foo);
+ assert (foo.bar == 0);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]