GNOME Bugzilla – Bug 682323
Dynamic creation of enum and flag gi types crashes in Python 3.3
Last modified: 2012-08-23 03:48:56 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.
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
Thanks! Committed with some changelog refinement.