Skip to content

Commit

Permalink
gh-126341: add release check to __iter__ method of memoryview (#1…
Browse files Browse the repository at this point in the history
…26759)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: sobolevn <[email protected]>
  • Loading branch information
5 people authored Nov 13, 2024
1 parent ba088c8 commit a12690e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/test/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3910,6 +3910,8 @@ def test_memoryview_check_released(self):
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Now :exc:`ValueError` is raised instead of :exc:`SystemError` when trying to iterate over a released :class:`memoryview` object.
1 change: 1 addition & 0 deletions Objects/memoryobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a12690e

Please sign in to comment.