Skip to content

Commit

Permalink
pythongh-126341: add release check to __iter__ method of `memoryvie…
Browse files Browse the repository at this point in the history
…w` (pythonGH-126759)

(cherry picked from commit a12690ef49e8fc8a3af4c5f1757eb3caffb35e03)

Co-authored-by: Ritvik Pasham <[email protected]>
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 and miss-islington committed Nov 13, 2024
1 parent dd21259 commit 1af10de
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 @@ -3906,6 +3906,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 @@ -3322,6 +3322,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 1af10de

Please sign in to comment.