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