[vala/0.12] codegen: Copy the delegate target when copying structs



commit e7c205b5dd907105b8b74dd55bbb7dc309172275
Author: Joakim Sindholt <opensource zhasha com>
Date:   Thu Mar 3 02:27:32 2011 +0100

    codegen: Copy the delegate target when copying structs
    
    Fixes bug 639751.

 codegen/valaccodestructmodule.vala |    9 +++++++++
 tests/Makefile.am                  |    1 +
 tests/delegates/bug639751.vala     |   10 ++++++++++
 3 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 553e821..b6114dc 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -293,6 +293,15 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 				} else {
 					ccode.add_assignment (dest, copy);
 
+					if (f.variable_type is DelegateType) {
+						var delegate_type = (DelegateType) f.variable_type;
+						if (delegate_type.delegate_symbol.has_target) {
+							// copy field storing delegate target
+							var target_name = get_delegate_target_cname (f.name);
+							ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("dest"), target_name), new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), target_name));
+						}
+					}
+
 					if (array_type != null) {
 						for (int dim = 1; dim <= array_type.rank; dim++) {
 							var len_src = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), get_array_length_cname (f.name, dim));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b643d8a..f4bb5c1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -54,6 +54,7 @@ TESTS = \
 	delegates/delegates.vala \
 	delegates/bug595610.vala \
 	delegates/bug595639.vala \
+	delegates/bug639751.vala \
 	objects/classes.vala \
 	objects/fields.vala \
 	objects/interfaces.vala \
diff --git a/tests/delegates/bug639751.vala b/tests/delegates/bug639751.vala
new file mode 100644
index 0000000..055a6de
--- /dev/null
+++ b/tests/delegates/bug639751.vala
@@ -0,0 +1,10 @@
+struct Foo {
+	public SourceFunc bar;
+}
+
+void main() {
+	var foo = Foo ();
+	foo.bar = () => { foo.bar = null; return false; };
+	var baz = foo;
+	baz.bar ();
+}



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