From: Paul Brossier Date: Sun, 23 Dec 2018 04:46:47 +0000 (+0100) Subject: [py] take a copy for the last source block when iterating X-Git-Tag: 0.4.9~15 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=966c65065c439fbc725650df96603086f346530d [py] take a copy for the last source block when iterating Appears to be the simplest solution to prevent resizing internal objects. See also 8e76c71. --- diff --git a/python/ext/py-source.c b/python/ext/py-source.c index d3c28e80..3ef4eb40 100644 --- a/python/ext/py-source.c +++ b/python/ext/py-source.c @@ -581,7 +581,10 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { return vec; } else if (PyLong_AsLong(size) > 0) { // short read, return a shorter array - PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0); + PyObject *vec = PyTuple_GetItem(done, 0); + // take a copy to prevent resizing internal arrays + PyArrayObject *shortread = PyArray_FROM_OTF(vec, NPY_NOTYPE, + NPY_ARRAY_ENSURECOPY); PyArray_Dims newdims; PyObject *reshaped; newdims.len = PyArray_NDIM(shortread); @@ -594,6 +597,7 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { } reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); Py_DECREF(shortread); + Py_DECREF(vec); return reshaped; } else { PyErr_SetNone(PyExc_StopIteration);