Commit 2b335420 authored by Stefan Behnel's avatar Stefan Behnel

fix C array assignments from lists of C arrays

parent 60490a4c
......@@ -6767,11 +6767,18 @@ class ListNode(SequenceNode):
else:
offset = ''
for i, arg in enumerate(self.args):
code.putln("%s[%s%s] = %s;" % (
self.result(),
i,
offset,
arg.result()))
if arg.type.is_array:
code.globalstate.use_utility_code(UtilityCode.load_cached("IncludeStringH", "StringTools.c"))
code.putln("memcpy(&(%s[%s%s]), %s, sizeof(%s[0]));" % (
self.result(), i, offset,
arg.result(), self.result()
))
else:
code.putln("%s[%s%s] = %s;" % (
self.result(),
i,
offset,
arg.result()))
if self.mult_factor:
code.putln("}")
code.putln("}")
......
......@@ -76,6 +76,15 @@ def assign_int_array_array():
return v
def assign_int_array_array_from_tuples():
"""
>>> assign_int_array_array_from_tuples()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[2][3] v = ([11, 12, 13], [21, 22, 23])
return v
def build_from_list_of_arrays():
"""
>>> build_from_list_of_arrays()
......@@ -87,6 +96,17 @@ def build_from_list_of_arrays():
return v
def build_from_tuple_of_arrays():
"""
>>> build_from_tuple_of_arrays()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[3] x = [11, 12, 13]
cdef int[3] y = [21, 22, 23]
cdef int[2][3] v = (x, y)
return v
ctypedef struct MyStructType:
int x
double y
......
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