[py] avoid resizing py-source output
authorPaul Brossier <piem@piem.org>
Thu, 20 Dec 2018 21:35:07 +0000 (22:35 +0100)
committerPaul Brossier <piem@piem.org>
Thu, 20 Dec 2018 21:42:11 +0000 (22:42 +0100)
Make sure a copy of the source output is taken before resizing it.

python/ext/py-source.c

index 7687fbd..909416e 100644 (file)
@@ -573,7 +573,9 @@ 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);
+      PyArrayObject *shortread = (PyArrayObject*)
+        PyArray_FROM_OTF(PyTuple_GetItem(done, 0), NPY_NOTYPE,
+            NPY_ARRAY_ENSURECOPY);
       PyArray_Dims newdims;
       PyObject *reshaped;
       newdims.len = PyArray_NDIM(shortread);