shithub: aubio

Download patch

ref: 8b7cdbad05db492a86eef2dc48bba1740b6afdf1
parent: 410a157f8b8271051a5a48d03347be90609bd0b9
author: Paul Brossier <piem@piem.org>
date: Mon Feb 27 12:21:34 EST 2017

python/ext/py-source.c: use PyArray_NewShape, not _Resize

--- a/python/ext/py-source.c
+++ b/python/ext/py-source.c
@@ -310,9 +310,10 @@
       PyObject *vec = PyTuple_GetItem(done, 0);
       return vec;
     } else if (PyLong_AsLong(size) > 0) {
-      // short read
+      // short read, return a shorter array
       PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0);
       PyArray_Dims newdims;
+      PyObject *reshaped;
       newdims.len = PyArray_NDIM(shortread);
       newdims.ptr = PyArray_DIMS(shortread);
       // mono or multiple channels?
@@ -321,8 +322,9 @@
       } else {
         newdims.ptr[1] = PyLong_AsLong(size);
       }
-      PyArray_Resize(shortread, &newdims, 1, NPY_ANYORDER);
-      return (PyObject*)shortread;
+      reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER);
+      Py_DECREF(shortread);
+      return reshaped;
     } else {
       PyErr_SetNone(PyExc_StopIteration);
       return NULL;