GNOME Bugzilla – Bug 355352
If you don't have an instantiatable type for a gtypeinterface, its signals will fail
Last modified: 2007-09-22 19:11:29 UTC
The scanner will not find signals if you don't have an instantiatable implementation of a gtypeinterface. It's the g_signal_list_ids method being used that is causing this bug. Unless a _get_type of an object that implements your gtypeinterface and that *is* instantiatable happened, this function will return 0 signals. Small example. In the example "tny_account_store_get_type" returns a GTypeInterface's GType. TNY_TYPE_TEST_ACCOUNT_STORE translates to tny_test_account_store_get_type is an implementation of the GTypeInterface TnyAccountStore. If this test-account-store implementation isn't included in the .types file used by gtk-doc, the signals of TnyAccountStore aren't generated in the documentation. g_type_init (); gint *signals, nsignals; /* If you remove this line, signals is 0, else it's 4 in libtinymail */ g_object_new (TNY_TYPE_TEST_ACCOUNT_STORE, NULL); GType type = tny_account_store_get_type (); if (G_TYPE_IS_CLASSED (type)) g_type_class_ref (type); g_print ("%s\n", g_type_name (type)); signals = g_signal_list_ids (type, &nsignals); g_print ("%d\n", nsignals);
The interface's base_init() vtable function -- which creates the signals -- doesn't have any reason to be called until it's actually used as a base of something. However, the fix should be easy: foo-scan.c must call g_type_default_interface_ref(FOO_TYPE_BAR); for each interface FooBarIface. More precisely, it has to call it only for interfaces whose base_init() functions will not be called for other reasons, but calling it for all interfaces cannot do any harm.
Created attachment 74513 [details] [review] proposed patch Reference interfaces in foo-scan.c.
The patch seems to work fine (though you missed a semi-colon!). I've committed it to cvs. Thanks.
Not fixed entirely. Or something has changed somewhere in GObject? If I create a library with only one type, an interface, the inspection fails: (process:11033): GLib-GObject-WARNING **: gsignal.c:1063: unable to list signals of non instantiatable type `BadgerPesky' (process:11033): GLib-GObject-CRITICAL **: g_param_spec_pool_list: assertion `pool != NULL' failed It works if a type that implements this interface is class-referenced before. Therefore most people don't observe it as libraries typically provide interfaces and some implementations of them. But if you provide just the interface, you are in trouble.
Created attachment 93460 [details] test case A minimal library (badger) defining only one interface (BadgerPesky). Unpack, run ./configure --enable-gtk-doc, make. Observe the errors mentioned in my previous comment.
Created attachment 93476 [details] test cases The problem is only with inspection of interfaces that do *not* register any signals. If their base init function actually registers some signals, it is sufficient to call g_type_default_interface_ref(itype); and signal inspection works. But if they don't it breaks. Attached a test case of both: for reference added BadgerDomestic interface which (unlike BadgerPesky) registers a signal and therefore works.
Unfortunately the test cases do not Just Work as gtk-doc distributes too many built files for that by default. See GObject bug 465625 and bug 465631 for better test cases (not involving gtk-doc, just performing the inspection). It seems this is a GLib issue and gtk-doc cannot do anything (more) about it.
Created attachment 93520 [details] [review] additional patch We can do something. The default initialization function can do g_type_class_ref(G_TYPE_OBJECT); in addition to g_type_init(). This ensures GObject is initialized (and consequently property pool is created) and something with signals ("notify") was initialized (and consequently g_signal_list_ids() finds nonzero n_nodes).
Too bad that this way its goona be hard for people to figure out that they should eventualy add this too. 2007-08-12 Stefan Kost <ensonic@users.sf.net> patch by: David Nečas <yeti@physics.muni.cz> * gtkdoc-scangobj.in: Make introspection of interfaces work in more cases. Fixes #355352.