[Cython] Bug, or changed array assignment in 0.17beta1?
Stefan Behnel
stefan_ml at behnel.de
Wed Jul 25 07:40:31 CEST 2012
Hi,
thanks for the report.
Mike Zaletel, 25.07.2012 00:40:
> The exact behavior of array assignment was never entirely clear to me
Yes, it's not entirely obvious.
> but I am certain the following behavior did not occur in 0.16:
>
> --------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.
Stefan
More information about the cython-devel
mailing list