Cython + tuple unpacking

Discussion in 'Python' started by Hugues Salamin, Apr 23, 2009.

  1. 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
    --
    Hugues Salamin
     
    Hugues Salamin, Apr 23, 2009
    #1
    1. Advertising

  2. Hugues Salamin

    Aahz Guest

    In article <>,
    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


    Does this crash if you unpack the a,b tuple inside the loop?
    --
    Aahz () <*> http://www.pythoncraft.com/

    "If you think it's expensive to hire a professional to do the job, wait
    until you hire an amateur." --Red Adair
     
    Aahz, Apr 23, 2009
    #2
    1. Advertising

  3. 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
     
    Stefan Behnel, Apr 23, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul McGuire
    Replies:
    8
    Views:
    1,189
    Mark Wooding
    Nov 24, 2004
  2. James Stroud

    Tuple Unpacking in raise

    James Stroud, Jun 21, 2005, in forum: Python
    Replies:
    3
    Views:
    415
    James Stroud
    Jun 21, 2005
  3. harold
    Replies:
    11
    Views:
    573
    John Machin
    Apr 23, 2006
  4. Patrick Toomey

    Can my own objects support tuple unpacking?

    Patrick Toomey, Mar 27, 2008, in forum: Python
    Replies:
    2
    Views:
    314
  5. Martin Geisler

    Tuple parameter unpacking in 3.x

    Martin Geisler, Oct 2, 2008, in forum: Python
    Replies:
    20
    Views:
    778
    Aaron \Castironpi\ Brady
    Oct 11, 2008
Loading...

Share This Page