Commit 9a2a051c authored by Stefan Behnel's avatar Stefan Behnel

let += and -= inplace operators use pointer arithmetic when used on C strings...

let += and -= inplace operators use pointer arithmetic when used on C strings (instead of currently failing attempt at string concatenation)
parent f21e5878
......@@ -4716,6 +4716,9 @@ class InPlaceAssignmentNode(AssignmentNode):
if (self.lhs.is_subscript and
(self.lhs.memslice_index or self.lhs.is_buffer_access)):
self.rhs = self.rhs.coerce_to(self.lhs.type, env)
elif self.lhs.type.is_string and self.operator in '+-':
# use pointer arithmetic for char* LHS instead of string concat
self.rhs = self.rhs.coerce_to(PyrexTypes.c_py_ssize_t_type, env)
return self
def generate_execution_code(self, code):
......
......@@ -16,4 +16,4 @@ def test():
a |= b
p += 42
p -= 42
#p += a # FIXME: should use pointer arithmetic, not string concat
p += a
......@@ -152,3 +152,17 @@ def coerce_uint_bytes_assign(unsigned int c):
"""
cdef bytes s = c
return s
def inplace_ops_use_arithmetic():
"""
>>> print(inplace_ops_use_arithmetic().decode('ascii'))
bc
"""
cdef char* s = 'abc'
cdef object x = 1
s += 1
s += 2*x
s -= 1
s -= x
return s
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