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 682323 - Dynamic creation of enum and flag gi types crashes in Python 3.3
Dynamic creation of enum and flag gi types crashes in Python 3.3
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-08-21 01:50 UTC by Simon Feltman
Modified: 2012-08-23 03:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixed immediate problems with python 3.3 (3.90 KB, patch)
2012-08-22 03:41 UTC, Simon Feltman
none Details | Review

Description Simon Feltman 2012-08-21 01:50:35 UTC
Importing Gtk will crash on the dynamic creation of Enum and Flag subclasses due to what looks to be an unsupported technique. The crash itself is happening because there is no NULL check after calling the C equivalent to "int.__new__". 

Stepping the code reveals python is trying to raise something like this:
TypeError: int.__new__(GtkSizeGroupMode) is not safe, use GtkSizeGroupMode.__new__()

In: <PythonSrc>/Object/typeobject.c : ~4848

The issue is Enum and Flag subclasses are setup in a tricky way and we cannot create the initial cached enum values using the dynamic subclasses standard creation method. Sudo code:

<static class>
class Enum(int):
    __new__ = int.__new__

<dynamic class>
class GtkSizeGroupMode(Enum):
    def __new__(cls, val):
        return self.__enum_values__[val]
GtkSizeGroupMode.__enum_values__ = [int.__new__(...), ...]

I have a fix for this but I would also like to include some refactoring to add clarity.
Comment 1 Simon Feltman 2012-08-22 03:41:24 UTC
Created attachment 222099 [details] [review]
Fixed immediate problems with python 3.3

This patch fixes the immediate problems seen in python 3.3 and I've logged some observations about PyGEnum and PyGFlags here: https://bugzilla.gnome.org/show_bug.cgi?id=682405

Tested 'make check' with Python 2.7, 3.2, and 3.3b2 and everything passes. I was unable to test Python 2.5 and 2.6 due to build errors: https://bugzilla.gnome.org/show_bug.cgi?id=682422
Comment 2 Martin Pitt 2012-08-23 03:48:56 UTC
Thanks! Committed with some changelog refinement.