[vala] Handle the integers and enums in generic closure wrapper



commit d7fcb230a1947bd569c3c4ea381eb608e5ab634e
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Fri Aug 23 18:24:18 2013 +0200

    Handle the integers and enums in generic closure wrapper
    
    Handle edge-case when the one of generic parameters of delegate is an
    integer in closure or method.

 codegen/valaccodebasemodule.vala     |    2 ++
 codegen/valaccodedelegatemodule.vala |   12 +++++++++++-
 tests/Makefile.am                    |    1 +
 tests/delegates/bug659778.vala       |   28 ++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 090fce3..3af2c2d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3092,6 +3092,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                        unref_function = "g_free";
                                                }
                                        }
+                               } else if (type is EnumValueType) {
+                                       unref_function = null;
                                } else {
                                        var st = (Struct) type.data_type;
                                        if (!get_ccode_has_destroy_function (st)) {
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index cf367a5..744f63a 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -290,6 +290,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        CCodeExpression arg;
                        if (d.has_target) {
                                arg = new CCodeIdentifier ("self");
+                               if (!m.closure && m.this_parameter != null) {
+                                       arg = convert_from_generic_pointer (arg, 
m.this_parameter.variable_type);
+                               }
                        } else {
                                // use first delegate parameter as instance
                                if (d_params.size == 0 || m.closure) {
@@ -316,6 +319,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
                        CCodeExpression arg;
                        arg = new CCodeIdentifier (get_variable_cname (d_params.get (i).name));
+                       if (d_params.get (i).variable_type is GenericType) {
+                               arg = convert_from_generic_pointer (arg, param.variable_type);
+                       }
                        carg_map.set (get_param_pos (get_ccode_pos (param)), arg);
 
                        // handle array arguments
@@ -405,7 +411,11 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                if (m.return_type is VoidType || m.return_type.is_real_non_null_struct_type ()) {
                        ccode.add_expression (ccall);
                } else {
-                       ccode.add_declaration (return_type_cname, new CCodeVariableDeclarator ("result", 
ccall));
+                       CCodeExpression result = ccall;
+                       if (d.return_type is GenericType) {
+                               result = convert_to_generic_pointer (result, m.return_type);
+                       }
+                       ccode.add_declaration (return_type_cname, new CCodeVariableDeclarator ("result", 
result));
                }
 
                if (d.has_target /* TODO: && dt.value_owned */ && dt.is_called_once) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index de7e823..f7dca48 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,6 +100,7 @@ TESTS = \
        delegates/bug595639.vala \
        delegates/bug638415.vala \
        delegates/bug639751.vala \
+       delegates/bug659778.vala \
        delegates/bug703804.vala \
        objects/chainup.vala \
        objects/classes.vala \
diff --git a/tests/delegates/bug659778.vala b/tests/delegates/bug659778.vala
new file mode 100644
index 0000000..3e60386
--- /dev/null
+++ b/tests/delegates/bug659778.vala
@@ -0,0 +1,28 @@
+delegate G DoSomething<G>(G g);
+
+void do_something<G> (DoSomething<G> f) {}
+
+enum TE {
+       T
+}
+
+class Test {
+       public void f() {
+               do_something<TE> (g);
+               do_something<int> (h);
+       }
+       [CCode (instance_pos = -1)]
+       private TE g(TE i) {
+               return i;
+       }
+       [CCode (instance_pos = -1)]
+       private int h(int i) {
+               return i;
+       }
+}
+
+int main() {
+       Test t2 = new Test ();
+       t2.f ();
+       return 0;
+}


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