[Numpy-discussion] PyArray_Resize reference counting

Travis E. Oliphant oliphant@enthought....
Tue Sep 30 15:26:08 CDT 2008


Ravi wrote:
> Hi,
>   Consider the following code:
>
>    PyArrayObject *array = get_me_an_array_along_with_a_reference(); /* 1 */
>    PyArray_Dims *dims = get_me_some_dims(); /* 2 */
>    array = (PyArrayObject *)PyArray_Resize( array, dims, 1 ); /* 3 */
>
> Is the code above valid? 
No.

You need to do something like:

temp = PyArray_Resize(array,...)
Py_DECREF(array)
array = temp

-Travis



More information about the Numpy-discussion mailing list