summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_memoryio.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-12-14 10:04:23 (GMT)
committerGitHub <noreply@github.com>2023-12-14 10:04:23 (GMT)
commitbb36f72efcc6a656e0907ffa83620a1e44044895 (patch)
treef23bc442613ac1f8c869fdeecc4bb62843805fc1 /Lib/test/test_memoryio.py
parent4d5d9acb22ee8c6908ebd4fdc3d17472f8b286e3 (diff)
downloadcpython-bb36f72efcc6a656e0907ffa83620a1e44044895.zip
cpython-bb36f72efcc6a656e0907ffa83620a1e44044895.tar.gz
cpython-bb36f72efcc6a656e0907ffa83620a1e44044895.tar.bz2
gh-111049: Fix crash during garbage collection of the BytesIO buffer object (GH-111221)
Diffstat (limited to 'Lib/test/test_memoryio.py')
-rw-r--r--Lib/test/test_memoryio.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index 7312992..8192502 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -6,10 +6,12 @@ BytesIO -- for bytes
import unittest
from test import support
+import gc
import io
import _pyio as pyio
import pickle
import sys
+import weakref
class IntLike:
def __init__(self, num):
@@ -477,6 +479,25 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
buf2.release()
memio.write(b'x')
+ def test_getbuffer_gc_collect(self):
+ memio = self.ioclass(b"1234567890")
+ buf = memio.getbuffer()
+ memiowr = weakref.ref(memio)
+ bufwr = weakref.ref(buf)
+ # Create a reference loop.
+ a = [buf]
+ a.append(a)
+ # The Python implementation emits an unraisable exception.
+ with support.catch_unraisable_exception():
+ del memio
+ del buf
+ del a
+ # The C implementation emits an unraisable exception.
+ with support.catch_unraisable_exception():
+ gc.collect()
+ self.assertIsNone(memiowr())
+ self.assertIsNone(bufwr())
+
def test_read1(self):
buf = self.buftype("1234567890")
self.assertEqual(self.ioclass(buf).read1(), buf)