Skip to content

Commit ea16a0f

Browse files
Merge branch '3.13' into backport-15a9762-3.13
2 parents 84d26e5 + c32a4c1 commit ea16a0f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Doc/library/ctypes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,9 @@ On Linux, :func:`~ctypes.util.find_library` tries to run external programs
13351335
(``/sbin/ldconfig``, ``gcc``, ``objdump`` and ``ld``) to find the library file.
13361336
It returns the filename of the library file.
13371337

1338+
Note that if the output of these programs does not correspond to the dynamic
1339+
linker used by Python, the result of this function may be misleading.
1340+
13381341
.. versionchanged:: 3.6
13391342
On Linux, the value of the environment variable ``LD_LIBRARY_PATH`` is used
13401343
when searching for libraries, if a library cannot be found by any other means.
@@ -2037,6 +2040,8 @@ Utility functions
20372040

20382041
The exact functionality is system dependent.
20392042

2043+
See :ref:`ctypes-finding-shared-libraries` for complete documentation.
2044+
20402045

20412046
.. function:: find_msvcrt()
20422047
:module: ctypes.util

Lib/test/test_io.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,6 +4160,22 @@ def write(self, data):
41604160
self.assertEqual([b"abcdef", b"middle", b"g"*chunk_size],
41614161
buf._write_stack)
41624162

4163+
def test_issue142594(self):
4164+
wrapper = None
4165+
detached = False
4166+
class ReentrantRawIO(self.RawIOBase):
4167+
@property
4168+
def closed(self):
4169+
nonlocal detached
4170+
if wrapper is not None and not detached:
4171+
detached = True
4172+
wrapper.detach()
4173+
return False
4174+
4175+
raw = ReentrantRawIO()
4176+
wrapper = self.TextIOWrapper(raw)
4177+
wrapper.close() # should not crash
4178+
41634179

41644180
class PyTextIOWrapperTest(TextIOWrapperTest):
41654181
io = pyio
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crash in ``TextIOWrapper.close()`` when the underlying buffer's
2+
``closed`` property calls :meth:`~io.TextIOBase.detach`.

Modules/_io/textio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,6 +3133,9 @@ _io_TextIOWrapper_close_impl(textio *self)
31333133
if (r > 0) {
31343134
Py_RETURN_NONE; /* stream already closed */
31353135
}
3136+
if (self->detached) {
3137+
Py_RETURN_NONE; /* gh-142594 null pointer issue */
3138+
}
31363139
else {
31373140
PyObject *exc = NULL;
31383141
if (self->finalizing) {

0 commit comments

Comments
 (0)