GNOME Bugzilla – Bug 709183
Segmentation Fault when help('modules') is typed
Last modified: 2014-08-06 05:56:50 UTC
Info: $ uname -a Linux localhost.localdomain 3.11.1-200.fc19.x86_64 #1 SMP Sat Sep 14 15:04:51 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Steps to reproduce and error: $ python Python 2.7.5 (default, Aug 22 2013, 09:31:58) [GCC 4.8.1 20130603 (Red Hat 4.8.1-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import Gdk >>> help('modules') Please wait a moment while I gather a list of all available modules... dm.c: 1693: not running as root returning empty list /usr/lib64/python2.7/site-packages/gobject/constants.py:24: Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed import gobject._gobject /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: cannot register existing type `GdkWindow' from gtk import _gtk /usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed from gtk import _gtk Segmentation fault (core dumped)
There is something odd here: in the call stack "import gobject._gobject" and "from gtk import _gtk" are PyGTK, not PyGObject3 packages. I'm not sure how those are showing up but they cannot be mixed into PyGObject3. Are they somehow autoloaded by your Python interpreter, do you have $PYTHONSTARTUP set to something which imports them?
I tried the following and got nothing. [mulhern@localhost ~]$ echo $PYTHONSTARTUP As far as I know the interpreter I'm using is the one that came out of the box.
I didn't realize "help('modules')" was a magic easter egg that tries to import all modules... The issue is basically the same as: >>> from gi.repository import Gdk >>> import gtk Segmentation fault (core dumped) In PyGI, we detect the reverse of this: >>> import gtk >>> from gi.repository import Gdk ImportError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". I'm pretty sure the problem is along the lines of not being able to import gtk2 and gtk3 into the same process due to symbol conflicts. I think the only potential fix here would be to have "from gi.repository import Gdk" clobber sys.modules['gobject/gdk/gtk'] that when used, gives an exception which is more helpful than a segfault.
(In reply to comment #3) > I'm pretty sure the problem is along the lines of not being able to import gtk2 > and gtk3 into the same process due to symbol conflicts. Indeed. I really wonder if those are the only kinds of mutually exclusive modules that exist. It seems quite dangerous to try and import *all* available modules (and expensive, too). > I think the only > potential fix here would be to have "from gi.repository import Gdk" clobber > sys.modules['gobject/gdk/gtk'] that when used, gives an exception which is more > helpful than a segfault. As usual, great idea!
The following fix has been pushed: d704033 Add protection against attempts at importing static bindings
Created attachment 282629 [details] [review] Add protection against attempts at importing static bindings Clobber gobject, gio, glib, gtk, and gtk.gdk in sys.modules upon importing gi with dummy modules which produce an error upon access.