]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix vfunc pointer cast for async method implementation/override
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 28 Feb 2017 12:49:20 +0000 (13:49 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 28 Feb 2017 14:01:38 +0000 (15:01 +0100)
codegen/valagtypemodule.vala

index 6b0c4daa85d5e7aedb000729c976d69925283235..8945d076655345a12f0541928b5428556a87344e 100644 (file)
@@ -1213,12 +1213,14 @@ public class Vala.GTypeModule : GErrorModule {
                        // there is currently no default handler for abstract async methods
                        if (!m.is_abstract || !m.coroutine) {
                                CCodeExpression cfunc = new CCodeIdentifier (get_ccode_real_name (m));
-                               cfunc = cast_method_pointer (m.base_method, cfunc, base_type);
+                               cfunc = cast_method_pointer (m.base_method, cfunc, base_type, (m.coroutine ? 1 : 3));
                                var ccast = new CCodeCastExpression (new CCodeIdentifier ("klass"), "%sClass *".printf (get_ccode_name (base_type)));
                                ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_vfunc_name (m.base_method)), cfunc);
 
                                if (m.coroutine) {
-                                       ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_finish_vfunc_name (m.base_method)), new CCodeIdentifier (get_ccode_finish_real_name (m)));
+                                       cfunc = new CCodeIdentifier (get_ccode_finish_real_name (m));
+                                       cfunc = cast_method_pointer (m.base_method, cfunc, base_type, 2);
+                                       ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_finish_vfunc_name (m.base_method)), cfunc);
                                }
                        }
                }
@@ -1332,7 +1334,7 @@ public class Vala.GTypeModule : GErrorModule {
                        } else {
                                cfunc = new CCodeIdentifier (get_ccode_real_name (m));
                        }
-                       cfunc = cast_method_pointer (m.base_interface_method, cfunc, iface);
+                       cfunc = cast_method_pointer (m.base_interface_method, cfunc, iface, (m.coroutine ? 1 : 3));
                        ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m.base_interface_method)), cfunc);
 
                        if (m.coroutine) {
@@ -1341,6 +1343,7 @@ public class Vala.GTypeModule : GErrorModule {
                                } else {
                                        cfunc = new CCodeIdentifier (get_ccode_finish_real_name (m));
                                }
+                               cfunc = cast_method_pointer (m.base_interface_method, cfunc, iface, 2);
                                ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_finish_vfunc_name (m.base_interface_method)), cfunc);
                        }
                }
@@ -1496,7 +1499,7 @@ public class Vala.GTypeModule : GErrorModule {
                return new CCodeCastExpression (cfunc, cast);
        }
 
-       CCodeExpression cast_method_pointer (Method m, CCodeExpression cfunc, ObjectTypeSymbol base_type) {
+       CCodeExpression cast_method_pointer (Method m, CCodeExpression cfunc, ObjectTypeSymbol base_type, int direction = 3) {
                // Cast the function pointer to match the interface
                string cast;
                if (m.return_type.is_real_non_null_struct_type ()) {
@@ -1509,7 +1512,7 @@ public class Vala.GTypeModule : GErrorModule {
                var vdeclarator = new CCodeFunctionDeclarator (get_ccode_vfunc_name (m));
                var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
 
-               generate_cparameters (m, cfile, cparam_map, new CCodeFunction ("fake"), vdeclarator);
+               generate_cparameters (m, cfile, cparam_map, new CCodeFunction ("fake"), vdeclarator, null, null, direction);
 
                // append C arguments in the right order
                int last_pos = -1;