Commit 610c112a authored by Stefan Behnel's avatar Stefan Behnel

fix carray assignments to char arrays and IndexNode

parent 48fa8563
......@@ -3884,24 +3884,23 @@ class SliceIndexNode(ExprNode):
check_negative_indices(self.start, self.stop)
base_type = self.base.type
if base_type.is_string or base_type.is_cpp_string:
if base_type.is_array and not getting:
# cannot assign directly to C array => try to assign by making a copy
if not self.start and not self.stop:
self.type = base_type
else:
self.type = PyrexTypes.CPtrType(base_type.base_type)
elif base_type.is_string or base_type.is_cpp_string:
self.type = default_str_type(env)
elif base_type.is_pyunicode_ptr:
self.type = unicode_type
elif base_type.is_ptr:
self.type = base_type
elif base_type.is_array:
if getting:
# we need a ptr type here instead of an array type, as
# array types can result in invalid type casts in the C
# code
self.type = PyrexTypes.CPtrType(base_type.base_type)
else:
# try to assign 'by value' (i.e. make a copy)
if not self.start and not self.stop:
self.type = base_type
else:
self.type = PyrexTypes.CPtrType(base_type.base_type)
else:
self.base = self.base.coerce_to_pyobject(env)
self.type = py_object_type
......
......@@ -4758,7 +4758,7 @@ class SingleAssignmentNode(AssignmentNode):
self.lhs.is_memslice_scalar_assignment = True
dtype = self.lhs.type.dtype
elif self.lhs.type.is_array:
if not isinstance(self.lhs, (ExprNodes.IndexNode, ExprNodes.SliceIndexNode)):
if not isinstance(self.lhs, ExprNodes.SliceIndexNode):
# cannot assign to C array, only to its full slice
self.lhs = ExprNodes.SliceIndexNode(
self.lhs.pos, base=self.lhs, start=None, stop=None)
......
......@@ -18,7 +18,7 @@ cdef {{struct_name}} {{funcname}}(obj) except *:
value = obj['{{member.name}}']
except KeyError:
raise ValueError("No value specified for struct attribute '{{member.name}}'")
result.{{member.cname}}{{'[:]' if member.type.is_array else ''}} = value
result.{{member.cname}} = value
{{endfor}}
return result
......
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