]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
GAsync: Support generic types in async methods
authorLuca Bruno <lucabru@src.gnome.org>
Fri, 8 Jul 2011 16:56:18 +0000 (18:56 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Fri, 8 Jul 2011 17:22:11 +0000 (19:22 +0200)
Fixes bug 653861.

codegen/valaccodebasemodule.vala
codegen/valagasyncmodule.vala
tests/Makefile.am
tests/asynchronous/bug653861.vala [new file with mode: 0644]

index 31870bb70ad628bf1e0624767c4e308b0c06e07b..16e3856fdce88ce62c5e129a9641b15aff6ce470 100644 (file)
@@ -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) {
index b6c486b37d5446f3d42314acb2bdea360390b21d..e9820fb39c91ac260bbb21a088c458af7a9d4683 100644 (file)
@@ -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);
index d67283558cd0117de6e099db2c42220e4aa85b3d..eca8dd27badff677352fbee740cf4b0f8f703efa 100644 (file)
@@ -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 (file)
index 0000000..dfe4db0
--- /dev/null
@@ -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));
+}