Skip to content

Commit 0a1f140

Browse files
committed
Merge branch 'main' into gh-142654
2 parents a1c66e5 + 8bb5b6e commit 0a1f140

File tree

17 files changed

+290
-3
lines changed

17 files changed

+290
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gmon.out
4545
.pytest_cache/
4646
.ruff_cache/
4747
.DS_Store
48+
.pixi/
4849

4950
*.exe
5051

Doc/deprecations/c-api-pending-removal-in-3.20.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Pending removal in Python 3.20
33

44
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
55
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
6-
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
6+
3.20. Instead, use :c:func:`PyUnicode_InternFromString()` and cache the result in
77
the module state, then call :c:func:`PyObject_CallMethod` or
88
:c:func:`PyObject_GetAttr`.
99
(Contributed by Victor Stinner in :gh:`141049`.)

Doc/library/ctypes.rst

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

1391+
Note that if the output of these programs does not correspond to the dynamic
1392+
linker used by Python, the result of this function may be misleading.
1393+
13911394
.. versionchanged:: 3.6
13921395
On Linux, the value of the environment variable ``LD_LIBRARY_PATH`` is used
13931396
when searching for libraries, if a library cannot be found by any other means.
@@ -2132,6 +2135,8 @@ Utility functions
21322135

21332136
The exact functionality is system dependent.
21342137

2138+
See :ref:`ctypes-finding-shared-libraries` for complete documentation.
2139+
21352140

21362141
.. function:: find_msvcrt()
21372142
:module: ctypes.util

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ Deprecated C APIs
12261226

12271227
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
12281228
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
1229-
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
1229+
3.20. Instead, use :c:func:`PyUnicode_InternFromString()` and cache the result in
12301230
the module state, then call :c:func:`PyObject_CallMethod` or
12311231
:c:func:`PyObject_GetAttr`.
12321232
(Contributed by Victor Stinner in :gh:`141049`.)

InternalDocs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ it is not, please report that through the
1111
[issue tracker](https://github.com/python/cpython/issues).
1212

1313

14+
General Resources
15+
---
16+
17+
- [Source Code Structure](structure.md)
18+
1419
Compiling Python Source Code
1520
---
1621

InternalDocs/structure.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# CPython source code
2+
3+
This section gives an overview of CPython's code structure and provides
4+
a summary of file locations for modules and built-ins.
5+
6+
7+
## Source code layout
8+
9+
For a Python module, the typical layout is:
10+
11+
* `Lib/<module>.py`
12+
* `Modules/_<module>.c` (if there's also a C accelerator module)
13+
* `Lib/test/test_<module>.py`
14+
* `Doc/library/<module>.rst`
15+
16+
For an extension module, the typical layout is:
17+
18+
* `Modules/<module>module.c`
19+
* `Lib/test/test_<module>.py`
20+
* `Doc/library/<module>.rst`
21+
22+
For builtin types, the typical layout is:
23+
24+
* `Objects/<builtin>object.c`
25+
* `Lib/test/test_<builtin>.py`
26+
* [`Doc/library/stdtypes.rst`](../Doc/library/stdtypes.rst)
27+
28+
For builtin functions, the typical layout is:
29+
30+
* [`Python/bltinmodule.c`](../Python/bltinmodule.c)
31+
* [`Lib/test/test_builtin.py`](../Lib/test/test_builtin.py)
32+
* [`Doc/library/functions.rst`](../Doc/library/functions.rst)
33+
34+
Some exceptions to these layouts are:
35+
36+
* built-in type `int` is at [`Objects/longobject.c`](../Objects/longobject.c)
37+
* built-in type `str` is at [`Objects/unicodeobject.c`](../Objects/unicodeobject.c)
38+
* built-in module `sys` is at [`Python/sysmodule.c`](../Python/sysmodule.c)
39+
* built-in module `marshal` is at [`Python/marshal.c`](../Python/marshal.c)
40+
* Windows-only module `winreg` is at [`PC/winreg.c`](../PC/winreg.c)

Lib/test/test_io/test_textio.py

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

1547+
def test_issue142594(self):
1548+
wrapper = None
1549+
detached = False
1550+
class ReentrantRawIO(self.RawIOBase):
1551+
@property
1552+
def closed(self):
1553+
nonlocal detached
1554+
if wrapper is not None and not detached:
1555+
detached = True
1556+
wrapper.detach()
1557+
return False
1558+
1559+
raw = ReentrantRawIO()
1560+
wrapper = self.TextIOWrapper(raw)
1561+
wrapper.close() # should not crash
1562+
15471563

15481564
class PyTextIOWrapperTest(TextIOWrapperTest, PyTestCase):
15491565
shutdown_error = "LookupError: unknown encoding: ascii"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
22
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
3-
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
3+
3.20. Instead, use :c:func:`PyUnicode_InternFromString()` and cache the result in
44
the module state, then call :c:func:`PyObject_CallMethod` or
55
:c:func:`PyObject_GetAttr`. Patch by Victor Stinner.
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
@@ -3150,6 +3150,9 @@ _io_TextIOWrapper_close_impl(textio *self)
31503150
if (r > 0) {
31513151
Py_RETURN_NONE; /* stream already closed */
31523152
}
3153+
if (self->detached) {
3154+
Py_RETURN_NONE; /* gh-142594 null pointer issue */
3155+
}
31533156
else {
31543157
PyObject *exc = NULL;
31553158
if (self->finalizing) {

0 commit comments

Comments
 (0)