On 2009-10-12 15:00 PM, Chris Colbert wrote: > so I have this function: (the print statements are just for debugging) > > cdef np.npy_intp* clone_array_shape(np.ndarray arr): > # the proper way to do this would be to use malloc > # to create a new npy_intp* array of the proper size > # but then we would have to track it and make a call to free > # it's easier just to create the two different possible sizes > # on the stack. > > # only arrays with len(shape)== 2 or 3 will pass validation > cdef int ndim = arr.ndim > cdef np.npy_intp shape_2[2] > cdef np.npy_intp shape_3[3]
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. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
