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:
Ritvik Pasham 2024-11-13 06:51:01 -05:00 committed by GitHub
parent ba088c8f9c
commit a12690ef49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 0 deletions

View File

@ -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()

View File

@ -0,0 +1 @@
Now :exc:`ValueError` is raised instead of :exc:`SystemError` when trying to iterate over a released :class:`memoryview` object.

View File

@ -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) {