GNOME Bugzilla – Bug 685733
Call ->constructed() after all properties are set
Last modified: 2012-11-18 20:44:33 UTC
Bug 425324 introduced the ->constructed() vcall on GObject. The original version of the patch called constructed() after all properties were set. Unfortunately, the version that made it into the tree moved the call to a point where only the construct properties were set (with the others being set after). The general consensus seems to be that this was a bad idea and has substantially reduced the usefulness of this function. We're going to move the call to after the other properties being set and see if it breaks anything...
Created attachment 226053 [details] [review] [gobject] set all properties before constructed() Move the constructed() call to happen after all of the properties are set (not just the construct properties). This is an incompatible change but we are making it under the belief that it should be safe. If this change impacts you in a negative way please comment on the bug.
Comment on attachment 226053 [details] [review] [gobject] set all properties before constructed() Attachment 226053 [details] pushed as 028d4a0 - [gobject] set all properties before constructed() Going to leave the bug open for now and wait for comments...
First hit in Rhythmbox, which is now seeing a (harmless) critical. http://git.gnome.org/browse/rhythmbox/tree/sources/rb-static-playlist-source.c#n439 case PROP_SHOW_BROWSER: if (g_value_get_boolean (value)) gtk_widget_show (GTK_WIDGET (priv->browser)); else gtk_widget_hide (GTK_WIDGET (priv->browser)); break; The widget is constructed in the constructed handler, so is causing the GTK_WIDGET cast to fail. The incorrect fix is to bail out if priv->browser is NULL. The ugly but correct fix is to move the construction of the widget to the constructor vfunc.
I filed bug 688596 before finding that this is still open. I'm sorry but this change needs to be reverted now. I don't need to cite our favorite kernel hacker to make it clear that API changes must be avoided for a platform critical library to be taken seriously. That aside, this change does not make sense even without considering the breakages, as now property setters cannot assume that the object is fully constructed. Take rhythmbox as an example. The only possible "fix" is to introduce a separate g_object_set() after the object is fully constructed. Moreover, it becomes worse once you deal with introspected languages, since constructors for those are just wrappers around g_object_newv, and it is a reasonable expectation that all properties can be set at once in those.
Since we now have bug 688596, we may as well close this one...