GNOME Bugzilla – Bug 761592
Passing boxed structure as a GValue in a function fails
Last modified: 2016-03-02 05:16: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;'
Created attachment 320499 [details] [review] test: check passing Boxed type in GValue as function paramatters
Created attachment 320500 [details] [review] test: check passing Boxed type in GValue as function paramatters
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")
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)
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.
Created attachment 322723 [details] [review] tests: check passing Boxed type in GValue as function parameters Removed unused variable and fixed spelling in commit message.
Review of attachment 322721 [details] [review]: Looks good to me, thanks for that patch :)
Review of attachment 322721 [details] [review]: Committed: https://git.gnome.org/browse/pygobject/commit/?id=5f4b08f4e8
Review of attachment 322723 [details] [review]: Committed: https://git.gnome.org/browse/pygobject/commit/?id=cc75f994a07