Robert Kern skrev:
>
> This is your problem. The reason that you don't have to keep track of the 
> pointer and free() it with declarations like these is that they *only* live 
> inside the function. You cannot return them. You must PyMem_Malloc() an 
> appropriately sized pointer, return the pointer, and PyMem_Free() it later.
>
>   

Or one could just use a numpy ndarray. Something like this (not tested):

cdef np.ndarray clone_array_shape(np.ndarray arr) except -1:
    cdef np.npy_intp ndim =  arr.ndim, i
    cdef np.ndarray[np.npy_intp] shape = np.zeros(ndim, dtype=int)
    for i in range(ndim): shape[i] =  arr.shape[i]
    return shape

Which avoids possible memory leaks by not calling free, and avoids the 
need to error check in the return value from malloc.


S.M.




_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to