Skip to content

Commit

Permalink
[3.12] gh-126341: add release check to __iter__ method of `memoryvi…
Browse files Browse the repository at this point in the history
…ew` (GH-126759) (#126779)

gh-126341: add release check to `__iter__` method of `memoryview` (GH-126759)
(cherry picked from commit a12690e)

Co-authored-by: Ritvik Pasham <ritvikpasham@gmail.com>
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>
  • Loading branch information
6 people authored Nov 13, 2024
1 parent dd21259 commit 0bdcc84
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 0bdcc84

Please sign in to comment.