mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
gh-142594: fix by property calls io.TextIOWrapper.detach (GH-142706)
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
14d3974db0
commit
1d3854a19a
3 changed files with 21 additions and 0 deletions
|
|
@ -1544,6 +1544,22 @@ def write(self, data):
|
|||
self.assertEqual([b"abcdef", b"middle", b"g"*chunk_size],
|
||||
buf._write_stack)
|
||||
|
||||
def test_issue142594(self):
|
||||
wrapper = None
|
||||
detached = False
|
||||
class ReentrantRawIO(self.RawIOBase):
|
||||
@property
|
||||
def closed(self):
|
||||
nonlocal detached
|
||||
if wrapper is not None and not detached:
|
||||
detached = True
|
||||
wrapper.detach()
|
||||
return False
|
||||
|
||||
raw = ReentrantRawIO()
|
||||
wrapper = self.TextIOWrapper(raw)
|
||||
wrapper.close() # should not crash
|
||||
|
||||
|
||||
class PyTextIOWrapperTest(TextIOWrapperTest, PyTestCase):
|
||||
shutdown_error = "LookupError: unknown encoding: ascii"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix crash in ``TextIOWrapper.close()`` when the underlying buffer's
|
||||
``closed`` property calls :meth:`~io.TextIOBase.detach`.
|
||||
|
|
@ -3150,6 +3150,9 @@ _io_TextIOWrapper_close_impl(textio *self)
|
|||
if (r > 0) {
|
||||
Py_RETURN_NONE; /* stream already closed */
|
||||
}
|
||||
if (self->detached) {
|
||||
Py_RETURN_NONE; /* gh-142594 null pointer issue */
|
||||
}
|
||||
else {
|
||||
PyObject *exc = NULL;
|
||||
if (self->finalizing) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue