Bug 11510 - GInterface implementation in managed land is broken with bleeding edge glib|gobject
Summary: GInterface implementation in managed land is broken with bleeding edge glib|g...
Alias: None
Product: Gtk#
Classification: Mono
Component: gtk-sharp ()
Version: unspecified
Hardware: All Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-04-01 21:06 UTC by Andres G. Aragoneses
Modified: 2013-05-20 12:21 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

proof of concept patch (5.43 KB, patch)
2013-04-06 11:33 UTC, Andres G. Aragoneses

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Andres G. Aragoneses 2013-04-01 21:06:40 UTC
GInterface implementation in managed land is broken with bleeding edge glib or gobject.

The WARNING thrown is:

GLib-GObject-WARNING **: attempting to add an interface (Foo) to class 
(__gtksharp_91_Namespace_SomeClass_+2c+20Assembly+2c+20Version+3d2_6_0_0+2c+20Culture+3dneutral+2c+20PublicKeyToken+3dnull+5d+5d) after class_init

Couple of real examples:

GLib-GObject-WARNING **: attempting to add an interface (AtkTable) to class (__gtksharp_91_Hyena_Data_Gui_Accessibility_ListViewAccessible+601+5b+5bBanshee_Collection_TrackInfo+2c+20Banshee_Core+2c+20Version+3d2_6_0_0+2c+20Culture+3dneutral+2c+20PublicKeyToken+3dnull+5d+5d) after class_init

GLib-GObject-WARNING **: attempting to add an interface (GtkScrollable) to class (__gtksharp_56_Hyena_Data_Gui_ListView+601+5b+5bBanshee_Collection_ArtistInfo+2c+20Banshee_Core+2c+20Version+3d2_6_0_0+2c+20Culture+3dneutral+2c+20PublicKeyToken+3dnull+5d+5d) after class_init
Comment 1 Andres G. Aragoneses 2013-04-02 21:14:36 UTC
Upstream motivation: https://bugzilla.gnome.org/show_bug.cgi?id=687659
Comment 2 Andres G. Aragoneses 2013-04-04 20:31:43 UTC
PR: https://github.com/mono/gtk-sharp/pull/60
Comment 3 Andres G. Aragoneses 2013-04-06 07:08:32 UTC
There's a problem with the above pull request, therefore I'm going to close it.

The problem is the following:
1) The patch replaces the use of gtype.GetClassPtr() with gtype.Val, because the former causes class_init to be called.
2) By passing gtype.Val instead of gtype.GetClassPtr(), the initialization of properties is broken.

In regards to (1), FWIW this is what GetClassPtr does:

	public IntPtr GetClassPtr ()
		IntPtr klass = g_type_class_peek (val);
		if (klass == IntPtr.Zero)
			klass = g_type_class_ref (val);
		return klass;

I'm still not sure about the reason for (2), but my guess is because g_object_class_override_property [1] receives a GObjectClass [2] ptr as a parameter, not a GType [3].

Now, if the use of g_type_add_interface_static [4] is properly supposed to call the interface_init function of GInterfaceInfo [5], which in turn should initialize (override) properties with g_object_class_override_property (otherwise g_type_add_interface_static throws a CRITICAL), then potentially there's only possibility to fix this: to call GetClassPtr in the interface_init function of GInterfaceInfo, but would that really meet the requirements of not calling class_init before adding interfaces? And most importantly: if we have more than one interface, the class would be initted after adding the first one, so this is not possible solution.

This seems to be a chicken&egg problem which I'll discuss with glib devs.

[1] https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#g-object-class-override-property
[2] https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#GObjectClass
[3] https://developer.gnome.org/gobject/stable/gobject-Type-Information.html#GType
[4] https://developer.gnome.org/gobject/stable/gobject-Type-Information.html#g-type-add-interface-static
[5] https://developer.gnome.org/gobject/stable/gobject-Type-Information.html#GInterfaceInfo
Comment 4 Andres G. Aragoneses 2013-04-06 11:33:48 UTC
Created attachment 3761 [details]
proof of concept patch

After some more feedback from Ryan in the upstream bug, this is a patch based on his suggestions. Still doesn't work though, but I'll leave it here for reference and further discussion.
Comment 5 Andres G. Aragoneses 2013-04-06 19:30:04 UTC
Finally a patch that seems to work for both treemodeldemo and custom-scrollable: https://github.com/mono/gtk-sharp/pull/61
Comment 6 Andres G. Aragoneses 2013-05-20 12:21:49 UTC
Bertrand has just merged this, so I'm marking it as FIXED.

Thanks Bertrand!