Cython + tuple unpacking

H

Hugues Salamin

Hello,

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".

I investigated the error with valgrind and gdb but I still have no clue what is
going on.

I'm on Ubuntu 8.04, Kernel 2.6.24-22-generic

Thanks
 
A

Aahz

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

Does this crash if you unpack the a,b tuple inside the loop?
 
S

Stefan Behnel

Hugues said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top