]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Avoid C compiler warning for abstract interface implementations
authorAli Sabil <ali.sabil@gmail.com>
Sat, 25 Apr 2009 12:31:17 +0000 (14:31 +0200)
committerAli Sabil <ali.sabil@gmail.com>
Sat, 25 Apr 2009 12:31:17 +0000 (14:31 +0200)
Fixes bug 571522.

gobject/valagtypemodule.vala

index 7a7acbb15035be8dd5db43b97b06b990d5094f06..bb52ad0cf1a7bf2267f477c3a306ac0cc1f072b4 100644 (file)
@@ -1196,12 +1196,42 @@ internal class Vala.GTypeModule : GErrorModule {
                        }
                        
                        var ciface = new CCodeIdentifier ("iface");
-                       string cname = m.get_real_cname ();
+                       CCodeExpression cfunc;
                        if (m.is_abstract || m.is_virtual) {
-                               // FIXME results in C compiler warning
-                               cname = m.get_cname ();
+                               cfunc = new CCodeIdentifier (m.get_cname ());
+                               // Cast the function pointer to match the interface
+                               string cast = m.return_type.get_cname () + " (*)";
+                               string cast_args = iface.get_cname () + "*";
+
+                               var vdeclarator = new CCodeFunctionDeclarator (m.vfunc_name);
+                               var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
+
+                               generate_cparameters (m, source_declarations, cparam_map, new CCodeFunction ("fake"), vdeclarator);
+
+                               // append C arguments in the right order
+                               int last_pos = -1;
+                               int min_pos;
+                               while (true) {
+                                       min_pos = -1;
+                                       foreach (int pos in cparam_map.get_keys ()) {
+                                               if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
+                                                       min_pos = pos;
+                                               }
+                                       }
+                                       if (last_pos != -1) { // Skip the 1st parameter
+                                               if (min_pos == -1) {
+                                                       break;
+                                               }
+                                               cast_args += " ," + cparam_map.get (min_pos).type_name;
+                                       }
+                                       last_pos = min_pos;
+                               }
+                               cast += "(" + cast_args + ")";
+                               cfunc = new CCodeCastExpression (cfunc, cast);
+                       } else {
+                               cfunc = new CCodeIdentifier (m.get_real_cname ());
                        }
-                       init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ciface, m.base_interface_method.vfunc_name), new CCodeIdentifier (cname))));
+                       init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ciface, m.base_interface_method.vfunc_name), cfunc)));
                }
 
                // connect inherited implementations