[vala] GAsync: Support generic types in async methods
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] GAsync: Support generic types in async methods
- Date: Fri, 8 Jul 2011 17:24:01 +0000 (UTC)
commit 0bf24df559f004f3642b6e6e33a13e3c3d1bc93f
Author: Luca Bruno <lucabru src gnome org>
Date: Fri Jul 8 18:56:18 2011 +0200
GAsync: Support generic types in async methods
Fixes bug 653861.
codegen/valaccodebasemodule.vala | 6 +++---
codegen/valagasyncmodule.vala | 15 +++++++++++++++
tests/Makefile.am | 1 +
tests/asynchronous/bug653861.vala | 10 ++++++++++
4 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 31870bb..16e3856 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2277,7 +2277,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (is_in_generic_type (type) && !is_chainup && !in_creation_method) {
return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), var_name);
} else {
- return new CCodeIdentifier (var_name);
+ return get_variable_cexpression (var_name);
}
} else {
string type_id = type.get_type_id ();
@@ -2333,7 +2333,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (is_in_generic_type (type) && !is_chainup && !in_creation_method) {
return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), func_name);
} else {
- return new CCodeIdentifier (func_name);
+ return get_variable_cexpression (func_name);
}
} else if (type is PointerType) {
var pointer_type = (PointerType) type;
@@ -2780,7 +2780,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (is_in_generic_type (type) && !is_chainup && !in_creation_method) {
return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), func_name);
} else {
- return new CCodeIdentifier (func_name);
+ return get_variable_cexpression (func_name);
}
} else if (type is ArrayType) {
if (context.profile == Profile.POSIX) {
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index b6c486b..e9820fb 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -66,6 +66,12 @@ public class Vala.GAsyncModule : GSignalModule {
}
}
+ foreach (var type_param in m.get_type_parameters ()) {
+ data.add_field ("GType", "%s_type".printf (type_param.name.down ()));
+ data.add_field ("GBoxedCopyFunc", "%s_dup_func".printf (type_param.name.down ()));
+ data.add_field ("GDestroyNotify", "%s_destroy_func".printf (type_param.name.down ()));
+ }
+
if (!(m.return_type is VoidType)) {
data.add_field (m.return_type.get_cname (), "result");
if (m.return_type is ArrayType) {
@@ -271,6 +277,15 @@ public class Vala.GAsyncModule : GSignalModule {
}
emit_context.pop_symbol ();
+ foreach (var type_param in m.get_type_parameters ()) {
+ var type = "%s_type".printf (type_param.name.down ());
+ var dup_func = "%s_dup_func".printf (type_param.name.down ());
+ var destroy_func = "%s_destroy_func".printf (type_param.name.down ());
+ ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, type), new CCodeIdentifier (type));
+ ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, dup_func), new CCodeIdentifier (dup_func));
+ ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, destroy_func), new CCodeIdentifier (destroy_func));
+ }
+
var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname () + "_co"));
ccall.add_argument (data_var);
ccode.add_expression (ccall);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d672835..eca8dd2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -123,6 +123,7 @@ TESTS = \
asynchronous/bug641182.vala \
asynchronous/bug646945.vala \
asynchronous/bug652252.vala \
+ asynchronous/bug653861.vala \
asynchronous/closures.vala \
dbus/basic-types.test \
dbus/arrays.test \
diff --git a/tests/asynchronous/bug653861.vala b/tests/asynchronous/bug653861.vala
new file mode 100644
index 0000000..dfe4db0
--- /dev/null
+++ b/tests/asynchronous/bug653861.vala
@@ -0,0 +1,10 @@
+class Foo {
+ public async void bar<G> (G arg, Type t) {
+ assert (typeof (G) == t);
+ }
+}
+
+void main () {
+ var foo = new Foo ();
+ foo.bar<string> ("foo", typeof (string));
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]