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

fix C array assignments from lists of C arrays

parent 60490a4c
...@@ -6767,6 +6767,13 @@ class ListNode(SequenceNode): ...@@ -6767,6 +6767,13 @@ class ListNode(SequenceNode):
else: else:
offset = '' offset = ''
for i, arg in enumerate(self.args): for i, arg in enumerate(self.args):
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;" % ( code.putln("%s[%s%s] = %s;" % (
self.result(), self.result(),
i, i,
......
...@@ -76,6 +76,15 @@ def assign_int_array_array(): ...@@ -76,6 +76,15 @@ def assign_int_array_array():
return v 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(): def build_from_list_of_arrays():
""" """
>>> build_from_list_of_arrays() >>> build_from_list_of_arrays()
...@@ -87,6 +96,17 @@ def build_from_list_of_arrays(): ...@@ -87,6 +96,17 @@ def build_from_list_of_arrays():
return v 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: ctypedef struct MyStructType:
int x int x
double y 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