mirror of https://github.com/python/cpython
gh-126341: add release check to `__iter__` method of `memoryview` (#126759)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
ba088c8f9c
commit
a12690ef49
|
@ -3910,6 +3910,8 @@ class TestBufferProtocol(unittest.TestCase):
|
|||
self.assertRaises(ValueError, memoryview, m)
|
||||
# memoryview.cast()
|
||||
self.assertRaises(ValueError, m.cast, 'c')
|
||||
# memoryview.__iter__()
|
||||
self.assertRaises(ValueError, m.__iter__)
|
||||
# getbuffer()
|
||||
self.assertRaises(ValueError, ndarray, m)
|
||||
# memoryview.tolist()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Now :exc:`ValueError` is raised instead of :exc:`SystemError` when trying to iterate over a released :class:`memoryview` object.
|
|
@ -3356,6 +3356,7 @@ memory_iter(PyObject *seq)
|
|||
PyErr_BadInternalCall();
|
||||
return NULL;
|
||||
}
|
||||
CHECK_RELEASED(seq);
|
||||
PyMemoryViewObject *obj = (PyMemoryViewObject *)seq;
|
||||
int ndims = obj->view.ndim;
|
||||
if (ndims == 0) {
|
||||
|
|
Loading…
Reference in New Issue