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 682192 - [widget] allow uninitialized GValue in style_get_property
[widget] allow uninitialized GValue in style_get_property
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 690495 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-08-19 14:09 UTC by Paolo Borelli
Modified: 2018-02-10 03:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[widget] allow cleared GValue in style_get_property (1.90 KB, patch)
2012-08-19 14:09 UTC, Paolo Borelli
none Details | Review

Description Paolo Borelli 2012-08-19 14:09:54 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
Comment 1 Paolo Borelli 2012-08-19 14:09:56 UTC
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.
Comment 2 Paolo Borelli 2012-08-19 14:34:21 UTC
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?
Comment 3 Emmanuele Bassi (:ebassi) 2012-08-19 16:44:58 UTC
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.
Comment 4 Emmanuele Bassi (:ebassi) 2012-08-19 17:25:45 UTC
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.
Comment 5 Simon Feltman 2012-12-21 20:59:58 UTC
*** Bug 690495 has been marked as a duplicate of this bug. ***
Comment 6 Simon Feltman 2012-12-21 21:05:14 UTC
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.
Comment 7 Simon Feltman 2012-12-21 21:36:21 UTC
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.
Comment 8 Matthias Clasen 2018-02-10 03:29:57 UTC
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.