Commit 7a47dfda authored by Stefan Behnel's avatar Stefan Behnel

fix crash when assigning memoryviews through ternary conditional expressions

parent dc70708e
...@@ -80,6 +80,8 @@ Optimizations ...@@ -80,6 +80,8 @@ Optimizations
Bugs fixed Bugs fixed
---------- ----------
* Crash when assigning memory views from ternary conditional expressions.
* Nested C++ templates could lead to unseparated ">>" characters being * Nested C++ templates could lead to unseparated ">>" characters being
generated into the C++ declarations, which older C++ compilers could generated into the C++ declarations, which older C++ compilers could
not parse. not parse.
......
...@@ -10156,6 +10156,9 @@ class CondExprNode(ExprNode): ...@@ -10156,6 +10156,9 @@ class CondExprNode(ExprNode):
def eval_and_get(self, code, expr): def eval_and_get(self, code, expr):
expr.generate_evaluation_code(code) expr.generate_evaluation_code(code)
if self.type.is_memoryviewslice:
expr.make_owned_memoryviewslice(code)
else:
expr.make_owned_reference(code) expr.make_owned_reference(code)
code.putln('%s = %s;' % (self.result(), expr.result_as(self.ctype()))) code.putln('%s = %s;' % (self.result(), expr.result_as(self.ctype())))
expr.generate_post_assignment_code(code) expr.generate_post_assignment_code(code)
......
...@@ -978,3 +978,37 @@ def test_dtype_object_scalar_assignment(): ...@@ -978,3 +978,37 @@ def test_dtype_object_scalar_assignment():
(<object> m)[:] = SingleObject(3) (<object> m)[:] = SingleObject(3)
assert m[0] == m[4] == m[-1] == 3 assert m[0] == m[4] == m[-1] == 3
def test_assignment_in_conditional_expression(bint left):
"""
>>> test_assignment_in_conditional_expression(True)
1.0
2.0
1.0
2.0
>>> test_assignment_in_conditional_expression(False)
3.0
4.0
3.0
4.0
"""
cdef double a[2]
cdef double b[2]
a[:] = [1, 2]
b[:] = [3, 4]
cdef double[:] A = a
cdef double[:] B = b
cdef double[:] C, c
# assign new memoryview references
C = A if left else B
for i in range(C.shape[0]):
print C[i]
# create new memoryviews
c = a if left else b
for i in range(c.shape[0]):
print c[i]
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