From 7bbc99cb3cbf80d03b7d8e54ec8b01d2fccd4fa3 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 8 Jul 2012 18:19:40 +0200 Subject: 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 --- tests/testsupport/cythonarrayutil.pxi | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/testsupport/cythonarrayutil.pxi (limited to 'tests/testsupport') 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 = 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 -- cgit v1.2.1