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 761592 - Passing boxed structure as a GValue in a function fails
Passing boxed structure as a GValue in a function fails
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 685197
Blocks:
 
 
Reported: 2016-02-05 14:13 UTC by Thibault Saunier
Modified: 2016-03-02 05:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test: check passing Boxed type in GValue as function paramatters (6.67 KB, patch)
2016-02-05 14:13 UTC, Thibault Saunier
none Details | Review
test: check passing Boxed type in GValue as function paramatters (4.65 KB, patch)
2016-02-05 14:14 UTC, Thibault Saunier
none Details | Review
gerror: Add special case marshaling for boxing GErrors (4.31 KB, patch)
2016-03-01 07:46 UTC, Simon Feltman
committed Details | Review
test: check passing Boxed type in GValue as function paramatters (5.53 KB, patch)
2016-03-01 07:48 UTC, Simon Feltman
none Details | Review
tests: check passing Boxed type in GValue as function parameters (5.09 KB, patch)
2016-03-01 07:53 UTC, Simon Feltman
committed Details | Review

Description Thibault Saunier 2016-02-05 14:13:12 UTC
Instead of properly passing the boxed structure setting the G_VALUE_TYPE
to the GType associated with that boxed type structure, it sets GI_TYPE_OBJECT
('PyGbject') and passes some PyGobject internal objects to the function. No one
outside PyGObject will be able to use it.

A good example in real world would be:


```
import gi
gi.require_version("Gst", 1.0)

from gi.repository import Gst, GLib

st = Gst.Structure.new_empty("test")
st["error"] = GLib.Error()

print(st.to_string())
```

which outputs:

'test, error=(PyObject)NULL;'
Comment 1 Thibault Saunier 2016-02-05 14:13:15 UTC
Created attachment 320499 [details] [review]
test: check passing Boxed type in GValue as function paramatters
Comment 2 Thibault Saunier 2016-02-05 14:14:06 UTC
Created attachment 320500 [details] [review]
test: check passing Boxed type in GValue as function paramatters
Comment 3 Thibault Saunier 2016-02-05 16:16:00 UTC
Actually we I am blocked in the GError case here, for other types I could do:

```
GObject.Value.init(v, Gst.Structure)
v.set_value(Gst.Structure.new_empty("yes"))
s = Gst.Structure.new_empty("test")
s['test'] = v

print(s.to_string())
```

> Yop, test=(structure)"yes\;";

But with GError which is treated quite differently (I bet because it is used for Exception handling) and I can not initialise a GValue with GError:

```
In [4]: v = GObject.Value()

In [5]: v.init(GLib.Error)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-d241640f4020> in <module>()
----> 1 v.init(GLib.Error)

TypeError: Must be gobject.GType, not type
```

Also interestingly:

In [6]: GObject.type_from_name("GError")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-736fef6c0f42> in <module>()
----> 1 GObject.type_from_name("GError")

/usr/lib/python3.5/site-packages/gi/overrides/GObject.py in type_from_name(name)
    359     type_ = GObjectModule.type_from_name(name)
    360     if type_ == TYPE_INVALID:
--> 361         raise RuntimeError('unknown type name: %s' % name)
    362     return type_
    363 

RuntimeError: unknown type name: GError

But:

In [7]: GObject.type_from_name("GstStructure")
Out[7]: <GType GstStructure (14618448)>


(and yes I double checked the GError GType name is... "GError")
Comment 4 Simon Feltman 2016-03-01 07:46:28 UTC
Created attachment 322721 [details] [review]
gerror: Add special case marshaling for boxing GErrors

Transfer gtype from introspection GError class to Python GError implementation. Expose the PyGError pointer as an extern so other C files can pick this up. Add custom to/from GValue marshalers for GError. Add tests for both complete and incomplete (no boxed pointer held).

(this requires patches from bug 685197 to be applied first)
Comment 5 Simon Feltman 2016-03-01 07:48:14 UTC
Created attachment 322722 [details] [review]
test: check passing Boxed type in GValue as function paramatters

This patch needed use the "dist_" prefix for the new sources as well as explicitly specify $(srcdir) as their location in order for distcheck to work.
Comment 6 Simon Feltman 2016-03-01 07:53:33 UTC
Created attachment 322723 [details] [review]
tests: check passing Boxed type in GValue as function parameters

Removed unused variable and fixed spelling in commit message.
Comment 7 Thibault Saunier 2016-03-01 09:48:21 UTC
Review of attachment 322721 [details] [review]:

Looks good to me, thanks for that patch :)