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 a12690e)

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 e8dbe7e commit a741431
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 @@ -3355,6 +3355,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 a741431

Please sign in to comment.