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 692515 - Differentiate Python created GType enum names to avoid registration problems
Differentiate Python created GType enum names to avoid registration problems
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
3.7.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-01-25 10:22 UTC by David Klasinc
Modified: 2013-01-31 01:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Obfuscate names of typeless enum and flags for GType registration (3.05 KB, patch)
2013-01-27 09:32 UTC, Simon Feltman
committed Details | Review
Prefix names of typeless enums and flags for GType registration (3.05 KB, patch)
2013-01-31 01:52 UTC, Simon Feltman
committed Details | Review

Description David Klasinc 2013-01-25 10:22:54 UTC
Trying to use Gstreamer in the latest Ubuntu Raring results in a runtime error.

How to reproduce:

$ python3
>>> from gi.repository import Gst
>>> Gst.init(None)
[]
>>> pipeline = Gst.Pipeline()
>>> pipeline.set_state(Gst.State.PLAYING)

This will result in:

/usr/lib/python3/dist-packages/gi/module.py:153: Warning: cannot register existing type `GstState'
Traceback (most recent call last):
  • File "<stdin>", line 1 in <module>
  • File "/usr/lib/python3/dist-packages/gi/module.py", line 316 in __getattr__
    return getattr(self._introspection_module, name)
  • File "/usr/lib/python3/dist-packages/gi/module.py", line 153 in __getattr__
    wrapper = enum_register_new_gtype_and_add(info)
RuntimeError: Unable to register enum 'GstState'

Comment 1 Iain Lane 2013-01-25 10:25:50 UTC
The example above works in Quantal with python-gi

  3.4.0-1ubuntu0.1

but in Raring, using

  3.7.3-0ubuntu2

we get the RuntimeError above.
Comment 2 Simon Feltman 2013-01-25 13:08:36 UTC
Looks like this is fallout from the fix for bug 690455.

Details:
Enums now are created with proper names in pygobject. This exposed another bug with how gi/module.py uses g_registered_type_info_get_g_type. Note the docs for this method specify a return of G_TYPE_NONE has a "special meaning":

http://developer.gnome.org/gi/unstable/gi-GIRegisteredTypeInfo.html#g-registered-type-info-get-g-type

Currently when TYPE_NONE is returned it is assumed the type is not registered and pygobject tries to create and register a new type. Instead pygobject should test if the type is already registered not only with gi but glib. I do not see a "g_type_is_registered" method, so we might have to do something a bit more hacky like catching an exception raised from g_type_from_name (GObject.type_from_name).

See:
http://git.gnome.org/browse/pygobject/tree/gi/module.py?id=3.7.4#n137
Comment 3 Simon Feltman 2013-01-27 08:50:48 UTC
It turns out the root cause of this and bug 690455 seems to be that Gst.State does not supply a "get_type" method in the typelib. This compounded by pygobject trying to register new GTypes for enums and flags which don't supply this method does not help. We can add a quick fix to pygobject which obfuscates enum and flags types it creates and registers with GLib. But we really need to find out why gir creation is not supplying GstState with a "glib:get-type" property. For instance, with GstVideoFormat we see a fully filled out gir definition:

     <enumeration name="VideoFormat"
                 glib:type-name="GstVideoFormat"
                 glib:get-type="gst_video_format_get_type"
                 c:type="GstVideoFormat">

GstState only shows the following annotation:

     <enumeration name="State" c:type="GstState">

In the eyes of pygobject (or any introspection based bindings) this is a "typeless" enum and so it tries to create a GType for it causing different problems depending on if Gst.init is called before or after accessing it.
Comment 4 Simon Feltman 2013-01-27 09:32:25 UTC
Created attachment 234516 [details] [review]
Obfuscate names of typeless enum and flags for GType registration

Prefix names given to g_flags_register_static and g_enum_register_static
with "Py". This avoids conflicts with GTypes of the same name being
registered later by a library which does not provide a "get-type"
annotation.
Comment 5 Simon Feltman 2013-01-29 06:00:39 UTC
Dropping priority on this because the problem has been fixed by bug 691185. However, I still think the proposed patch should go in to further differentiate pygobject created enum GTypes from others because they are only temporarily used for the purpose of creating and filling out an enum.
Comment 6 Simon Feltman 2013-01-31 01:52:09 UTC
Pushing as this is a simple fix that probably doesn't need review.

The following fix has been pushed:
571e0cb Prefix names of typeless enums and flags for GType registration
Comment 7 Simon Feltman 2013-01-31 01:52:14 UTC
Created attachment 234878 [details] [review]
Prefix names of typeless enums and flags for GType registration

Prefix names given to g_flags_register_static and g_enum_register_static
with "Py". This avoids conflicts with GTypes of the same name being
registered later by a library which does not provide a "get-type"
annotation.