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
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 array583 // 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);

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