Commit 6704d23e authored by Stefan Behnel's avatar Stefan Behnel

Re-allow copy assignments from const memory views into read/write memory views.

parent 7c63e2d1
...@@ -782,8 +782,8 @@ class MemoryViewSliceType(PyrexType): ...@@ -782,8 +782,8 @@ class MemoryViewSliceType(PyrexType):
src = self src = self
if self.writable_needed and not dst.writable_needed: #if not copying and self.writable_needed and not dst.writable_needed:
return False # return False
src_dtype, dst_dtype = src.dtype, dst.dtype src_dtype, dst_dtype = src.dtype, dst.dtype
if dst_dtype.is_const: if dst_dtype.is_const:
...@@ -792,6 +792,9 @@ class MemoryViewSliceType(PyrexType): ...@@ -792,6 +792,9 @@ class MemoryViewSliceType(PyrexType):
if src_dtype.is_const: if src_dtype.is_const:
# When assigning between read-only views, compare only the non-const base types. # When assigning between read-only views, compare only the non-const base types.
src_dtype = src_dtype.const_base_type src_dtype = src_dtype.const_base_type
elif copying and src_dtype.is_const:
# Copying by value => ignore const on source.
src_dtype = src_dtype.const_base_type
if src_dtype != dst_dtype: if src_dtype != dst_dtype:
return False return False
......
...@@ -88,3 +88,25 @@ def test_const_mmview_ro(x): ...@@ -88,3 +88,25 @@ def test_const_mmview_ro(x):
x.setflags(write=False) x.setflags(write=False)
assert x.flags.writeable is False assert x.flags.writeable is False
return getconst(x) return getconst(x)
def test_two_views(x):
"""
>>> test_two_views(new_array())
23.0
"""
cdef double[:] rw = x
cdef const double[:] ro = rw
rw[0] = 23
return ro[0]
def test_assign_ro_to_rw(x):
"""
>>> test_assign_ro_to_rw(new_array())
2.0
"""
cdef const double[:] ro = x
cdef double[:] rw = np.empty_like(ro)
rw[:] = ro
return rw[2]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment