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 465625 - g_type_default_interface_ref() does not ensure working g_signal_list_ids()
g_type_default_interface_ref() does not ensure working g_signal_list_ids()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
2.12.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-08-11 08:55 UTC by Yeti
Modified: 2007-08-14 22:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test case (216.69 KB, application/x-compressed-tar)
2007-08-11 08:56 UTC, Yeti
  Details
suggested patch (786 bytes, patch)
2007-08-11 22:17 UTC, Yeti
committed Details | Review

Description Yeti 2007-08-11 08:55:26 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.
Comment 1 Yeti 2007-08-11 08:56:19 UTC
Created attachment 93477 [details]
test case
Comment 2 Yeti 2007-08-11 22:14:07 UTC
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.
Comment 3 Yeti 2007-08-11 22:17:44 UTC
Created attachment 93517 [details] [review]
suggested patch

Suppress warnings message about uninstantiatable type and unloaded type when the type is an interface.
Comment 4 Tim Janik 2007-08-14 22:33:07 UTC
(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.
Comment 5 Cody Russell 2007-08-14 22:57:20 UTC
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.