GNOME Bugzilla – Bug 465625
g_type_default_interface_ref() does not ensure working g_signal_list_ids()
Last modified: 2007-08-14 22:57:59 UTC
g_signal_list_ids() requires class initialization. This means that for classes one has to call g_type_class_ref(type) and for interfaces g_type_default_interface_ref(type) beforehand to ensure the initialization. However, for interfaces it can still be insufficient. If the inspected interface registers no signals and no other class that would register signals have been initialized yet, it breaks. An example will be attached. In src/ it contains two interfaces: - BadgerPesky (no signals) - BadgerDomestic (has a signal) and a program - inspect inspect essentially does g_type_default_interface_ref(type); ids = g_signal_list_ids(type, &nids); for both interfaces. If you run it ./src/inspect it prints: Inspecting BadgerPesky (process:20020): GLib-GObject-WARNING **: gsignal.c:1063: unable to list signals of non instantiatable type `BadgerPesky' 0 signals: Inspecting BadgerDomestic 1 signals: bite By running it ./src/inspect invert you instruct it to inspect the interfaces in the reverse order, and voilà, it works: Inspecting BadgerDomestic 1 signals: bite Inspecting BadgerPesky 0 signals: There seems to be some global initialization missing in the first case.
Created attachment 93477 [details] test case
After some investigation I have found the reason is quite simple. g_signal_list_ids() assumes that if n_nodes obtained n_nodes = g_bsearch_array_get_n_nodes (g_signal_key_bsa); is zero, then an error occurred and tries to print an error message. But that is not necessarily an error. Zero can be returned when no type with signals have been initialized yet.
Created attachment 93517 [details] [review] suggested patch Suppress warnings message about uninstantiatable type and unloaded type when the type is an interface.
(In reply to comment #3) > Created an attachment (id=93517) [edit] > suggested patch > > Suppress warnings message about uninstantiatable type and unloaded type when > the type is an interface. thanks, the patch is ok. bratsche,tbf please commit.
2007-08-14 Cody Russell <bratsche@gnome.org> * gobject/gsignal.c: g_type_default_interface_ref() was not ensuring working g_signal_list_ids. Added checks for !G_TYPE_IS_INTERFACE (itype). (#465625, by some guy who calls himself Yeti) Committed revision 5704.