summaryrefslogtreecommitdiff
path: root/tests/testsupport
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2012-07-08 18:19:40 +0200
committerStefan Behnel <stefan_ml@behnel.de>2012-07-08 18:19:40 +0200
commit7bbc99cb3cbf80d03b7d8e54ec8b01d2fccd4fa3 (patch)
treed1a0a26f080284566687e6d7bffbd8104090f075 /tests/testsupport
parent1924e95374ab11c3ce91eeb813da5442633dcfd7 (diff)
downloadcython-7bbc99cb3cbf80d03b7d8e54ec8b01d2fccd4fa3.tar.gz
fix tests by moving commonly used test helper file to a new test support directory
--HG-- rename : tests/memoryview/cythonarrayutil.pxi => tests/testsupport/cythonarrayutil.pxi
Diffstat (limited to 'tests/testsupport')
-rw-r--r--tests/testsupport/cythonarrayutil.pxi28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/testsupport/cythonarrayutil.pxi b/tests/testsupport/cythonarrayutil.pxi
new file mode 100644
index 000000000..50d764acd
--- /dev/null
+++ b/tests/testsupport/cythonarrayutil.pxi
@@ -0,0 +1,28 @@
+from libc.stdlib cimport malloc, free
+cimport cython
+from cython.view cimport array
+
+cdef void callback(void *data):
+ print "callback called"
+ free(data)
+
+def create_array(shape, mode, use_callback=False):
+ cdef array result = array(shape, itemsize=sizeof(int),
+ format='i', mode=mode)
+ cdef int *data = <int *> result.data
+ cdef int i, j, cidx, fidx
+
+ for i in range(shape[0]):
+ for j in range(shape[1]):
+ cidx = i * shape[1] + j
+ fidx = i + j * shape[0]
+
+ if mode == 'fortran':
+ data[fidx] = cidx
+ else:
+ data[cidx] = cidx
+
+ if use_callback:
+ result.callback_free_data = callback
+
+ return result