[3.12] gh-77894: Fix a crash when the GC breaks a loop containing a memoryview (GH-123898) (GH-123937)

Now a memoryview object can only be cleared if there are no buffers
that refer it.
(cherry picked from commit a1dbf2ea69)
This commit is contained in:
Serhiy Storchaka 2024-09-11 12:32:39 +03:00 committed by GitHub
parent c6ae90a63c
commit 90e5bd7ed2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 57 additions and 33 deletions

View file

@ -2019,12 +2019,10 @@ class AbstractPicklingErrorTests:
'PickleBuffer can only be pickled with protocol >= 5')
def test_non_continuous_buffer(self):
if self.pickler is pickle._Pickler:
self.skipTest('CRASHES (see gh-122306)')
for proto in protocols[5:]:
with self.subTest(proto=proto):
pb = pickle.PickleBuffer(memoryview(b"foobar")[::2])
with self.assertRaises(pickle.PicklingError):
with self.assertRaises((pickle.PicklingError, BufferError)):
self.dumps(pb, proto)
def test_buffer_callback_error(self):