Commit 3b609241 authored by Mark Florisson's avatar Mark Florisson

Do not deallocate cython.array buffer if user-allocated

parent e71755fd
......@@ -33,8 +33,9 @@ cdef class array:
Py_ssize_t itemsize
unicode mode
bytes _format
void (*callback_free_data)(char *data)
void (*callback_free_data)(void *data)
# cdef object _memview
cdef bint free_data
def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format,
mode=u"c", bint allocate_buffer=True):
......@@ -95,6 +96,7 @@ cdef class array:
mode = decode('ASCII')
self.mode = mode
self.free_data = allocate_buffer
if allocate_buffer:
self.data = <char *>malloc(self.len)
if not self.data:
......@@ -127,7 +129,7 @@ cdef class array:
def __dealloc__(array self):
if self.callback_free_data != NULL:
self.callback_free_data(self.data)
else:
elif self.free_data:
free(self.data)
self.data = NULL
......
from libc.stdlib cimport malloc, free
cimport cython
cdef void callback(char *data):
cdef void callback(void *data):
print "callback called"
free(data)
def create_array(shape, mode, use_callback=False):
cdef cython.array result = cython.array(shape, itemsize=sizeof(int),
......
......@@ -215,7 +215,7 @@ cdef extern from "bufaccess.h":
ctypedef unsigned int td_h_ushort # Defined as unsigned short
ctypedef td_h_short td_h_cy_short
cdef void dealloc_callback(char *data):
cdef void dealloc_callback(void *data):
print "deallocating..."
def index(cython.array array):
......
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