History

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

Paul Brossier committed 7 years ago

Commit 966c6501 parent 79dc9ad1 file · +5 −1Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/ext/py-source.c+5−1
@@ -581,7 +581,10 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { · 580 unmodified lines
581581 return vec;
582582 } else if (PyLong_AsLong(size) > 0) {
583583 // 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);
585588 PyArray_Dims newdims;
586589 PyObject *reshaped;
587590 newdims.len = PyArray_NDIM(shortread);
@@ -594,6 +597,7 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { · 6 unmodified lines
594597 }
595598 reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER);
596599 Py_DECREF(shortread);
600+ Py_DECREF(vec);
597601 return reshaped;
598602 } else {
599603 PyErr_SetNone(PyExc_StopIteration);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t