https://github.com/python/cpython/commit/0bdcc84ae99ff695b10b2f13c5a00497ce0840e5 commit: 0bdcc84ae99ff695b10b2f13c5a00497ce0840e5 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: Eclips4 <[email protected]> date: 2024-11-13T20:44:01+02:00 summary:
[3.12] gh-126341: add release check to `__iter__` method of `memoryview` (GH-126759) (#126779) gh-126341: add release check to `__iter__` method of `memoryview` (GH-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]> files: A Misc/NEWS.d/next/Core_and_Builtins/2024-11-12-19-24-00.gh-issue-126341.5SdAe1.rst M Lib/test/test_buffer.py M Objects/memoryobject.c diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index aafbb8a993def5..84a34bccbc9af1 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -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() diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-12-19-24-00.gh-issue-126341.5SdAe1.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-12-19-24-00.gh-issue-126341.5SdAe1.rst new file mode 100644 index 00000000000000..c2436d2ebf4d09 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-12-19-24-00.gh-issue-126341.5SdAe1.rst @@ -0,0 +1 @@ +Now :exc:`ValueError` is raised instead of :exc:`SystemError` when trying to iterate over a released :class:`memoryview` object. diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 26871612ea794d..9a5f9c665b2a9f 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -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) { _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
