After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 629612 - classes implementing 2 interfaces with same method name causes segfault
classes implementing 2 interfaces with same method name causes segfault
Status: RESOLVED DUPLICATE of bug 652098
Product: vala
Classification: Core
Component: Code Generator: GObject
unspecified
Other Linux
: Urgent critical
: ---
Assigned To: Vala maintainers
Vala maintainers
wrong-code test-case
Depends on: 652098
Blocks:
 
 
Reported: 2010-09-14 04:23 UTC by Frederik Sdun
Modified: 2012-06-02 13:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase (401 bytes, text/x-vala)
2010-09-14 04:23 UTC, Frederik Sdun
  Details
codegen: GType, support for class implementing more interfaces sharing methods names (1.63 KB, patch)
2011-03-09 21:12 UTC, Marco Trevisan (Treviño)
none Details | Review

Description Frederik Sdun 2010-09-14 04:23:09 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);
}
Comment 1 Marco Trevisan (Treviño) 2011-03-09 21:12:38 UTC
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.
Comment 2 Luca Bruno 2011-12-25 14:09:39 UTC
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.
Comment 3 Maciej (Matthew) Piechotka 2012-06-02 06:56:02 UTC
(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.
Comment 4 Jürg Billeter 2012-06-02 13:57:41 UTC
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 ***