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 709183 - Segmentation Fault when help('modules') is typed
Segmentation Fault when help('modules') is typed
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-01 12:03 UTC by mulhern
Modified: 2014-08-06 05:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add protection against attempts at importing static bindings (3.50 KB, patch)
2014-08-06 05:56 UTC, Simon Feltman
committed Details | Review

Description mulhern 2013-10-01 12:03:29 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)
Comment 1 Simon Feltman 2013-10-16 19:17:45 UTC
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?
Comment 2 mulhern 2013-10-16 20:11:46 UTC
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.
Comment 3 Simon Feltman 2013-10-16 21:28:17 UTC
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.
Comment 4 Martin Pitt 2013-10-17 04:00:36 UTC
(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!
Comment 5 Simon Feltman 2014-08-06 05:56:47 UTC
The following fix has been pushed:
d704033 Add protection against attempts at importing static bindings
Comment 6 Simon Feltman 2014-08-06 05:56:50 UTC
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.