Skip to content

Commit 4536222

Browse files
committed
Merge branch 'main' of github.com:python/cpython into defaultdict
2 parents 78d0180 + 8bb5b6e commit 4536222

File tree

14 files changed

+287
-0
lines changed

14 files changed

+287
-0
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/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

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: 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) {

Tools/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ patchcheck Tools for checking and applying patches to the Python source cod
4343

4444
peg_generator PEG-based parser generator (pegen) used for new parser.
4545

46+
pixi-packages Pixi package definitions for downstream from-source builds.
47+
4648
scripts A number of useful single-file programs, e.g. run_tests.py
4749
which runs the Python test suite.
4850

Tools/pixi-packages/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# CPython Pixi packages
2+
3+
This directory contains definitions for [Pixi packages](https://pixi.sh/latest/reference/pixi_manifest/#the-package-section)
4+
which can be built from the CPython source code.
5+
6+
Downstream developers can make use of these packages by adding them as Git dependencies in a
7+
[Pixi workspace](https://pixi.sh/latest/first_workspace/), like:
8+
9+
```toml
10+
[dependencies]
11+
python = { git = "https://github.com/python/cpython", subdirectory = "Tools/pixi-packages/asan" }
12+
```
13+
14+
This is particularly useful when developers need to build CPython from source
15+
(for example, for an ASan-instrumented build), as it does not require any manual
16+
clone or build steps. Instead, Pixi will automatically handle both the build
17+
and installation of the package.
18+
19+
Each package definition is contained in a subdirectory, but they share the build script
20+
`build.sh` in this directory. Currently defined package variants:
21+
22+
- `default`
23+
- `asan`: ASan-instrumented build with `PYTHON_ASAN=1`
24+
25+
## Maintenance
26+
27+
- Keep the `version` fields in each `recipe.yaml` up to date with the Python version
28+
- Keep the dependency requirements up to date in each `recipe.yaml`
29+
- Update `build.sh` for any breaking changes in the `configure` and `make` workflow
30+
31+
## Opportunities for future improvement
32+
33+
- More package variants (such as TSan, UBSan)
34+
- Support for Windows
35+
- Using a single `pixi.toml` and `recipe.yaml` for all package variants is blocked on https://github.com/prefix-dev/pixi/issues/4599
36+
- A workaround can be removed from the build script once https://github.com/prefix-dev/rattler-build/issues/2012 is resolved

Tools/pixi-packages/asan/pixi.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[workspace]
2+
channels = ["https://prefix.dev/conda-forge"]
3+
platforms = ["osx-arm64", "linux-64"]
4+
preview = ["pixi-build"]
5+
6+
[package.build.backend]
7+
name = "pixi-build-rattler-build"
8+
version = "*"

0 commit comments

Comments
 (0)