Appears to be the simplest solution to prevent resizing internal objects. See also 8e76c71.
Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -581,7 +581,10 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { · 580 unmodified lines | |||
| 581 | return vec; | 581 | return vec; |
| 582 | } else if (PyLong_AsLong(size) > 0) { | 582 | } else if (PyLong_AsLong(size) > 0) { |
| 583 | // short read, return a shorter array | 583 | // short read, return a shorter array |
| 584 | PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0); | 584 | PyObject *vec = PyTuple_GetItem(done, 0); |
| 585 | // take a copy to prevent resizing internal arrays | ||
| 586 | PyArrayObject *shortread = PyArray_FROM_OTF(vec, NPY_NOTYPE, | ||
| 587 | NPY_ARRAY_ENSURECOPY); | ||
| 585 | PyArray_Dims newdims; | 588 | PyArray_Dims newdims; |
| 586 | PyObject *reshaped; | 589 | PyObject *reshaped; |
| 587 | newdims.len = PyArray_NDIM(shortread); | 590 | newdims.len = PyArray_NDIM(shortread); |
| @@ -594,6 +597,7 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { · 6 unmodified lines | |||
| 594 | } | 597 | } |
| 595 | reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); | 598 | reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); |
| 596 | Py_DECREF(shortread); | 599 | Py_DECREF(shortread); |
| 600 | Py_DECREF(vec); | ||
| 597 | return reshaped; | 601 | return reshaped; |
| 598 | } else { | 602 | } else { |
| 599 | PyErr_SetNone(PyExc_StopIteration); | 603 | PyErr_SetNone(PyExc_StopIteration); |