GNOME Bugzilla – Bug 682192
[widget] allow uninitialized GValue in style_get_property
Last modified: 2018-02-10 03:29:57 UTC
This is needed to make the following testcase work: from gi.repository import Gtk w = Gtk.Button() i = w.style_get_property("image-spacing") print i
Created attachment 221744 [details] [review] [widget] allow cleared GValue in style_get_property Allow to pass a GValue whihc has just been inited to gtk_widget_style_get_property and annotate the parameter as "out". This is needed to make this function instrospectable since bindings like pygobject expect to create and init a new GValue for the function to fill.
As pointed out by Benjamin on irc, g_object_get_property itself has the same behavior and also gtk_container_child_get_property I suspect that bindings deal with g_object_get_property as a special case, since they are aware of gobject (while they are not aware of GtkWidget). I still do not see why all these functions do not allow a cleared GValue... anybody knows why? They even claim to be there to make bindings'life easier :-) Martin, do you know if pygobject has specical code for g_object_get_property?
retitling, because "inited" has a fairly specific meaning with GValue - i.e. g_value_init() has been called on it. basically all API that deals with GValues directly assumes that the value has been initialized by the caller, so if we relax this constraint to allow uninitialized GValues, we should do this all across the board. AFAIK, all language bindings have special code to introspect the property's GParamSpec, and use that to initialize the GValue prior to passing it to the get_property(); this allows catching the case of an invalid property name, given that g_object_get_property() does not have a way to signal failure, except printing a warning on the console. given that we don't have special code to handle GtkWidget any more, we'll need some Gtk override for pygobject (and other language bindings) that queries the class for the GParamSpec and initializes the GValue - for every class that has the ability to use GParamSpecs.
as noted by Paolo on IRC, GtkTreeModel.get_value() asks for uninitialized GValues instead of initialized ones, so yey for consistency. just to reiterate: I don't think there's anything wrong in relaxing the preconditions, and accepting unset GValues in generic getters; it would be nice to have a consistent policy for all the libraries in the platform as well.
*** Bug 690495 has been marked as a duplicate of this bug. ***
FYI, there is a ticket and patch which requests the addition of a style_peek_property API (bug 685091). The reason I thought this was needed is style_get_property should be marked as (inout) which is awkward to deal with in python.
Although I would be much happier if we could relax get_property, style_get_property, and child_get_property as (out) only annotations because it would make bindings much easier to deal with (the annotations would be somewhat inaccurate though). With (out) only GValue params, the pygi internals will auto coerce them into the appropriate python types as return values of the method. If they are (inout) we have to add overrides for each of the methods which first create and initialize a GValue and then coerce them in python. See: bug 685076 This was the purpose of having a peek method which the GValue could accurately be marked as (out) only and we wouldn't have to change the existing APIs.
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.