Commit cc419833 authored by Mark Florisson's avatar Mark Florisson

Support inplace assignment for memoryviews and buffers

parent 9f672d71
......@@ -5050,9 +5050,16 @@ class InPlaceAssignmentNode(AssignmentNode):
self.lhs.analyse_target_declaration(env)
def analyse_types(self, env):
import ExprNodes
self.rhs.analyse_types(env)
self.lhs.analyse_target_types(env)
# When assigning to a fully indexed buffer or memoryview, coerce the rhs
if (isinstance(self.lhs, ExprNodes.IndexNode) and
(self.lhs.memslice_index or self.lhs.is_buffer_access)):
self.rhs = self.rhs.coerce_to(self.lhs.type, env)
def generate_execution_code(self, code):
import ExprNodes
self.rhs.generate_evaluation_code(code)
......
......@@ -1127,3 +1127,17 @@ def buffer_nogil_oob():
with nogil:
buf[5] = 10
return buf[1]
def get_int():
return 10
@testcase
def test_inplace_assignment():
"""
>>> test_inplace_assignment()
10
"""
cdef object[int, ndim=1] buf = IntMockBuffer(None, [1, 2, 3])
buf[0] = get_int()
print buf[0]
......@@ -2202,3 +2202,17 @@ def test_noneslice_del():
del m
print m
def get_int():
return 10
@testcase
def test_inplace_assignment():
"""
>>> test_inplace_assignment()
10
"""
cdef int[10] a
cdef int[:] m = a
m[0] = get_int()
print m[0]
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