GNOME Bugzilla – Bug 629612
classes implementing 2 interfaces with same method name causes segfault
Last modified: 2012-06-02 13:57:41 UTC
Created attachment 170223 [details] Testcase If a class implements 2 interfaces with the same method, the second one isn't initialised and causes a segfault: static void foo_bar_foo_interface_init (FooIface * iface) { foo_bar_foo_parent_iface = g_type_interface_peek_parent (iface); iface->test = foo_bar_real_test; } static void foo_bar_bar_interface_init (BarIface * iface) { foo_bar_bar_parent_iface = g_type_interface_peek_parent (iface); } If we want to support, that the method is called from both interfaces, we should move the cast outside of the method, like: static void foo_bar_real_foo_test (Foo* base) { FooBar * self; self = (FooBar*) base; foo_bar_real_test (self); } static void foo_bar_real_bar_test (Bar* base) { FooBar * self; self = (FooBar*) base; foo_bar_real_test (self); }
Created attachment 183023 [details] [review] codegen: GType, support for class implementing more interfaces sharing methods names The same happens in Vala 0.11 using this code (so the issue is obviously valid for more than two interfaces too): public interface Int1 : Object { public abstract void my_shared_method(); public abstract void my_own_method1(); } public interface Int2 : Object { public abstract void my_shared_method(); public abstract void my_own_method2(); } public interface Int3 : Object { public abstract void my_shared_method(); } public class MultiInterface : Object, Int1, Int2, Int3 { public void my_shared_method() { message("my_shared_method called"); } public void my_own_method1() { message("my_own_method1 called"); } public void my_own_method2() { message("my_own_method2 called"); } } void main() { var cl = new MultiInterface(); cl.my_shared_method(); cl.my_own_method1(); cl.my_own_method2(); Int1 cl1 = new MultiInterface(); cl1.my_own_method1(); cl1.my_shared_method(); // This works! Int2 cl2 = new MultiInterface(); cl2.my_own_method2(); cl2.my_shared_method(); // This causes crash! Int3 cl3 = new MultiInterface(); cl3.my_shared_method(); // This would cause crash too! } Output: ** Message: crash-interface.vala:13: my_shared_method called ** Message: crash-interface.vala:17: my_own_method1 called ** Message: crash-interface.vala:21: my_own_method2 called ** Message: crash-interface.vala:17: my_own_method1 called ** Message: crash-interface.vala:13: my_shared_method called ** Message: crash-interface.vala:21: my_own_method2 called Segmentation fault This should due the fact that by default a method is overriding just one base interface method, and then since its base type is different than the checked interface no init code is generated. The attached patch fixes the issue, but maybe is more a workaround: when creating a method initialization, it basically checks if a class method implementing some interfaces is compatible and has the same name of a method of all the interfaces before initializing it.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.
(In reply to comment #2) > Thanks for the bug report. This particular bug has already been reported into > our bug tracking system, but please feel free to report any further bugs you > find. It looks like a duplicate but it was not marked as such. I don't know what it is duplicate of - it should be probably marked as such and closed.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of bug 652098 ***