[vala/wip/effectfree: 17/43] codegen: Use temporary variables when accessing a variable



commit a05b537d802cdbfda4ede5a3c4a6e5c87074ee29
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 15 13:27:21 2011 +0200

    codegen: Use temporary variables when accessing a variable
    
    Fixes bugs 626038 and 572091.

 codegen/valaccodememberaccessmodule.vala |    5 +++++
 tests/Makefile.am                        |    2 ++
 tests/objects/bug626038.vala             |    8 ++++++++
 tests/structs/bug572091.vala             |   13 +++++++++++++
 4 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index bf1c6e9..16de063 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -698,6 +698,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 			result.delegate_target_destroy_notify_cvalue = new CCodeConstant ("NULL");
 		}
 		result.value_type.value_owned = false;
+
+		if (!(variable is Parameter && variable.name == "this") && !(array_type != null && array_type.inline_allocated)) {
+			result = (GLibValue) store_temp_value (result, variable);
+		}
+
 		return result;
 	}
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 309c72c..b22848f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -53,6 +53,7 @@ TESTS = \
 	structs/structs.vala \
 	structs/gvalue.vala \
 	structs/bug530605.vala \
+	structs/bug572091.vala \
 	structs/bug583603.vala \
 	structs/bug595587.vala \
 	structs/bug606202.vala \
@@ -90,6 +91,7 @@ TESTS = \
 	objects/bug613840.vala \
 	objects/bug620706.vala \
 	objects/bug624594.vala \
+	objects/bug626038.vala \
 	objects/bug628639.vala \
 	objects/bug642809.vala \
 	objects/bug643711.vala \
diff --git a/tests/objects/bug626038.vala b/tests/objects/bug626038.vala
new file mode 100644
index 0000000..3c1f875
--- /dev/null
+++ b/tests/objects/bug626038.vala
@@ -0,0 +1,8 @@
+class Foo {
+	public Foo foo;
+}
+
+void main () {
+	var foo = new Foo ();
+	foo.foo = (owned) foo;
+}
diff --git a/tests/structs/bug572091.vala b/tests/structs/bug572091.vala
new file mode 100644
index 0000000..5fa3788
--- /dev/null
+++ b/tests/structs/bug572091.vala
@@ -0,0 +1,13 @@
+struct Foo {
+	public int bar;
+}
+
+void baz (Foo foo) {
+	foo.bar = 2;
+}
+
+void main() {
+	var foo = Foo () { bar = 1 };
+	baz (foo);
+	assert (foo.bar == 1);
+}



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