GNOME Bugzilla – Bug 637738
object_interface_check_properties never actually executes
Last modified: 2011-04-06 13:58:09 UTC
I have been using the g_object_interface_install_property function to install properties on a GInterface, and the docs say that GObject should check that an object implementing the interface has properties that conform to the interface's properties. However, my tests have shown that creating an GObject that has missing properties does not give any sort of warning. After poking around in the source code I found the object_interface_check_properties function in gobject.c. This function was being called, but the g_type_class_peek call was always returning NULL, so the checks were bypassed. So as far as I can tell from trawling the source code: - object_interface_check_properties is a GTypeInterfaceCheckFunc (registered via g_type_add_interface_check) - a class is initialised in type_class_init_Wm (in gtype.c) - within here, type_iface_vtable_iface_init_Wm is called for each interface to initialise its implementation in the class - within here, the GTypeInterfaceCheckFunc functions are called Going back to type_class_init_Wm, I notice that *after* the calls to type_iface_vtable_iface_init_Wm we have: g_atomic_int_set (&node->data->class.init_state, INITIALIZED); So, from that, I infer that the class is not set to the INITIALIZED state until *after* the check functions are called. This explains the wrong behaviour in object_interface_check_properties, because if the class is not in INITIALIZED state, g_type_class_peek will return NULL. A simple fix for this is replacing g_type_class_peek with g_type_class_ref.
Thanks for the detective work. Fixed, and added a testcase.
The patch committed breaks dynamic types that implement interfaces. Now a critical warning is emitted for all properties of the interface even though they are overridden. This can be tested using libpeas and running the demo.
Hmm, I don't see any warnings from the peas demo, and I don't see any warnings either in the testcase I've added to gobject/tests/dynamictests.c
Garrett, could you please retest this and let us know, so that if you don't see any regression the bug an be closed.