diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2015-02-07 15:37:58 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2015-02-07 15:37:58 +0100 |
commit | 2b3354206af4ba0b12952358c04160dc05f8905a (patch) | |
tree | 3a89266d427467860512ff2cfaf7d598c37d6776 | |
parent | 60490a4c95e96faaee0e07982a1a0652ce08cb4f (diff) | |
download | cython-2b3354206af4ba0b12952358c04160dc05f8905a.tar.gz |
fix C array assignments from lists of C arrays
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 17 | ||||
-rw-r--r-- | tests/run/carray_coercion.pyx | 20 |
2 files changed, 32 insertions, 5 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 61143c9df..f99ec6e92 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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("}") diff --git a/tests/run/carray_coercion.pyx b/tests/run/carray_coercion.pyx index 5c313e4e6..a3b97b757 100644 --- a/tests/run/carray_coercion.pyx +++ b/tests/run/carray_coercion.pyx @@ -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 |