mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-111049: Fix crash during garbage collection of the BytesIO buffer object (GH-111221)
This commit is contained in:
parent
4d5d9acb22
commit
bb36f72efc
3 changed files with 27 additions and 10 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue