[Cython] Bug, or changed array assignment in 0.17beta1?

Stefan Behnel stefan_ml at behnel.de
Wed Jul 25 07:55:29 CEST 2012


Stefan Behnel, 25.07.2012 07:40:
> Mike Zaletel, 25.07.2012 00:40:
>> --------bug.pyx----------
>> def foo():
>>        cdef int i
>>        cdef int* p1 = [4, 4]
>>        cdef int* p2 = [5, 5]
>>
>>        print "p1:",
>>        for i in range(2):
>>                print p1[i],
>>        print "\np2:",
>>        for i in range(2):
>>                print p2[i],
>> -----------------------------
>>
>> which in Cython 0.17beta1 gives me
>>
>> >>> import bug
>> >>> bug.foo()
>> p1: 5 5
>> p2: 5 5
>>
>>
>> while in Cython 0.16 I get
>>
>> >>> import bug
>> >>> bug.foo()
>> p1: 4 4
>> p2: 5 5
> 
> The problem is that the same (temporary) local array variable is used in
> both cases to build the array, and then only a pointer is assigned, i.e. p1
> and p2 then point to the same array, which gets overwritten with the new
> values in the second assignment.

Oh, just in case I wasn't clear: you've found a bug.

Stefan



More information about the cython-devel mailing list