shithub: aubio

Download patch

ref: 966c65065c439fbc725650df96603086f346530d
parent: 79dc9adb6a541b1929227ded5d53730686fbc3d6
author: Paul Brossier <piem@piem.org>
date: Sun Dec 23 00:46:47 EST 2018

[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.

--- a/python/ext/py-source.c
+++ b/python/ext/py-source.c
@@ -581,7 +581,10 @@
       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 @@
       }
       reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER);
       Py_DECREF(shortread);
+      Py_DECREF(vec);
       return reshaped;
     } else {
       PyErr_SetNone(PyExc_StopIteration);