'import zope.interface._zope_interface_coptimizations': Segmentation fault with Python 3

Bug #675064 reported by Arfrever Frehtes Taifersar Arahesis
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zope.interface
Fix Released
Undecided
Tres Seaver

Bug Description

$ python2.6 -c 'import zope.interface._zope_interface_coptimizations'
$ python2.7 -c 'import zope.interface._zope_interface_coptimizations'
$ python3.1 -c 'import zope.interface._zope_interface_coptimizations'
Segmentation fault
$ python3.2 -c 'import zope.interface._zope_interface_coptimizations'
Segmentation fault

There are also relevant compiler warnings:
src/zope/interface/_zope_interface_coptimizations.c:1684: warning: return type defaults to ‘int’
src/zope/interface/_zope_interface_coptimizations.c: In function ‘PyInit__zope_interface_coptimizations’:
src/zope/interface/_zope_interface_coptimizations.c:1685: warning: return makes integer from pointer without a cast

I'm attaching the patch.

Revision history for this message
Arfrever Frehtes Taifersar Arahesis (arfrever-fta) wrote :
Revision history for this message
Tres Seaver (tseaver) wrote :

Are you trying to reuse the Python2 .so file under Python3 without
rebuilding it? We aren't going to support that usecase; please just
rebuild it via:

  $ /path/to/python3 setup.py build_ext

Changed in zope.interface:
status: New → Incomplete
Revision history for this message
Arfrever Frehtes Taifersar Arahesis (arfrever-fta) wrote :

I don't try to reuse Python-2's .so files under Python-3. I use system Python. My package manager (Portage) has built zope.interface for Python 2.6, 2.7, 3.1 and 3.2. The paths to modules are:
/usr/lib64/python2.6/site-packages/zope/interface/_zope_interface_coptimizations.so
/usr/lib64/python2.7/site-packages/zope/interface/_zope_interface_coptimizations.so
/usr/lib64/python3.1/site-packages/zope/interface/_zope_interface_coptimizations.so
/usr/lib64/python3.2/site-packages/zope/interface/_zope_interface_coptimizations.cpython-32.so

This problem might occur only on 64-bit systems, where sizeof(int) != sizeof(pointer).

Revision history for this message
Tres Seaver (tseaver) wrote :

I can't reproduce this using "stock" Python 3.1.2 and a fresh checkout
of zope.interface::

 $ cd /tmp
 $ tar xzf ~/tarballs/Python-3.1.2.tar.bz2
 $ cd Python-3.1.2
 $ ./configure --prefix=/opt/Python-3.1.2 && make && sudo make install
 ...
 $ cd /tmp
 $ tar xjf ~/tarballs/distribute-0.6.10.tar.gz
 $ cd distribute-0.6.10
 $ sudo /opt/Python-3.1.2/bin/python3 setup.py install
 ...
 $ cd /tmp
 $ export ZSVN=svn+ssh://svn.zope.org/repos/main
 $ svn co $ZSVN/zope.interface/trunk zi-trunk
 $ cd zi-trunk
 $ /opt/Python-3.1.2/bin/python3 setup.py build
 ...
 $ /opt/Python-3.1.2/bin/python3 setup.py test
 ...
 ----------------------------------------------------------------------
 Ran 146 tests in 0.350s

 OK
 $ PYTHONPATH=build/lib.linux-i686-3.1/ \
  /opt/Python-3.1.2/bin/python3 \
  -c "import zope.interface._zope_interface_coptimizations"
 $ # no segfault

So, I would say this is an issue with the packaging for your system.

Changed in zope.interface:
status: Incomplete → Invalid
Changed in zope.interface:
status: Invalid → In Progress
Revision history for this message
Arfrever Frehtes Taifersar Arahesis (arfrever-fta) wrote :

I am packager of Python and Zope in Gentoo Linux and I know that there's no issue with the packaging. In C, functions defined without explicit type always return int. pyport.h defines PyMODINIT_FUNC as e.g. PyObject*. On 64-bit architectures: sizeof(int) == 32 bits, sizeof(pointer) == 64 bits. On 32-bit architectures: sizeof(int) == sizeof(pointer) == 32 bits. Lack of PyMODINIT_FUNC with Python 3 causes that the returned pointer is truncated on 64-bit architectures. You were using "PYTHONPATH=build/lib.linux-i686-3.1/", which suggests that you use a 32-bit architecture. Please read the patch, which I had attached. I also noticed that segmentation fault occurs only when some optimizations are enabled. I have exported CFLAGS="-march=core2 -O2".

Revision history for this message
Tres Seaver (tseaver) wrote :

"In progress" means that the bug is confirmed and that the assigne
committer is actively working to implement a fix. This bug fits neither
of those criteria: I can't reproduce your segfault on a "from source" Python
and a fresh checkout, and I'm certainly not going to check in your
patch without a way to reproduce it.

I recommend that you raise this issue to the distribution which made
the packages you are using: the ZTK team doesn't have any visibility
into the kinds of changes they may have made when packaging either
Python 3 or zope.interface. You could do more fault isolation, e.g.
by using the "system" python but working inside a downloaded tarball
(or SVN checkout).

Revision history for this message
Tres Seaver (tseaver) wrote :

Our messages seemed to have crossed. I will need to look at what the Python
C API requires across all our supported platforms to figure out how to
apply your patch. In particular, the return type required for module
initialization functions has changed between Python 2 and Python 3: I'm
suspicious of the conditional definitiion of PyMODULE_INITFUC higher in
that file.

Revision history for this message
Arfrever Frehtes Taifersar Arahesis (arfrever-fta) wrote :

You can't reproduce it, because you use 32-bit architecture. http://docs.python.org/py3k/extending/extending.html shows that PyMODINIT_FUNC is needed also with Python 3. Mistakenly placed '#if PY_MAJOR_VERSION < 3' causes that PyMODINIT_FUNC is used only with Python 2. If you don't have access to 64-bit architecture, then please wait for somebody using 64-bit architecture.

Revision history for this message
Tres Seaver (tseaver) wrote :

Fix committed on the trunk for the 3.6.2 release:

  http://svn.zope.org/zope.interface/trunk/?rev=118418&view=rev

Changed in zope.interface:
status: In Progress → Fix Committed
Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in zope.interface:
assignee: nobody → Tres Seaver (tseaver)
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.