GNOME Bugzilla – Bug 576492
GtkBuilder does not respect G_PARAM_CONSTRUCT properties
Last modified: 2017-08-24 10:59:28 UTC
Every construct properties should be set before calling GObject:constructor and GObject::constructed methods, but this is not the case with GtkBuilder
Created attachment 131220 [details] Simple test case i have created a simple object with some debug output in both constructor and constructed methods and it instantiate an object using g_object_new() and another with GtkBuilder
Something like this should probably do it: Index: gtk/gtkbuilder.c =================================================================== --- gtk/gtkbuilder.c (revision 22374) +++ gtk/gtkbuilder.c (working copy) @@ -280,7 +280,8 @@ if (G_IS_PARAM_SPEC_OBJECT (pspec) && (G_PARAM_SPEC_VALUE_TYPE (pspec) != GDK_TYPE_PIXBUF)) { - if (pspec->flags & G_PARAM_CONSTRUCT_ONLY) + if (pspec->flags & G_PARAM_CONSTRUCT || + pspec->flags & G_PARAM_CONSTRUCT_ONLY) { GObject *object; object = gtk_builder_get_object (builder, prop->data); No time to compile/add test right now.
Looks right to me.
Geez I completely forgot I reported this bug. Matthias, I can test and commit the proposed patch if you like.
That would be great
Fixed in master, gtk-2-24 and gtk-3-0 branches http://git.gnome.org/browse/gtk+/commit/?id=f430a76f10d1b7790d83006f9817890960063ed8
This breaks the xfce4-panel. Getting messages like "Gtk-WARNING **: Failed to get constuct only property adjustment of leave-opacity-scale with value `leave-opacity'" http://git.xfce.org/xfce/xfce4-panel/plain/panel/panel-preferences-dialog.glade
I think this just exposed a different bug, before this patch those properties where not even set up, now that they are, object properties seems to fail if the object is not defined before its used. I always though GtkBuilder dereferenced setting up object props to the end but for some reason its not. So if you move all those objects like `leave-opacity` to the beginning of the file the warnings go away.
Yeah indeed that works fine. However maybe this bug should be reassigned to glade to fix the saving.
I've released new versions of the Xfce packages that were affected by this change. However I'd like show my concern that fixes like these are landing in the 2.24 branch. Nothing was broken (the previous glade files worked fine) and although I agree this "does the right thing", imho it does not qualify as critical bug fixes or regressions. Given the fact that git-gtk2 is less tested now gtk3 is around, it's easier for regressions to slip through... Hope this will be taken in consideration when future patches are allowed in gtk-2.24.
(In reply to comment #9) > Yeah indeed that works fine. However maybe this bug should be reassigned to > glade to fix the saving. No, this is still a gtkbuilder bug. (In reply to comment #10) > I've released new versions of the Xfce packages that were affected by this > change. > > However I'd like show my concern that fixes like these are landing in the 2.24 > branch. Nothing was broken (the previous glade files worked fine) and although > I agree this "does the right thing", imho it does not qualify as critical bug > fixes or regressions. > Given the fact that git-gtk2 is less tested now gtk3 is around, it's easier for > regressions to slip through... Hope this will be taken in consideration when > future patches are allowed in gtk-2.24. I'm sorry that you were inconvenienced by this. Here is how you can help avoiding this kind of fallout in the future: Write a patch for gtk/tests/builder.c adding a test case for the problem you've experienced. That should make it a) much easier to fix and b) prevent regressions in the future.
Created attachment 190466 [details] Better test case I added a new object construct only property to the test case.
Created attachment 190469 [details] [review] regresion fix Construct only object properties can not be delayed because... well they are construct only which means that it will fail if the object is not already constructed. So we either need to make sure that glade serializes objects that are referenced in a construct only property first or we need to fix GtkBuilder to make it construct the object property instead of just complaining. In either case we will have to handle circular dependencies, right? but i guess in this case it makes sense to just complain! :D
Created attachment 190477 [details] Even better test case
Created attachment 190478 [details] [review] Regresion fix This patch makes builder do not delay construct properties that can be resolved (so construct is respected when possible) and skip construct only props that can not.
Review of attachment 190478 [details] [review]: Looks like thats about the best we can do here.
Review of attachment 190478 [details] [review]: Committed in master 3.0 and 2.24 branches http://git.gnome.org/browse/gtk+/commit/?id=ea81c710d0c0df31035297c4be6ca50b196560c6
*** Bug 653047 has been marked as a duplicate of this bug. ***