Hi,

I'm currently working on a patch for out binding tool and want to add
some simple mediators to easily use it from C. During compilation i
stumpled over 2 little bugs:
* vala creates a local variable result, but a parameter has the same
  name. This one is fixed, even I'm not completely happy with the
  solution, but it passes all tests.
* If you use Values, vala creates a wrong Data struct for the coroutine.
  It adds a result with type of Value instead of Value* and i cannot
  figure out where this happens. This leads to some wrong copy methods,
  too.

I attached my 3 patches. The third one extends the test to cover the
second case and fails atm.

Regards. Frederik
-- 
IRC: playya @ Freenode, Gimpnet
xmpp: [email protected]
From 2a280f1db8f0ed8eb30b44cb761440e406997d69 Mon Sep 17 00:00:00 2001
From: Frederik 'playya' Sdun <[email protected]>
Date: Sun, 10 Jan 2010 00:41:39 +0100
Subject: [PATCH 1/3] Fix methods result names for async methods


Signed-off-by: Frederik 'playya' Sdun <[email protected]>
---
 codegen/valagasyncmodule.vala |    8 ++++----
 vala/valaclass.vala           |    2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 9bd6cb7..680dea9 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -349,7 +349,7 @@ internal class Vala.GAsyncModule : GSignalModule {
 		var return_type = m.return_type;
 		if (!(return_type is VoidType)) {
 			var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
-			cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
+			cdecl.add_declarator (new CCodeVariableDeclarator ("_result"));
 			finishblock.add_statement (cdecl);
 		}
 
@@ -388,19 +388,19 @@ internal class Vala.GAsyncModule : GSignalModule {
 		}
 
 		if (!(return_type is VoidType)) {
-			finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("result"), new CCodeMemberAccess.pointer (data_var, "result"))));
+			finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("_result"), new CCodeMemberAccess.pointer (data_var, "result"))));
 			if (return_type is ArrayType) {
 				var array_type = (ArrayType) return_type;
 				for (int dim = 1; dim <= array_type.rank; dim++) {
 					finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_array_length_cname ("result", dim))), new CCodeMemberAccess.pointer (data_var, get_array_length_cname ("result", dim)))));
 				}
 			} else if (return_type is DelegateType) {
-				finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_delegate_target_cname ("result"))), new CCodeMemberAccess.pointer (data_var, get_delegate_target_cname ("result")))));
+				finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_delegate_target_cname ("_result"))), new CCodeMemberAccess.pointer (data_var, get_delegate_target_cname ("result")))));
 			}
 			if (!(return_type is ValueType) || return_type.nullable) {
 				finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, "result"), new CCodeConstant ("NULL"))));
 			}
-			finishblock.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
+			finishblock.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
 		cparam_map.set (get_param_pos (0.1), new CCodeFormalParameter ("_res_", "GAsyncResult*"));
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index aee7743..a563339 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -327,7 +327,7 @@ public class Vala.Class : ObjectTypeSymbol {
 			if (m.result_var != null) {
 				m.scope.remove (m.result_var.name);
 			}
-			m.result_var = new LocalVariable (m.return_type.copy (), "result");
+			m.result_var = new LocalVariable (m.return_type.copy (), "_result");
 			m.result_var.is_result = true;
 		}
 		if (m is CreationMethod) {
-- 
1.6.3.3

From 3a73fee16e5f6a13436bde48a570ee7cb54b6702 Mon Sep 17 00:00:00 2001
From: Frederik 'playya' Sdun <[email protected]>
Date: Sun, 10 Jan 2010 02:19:01 +0100
Subject: [PATCH 2/3] Add testcase for async mediator


Signed-off-by: Frederik 'playya' Sdun <[email protected]>
---
 tests/Makefile.am                     |    1 +
 tests/asynchronous/asyncmediator.vala |   13 +++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index e9628cd..a30b3db 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -74,6 +74,7 @@ TESTS = \
 	asynchronous/bug599568.vala \
 	asynchronous/bug600827.vala \
 	asynchronous/bug601558.vala \
+	asynchronous/asyncmediator.vala \
 	dbus/basic-types.test \
 	dbus/arrays.test \
 	dbus/structs.test \
diff --git a/tests/asynchronous/asyncmediator.vala b/tests/asynchronous/asyncmediator.vala
new file mode 100644
index 0000000..f4463e2
--- /dev/null
+++ b/tests/asynchronous/asyncmediator.vala
@@ -0,0 +1,13 @@
+public interface IFoo: GLib.Object {
+    public abstract async void foo (int i);
+}
+
+public class Foo : GLib.Object, IFoo {
+    IFoo i_foo;
+    public async void foo (int i) {
+        yield i_foo.foo(i);
+    }
+}
+
+void main() {
+}
-- 
1.6.3.3

From 3a04cc0865cb5137cf0fe8ae5f505860cca2e246 Mon Sep 17 00:00:00 2001
From: Frederik 'playya' Sdun <[email protected]>
Date: Sun, 10 Jan 2010 03:30:57 +0100
Subject: [PATCH 3/3] Add test for async mediators with values


Signed-off-by: Frederik 'playya' Sdun <[email protected]>
---
 tests/asynchronous/asyncmediator.vala |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tests/asynchronous/asyncmediator.vala b/tests/asynchronous/asyncmediator.vala
index f4463e2..9ed5ecb 100644
--- a/tests/asynchronous/asyncmediator.vala
+++ b/tests/asynchronous/asyncmediator.vala
@@ -1,5 +1,6 @@
 public interface IFoo: GLib.Object {
     public abstract async void foo (int i);
+    public abstract async void bar (Value v);
 }
 
 public class Foo : GLib.Object, IFoo {
@@ -7,6 +8,9 @@ public class Foo : GLib.Object, IFoo {
     public async void foo (int i) {
         yield i_foo.foo(i);
     }
+    public async void bar (Value v) {
+        yield i_foo.bar(v);
+    }
 }
 
 void main() {
-- 
1.6.3.3

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to