Cython + tuple unpacking

Stefan Behnel stefan_ml at behnel.de
Thu Apr 23 16:39:49 EDT 2009


Hugues Salamin wrote:
> The following code will crash with a segfault when compiled using cython (v0.11)
> 
> def func():
>     for (a, b) ,c ,d in zip(zip(range(3), range(3)), range(3), range(3)):
>         print a, b
>         print c
>         print d # This line segfault
> 
> Compilation is done using distutils.
> 
> If the module is imported in python and func is called, I got a segmentation
> fault at the line "print d".

Yes, this works for me in the latest (unstable) developer branch, but fails
in the release branch:

  $ cd cython-unstable
  $ cat rangeloop.pyx
  def func():
      for (a, b) ,c ,d in zip(zip(range(3), range(3)), range(3), range(3)):
          print a, b
          print c
          print d # This line segfault

  $ python2.6 -c 'import pyximport; pyximport.install(); \
                                 import rangeloop; rangeloop.func()'
  0 0
  0
  0
  1 1
  1
  1
  2 2
  2
  2

  $ cd ../cython-release
  $ python2.6 -c 'import pyximport; pyximport.install(); \
                                 import rangeloop; rangeloop.func()'
  0 0
  0
  Segmentation fault

Not sure why. I'm moving this to the Cython mailing list, we should be able
to help you there.

Stefan



More information about the Python-list mailing list