Skip to content

Commit 2ad1427

Browse files
committed
Merge in the main branch
2 parents 865864a + 9731dd2 commit 2ad1427

104 files changed

Lines changed: 3667 additions & 1823 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Objects/type* @markshannon
3535
Objects/codeobject.c @markshannon
3636
Objects/frameobject.c @markshannon
3737
Objects/call.c @markshannon
38+
Objects/object.c @ZeroIntensity
3839
Python/ceval*.c @markshannon
3940
Python/ceval*.h @markshannon
4041
Python/codegen.c @markshannon @iritkatriel
@@ -66,8 +67,8 @@ Doc/_static/** @AA-Turner @hugovk
6667
Doc/tools/** @AA-Turner @hugovk
6768

6869
# runtime state/lifecycle
69-
**/*pylifecycle* @ericsnowcurrently
70-
**/*pystate* @ericsnowcurrently
70+
**/*pylifecycle* @ericsnowcurrently @ZeroIntensity
71+
**/*pystate* @ericsnowcurrently @ZeroIntensity
7172
**/*preconfig* @ericsnowcurrently
7273
**/*initconfig* @ericsnowcurrently
7374
**/*pathconfig* @ericsnowcurrently

.github/workflows/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,14 @@ jobs:
527527
config_hash: ${{ needs.build-context.outputs.config-hash }}
528528
free-threading: ${{ matrix.free-threading }}
529529

530+
build-ubsan:
531+
name: Undefined behavior sanitizer
532+
needs: build-context
533+
if: needs.build-context.outputs.run-tests == 'true'
534+
uses: ./.github/workflows/reusable-ubsan.yml
535+
with:
536+
config_hash: ${{ needs.build-context.outputs.config-hash }}
537+
530538
cross-build-linux:
531539
name: Cross build Linux
532540
runs-on: ubuntu-latest
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Reusable Undefined Behavior Sanitizer
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
config_hash:
7+
required: true
8+
type: string
9+
10+
env:
11+
FORCE_COLOR: 1
12+
13+
jobs:
14+
build-ubsan-reusable:
15+
name: 'Undefined behavior sanitizer'
16+
runs-on: ubuntu-24.04
17+
timeout-minutes: 60
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
- name: Runner image version
23+
run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
24+
- name: Restore config.cache
25+
uses: actions/cache@v4
26+
with:
27+
path: config.cache
28+
key: ${{ github.job }}-${{ env.IMAGE_OS_VERSION }}-${{ inputs.config_hash }}
29+
- name: Install dependencies
30+
run: |
31+
sudo ./.github/workflows/posix-deps-apt.sh
32+
# Install clang-20
33+
wget https://apt.llvm.org/llvm.sh
34+
chmod +x llvm.sh
35+
sudo ./llvm.sh 20
36+
- name: UBSAN option setup
37+
run: |
38+
echo "UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1" >> "$GITHUB_ENV"
39+
echo "CC=clang" >> "$GITHUB_ENV"
40+
echo "CXX=clang++" >> "$GITHUB_ENV"
41+
- name: Add ccache to PATH
42+
run: |
43+
echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV"
44+
- name: Configure ccache action
45+
uses: hendrikmuhs/ccache-action@v1.2
46+
with:
47+
save: ${{ github.event_name == 'push' }}
48+
max-size: "200M"
49+
- name: Configure CPython
50+
run: >-
51+
./configure
52+
--config-cache
53+
--with-undefined-behavior-sanitizer
54+
--with-pydebug
55+
- name: Set up UBSAN log after configuration
56+
run: |
57+
echo "UBSAN_OPTIONS=${UBSAN_OPTIONS}:log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV"
58+
- name: Build CPython
59+
run: make -j4
60+
- name: Display build info
61+
run: make pythoninfo
62+
- name: Tests
63+
run: ./python -m test -j4
64+
- name: Display UBSAN logs
65+
if: always()
66+
run: find "${GITHUB_WORKSPACE}" -name 'ubsan_log.*' | xargs head -n 1000
67+
- name: Archive UBSAN logs
68+
if: always()
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: >-
72+
ubsan-logs
73+
path: ubsan_log.*
74+
if-no-files-found: ignore

Doc/c-api/refcounting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ of Python objects.
210210
211211
Py_SETREF(dst, src);
212212
213-
That arranges to set *dst* to *src* _before_ releasing the reference
213+
That arranges to set *dst* to *src* *before* releasing the reference
214214
to the old value of *dst*, so that any code triggered as a side-effect
215215
of *dst* getting torn down no longer believes *dst* points
216216
to a valid object.

Doc/c-api/type.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ Type Objects
282282
and other places where a method's defining class cannot be passed using the
283283
:c:type:`PyCMethod` calling convention.
284284
285+
The returned reference is :term:`borrowed <borrowed reference>` from *type*,
286+
and will be valid as long as you hold a reference to *type*.
287+
Do not release it with :c:func:`Py_DECREF` or similar.
288+
285289
.. versionadded:: 3.11
286290
287291
.. c:function:: int PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result)

Doc/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
rst_epilog = f"""
8080
.. |python_version_literal| replace:: ``Python {version}``
8181
.. |python_x_dot_y_literal| replace:: ``python{version}``
82+
.. |python_x_dot_y_t_literal| replace:: ``python{version}t``
83+
.. |python_x_dot_y_t_literal_config| replace:: ``python{version}t-config``
84+
.. |x_dot_y_b2_literal| replace:: ``{version}.0b2``
85+
.. |applications_python_version_literal| replace:: ``/Applications/Python {version}/``
8286
.. |usr_local_bin_python_x_dot_y_literal| replace:: ``/usr/local/bin/python{version}``
8387
8488
.. Apparently this how you hack together a formatted link:

Doc/data/refcounts.dat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,10 @@ PyType_GetFlags:PyTypeObject*:type:0:
23852385
PyType_GetName:PyObject*::+1:
23862386
PyType_GetName:PyTypeObject*:type:0:
23872387

2388+
PyType_GetModuleByDef:PyObject*::0:
2389+
PyType_GetModuleByDef:PyTypeObject*:type:0:
2390+
PyType_GetModuleByDef:PyModuleDef*:def::
2391+
23882392
PyType_GetQualName:PyObject*::+1:
23892393
PyType_GetQualName:PyTypeObject*:type:0:
23902394

Doc/howto/free-threading-extensions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
C API Extension Support for Free Threading
77
******************************************
88

9-
Starting with the 3.13 release, CPython has experimental support for running
10-
with the :term:`global interpreter lock` (GIL) disabled in a configuration
9+
Starting with the 3.13 release, CPython has support for running with
10+
the :term:`global interpreter lock` (GIL) disabled in a configuration
1111
called :term:`free threading`. This document describes how to adapt C API
1212
extensions to support free threading.
1313

Doc/howto/free-threading-python.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
.. _freethreading-python-howto:
22

3-
**********************************************
4-
Python experimental support for free threading
5-
**********************************************
3+
*********************************
4+
Python support for free threading
5+
*********************************
66

7-
Starting with the 3.13 release, CPython has experimental support for a build of
7+
Starting with the 3.13 release, CPython has support for a build of
88
Python called :term:`free threading` where the :term:`global interpreter lock`
99
(GIL) is disabled. Free-threaded execution allows for full utilization of the
1010
available processing power by running threads in parallel on available CPU cores.
1111
While not all software will benefit from this automatically, programs
1212
designed with threading in mind will run faster on multi-core hardware.
1313

14-
**The free-threaded mode is experimental** and work is ongoing to improve it:
15-
expect some bugs and a substantial single-threaded performance hit.
14+
The free-threaded mode is working and continues to be improved, but
15+
there is some additional overhead in single-threaded workloads compared
16+
to the regular build. Additionally, third-party packages, in particular ones
17+
with an :term:`extension module`, may not be ready for use in a
18+
free-threaded build, and will re-enable the :term:`GIL`.
1619

1720
This document describes the implications of free threading
1821
for Python code. See :ref:`freethreading-extensions-howto` for information on
@@ -43,7 +46,7 @@ Identifying free-threaded Python
4346
================================
4447

4548
To check if the current interpreter supports free-threading, :option:`python -VV <-V>`
46-
and :data:`sys.version` contain "experimental free-threading build".
49+
and :data:`sys.version` contain "free-threading build".
4750
The new :func:`sys._is_gil_enabled` function can be used to check whether
4851
the GIL is actually disabled in the running process.
4952

Doc/library/concurrent.futures.rst

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Each worker's interpreter is isolated from all the other interpreters.
265265
"Isolated" means each interpreter has its own runtime state and
266266
operates completely independently. For example, if you redirect
267267
:data:`sys.stdout` in one interpreter, it will not be automatically
268-
redirected any other interpreter. If you import a module in one
268+
redirected to any other interpreter. If you import a module in one
269269
interpreter, it is not automatically imported in any other. You
270270
would need to import the module separately in interpreter where
271271
you need it. In fact, each module imported in an interpreter is
@@ -287,7 +287,7 @@ efficient alternative is to serialize with :mod:`pickle` and then send
287287
the bytes over a shared :mod:`socket <socket>` or
288288
:func:`pipe <os.pipe>`.
289289

290-
.. class:: InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=(), shared=None)
290+
.. class:: InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())
291291

292292
A :class:`ThreadPoolExecutor` subclass that executes calls asynchronously
293293
using a pool of at most *max_workers* threads. Each thread runs
@@ -304,32 +304,17 @@ the bytes over a shared :mod:`socket <socket>` or
304304
and *initargs* using :mod:`pickle` when sending them to the worker's
305305
interpreter.
306306

307-
.. note::
308-
Functions defined in the ``__main__`` module cannot be pickled
309-
and thus cannot be used.
310-
311307
.. note::
312308
The executor may replace uncaught exceptions from *initializer*
313309
with :class:`~concurrent.futures.interpreter.ExecutionFailed`.
314310

315-
The optional *shared* argument is a :class:`dict` of objects that all
316-
interpreters in the pool share. The *shared* items are added to each
317-
interpreter's ``__main__`` module. Not all objects are shareable.
318-
Shareable objects include the builtin singletons, :class:`str`
319-
and :class:`bytes`, and :class:`memoryview`. See :pep:`734`
320-
for more info.
321-
322311
Other caveats from parent :class:`ThreadPoolExecutor` apply here.
323312

324313
:meth:`~Executor.submit` and :meth:`~Executor.map` work like normal,
325314
except the worker serializes the callable and arguments using
326315
:mod:`pickle` when sending them to its interpreter. The worker
327316
likewise serializes the return value when sending it back.
328317

329-
.. note::
330-
Functions defined in the ``__main__`` module cannot be pickled
331-
and thus cannot be used.
332-
333318
When a worker's current task raises an uncaught exception, the worker
334319
always tries to preserve the exception as-is. If that is successful
335320
then it also sets the ``__cause__`` to a corresponding

0 commit comments

Comments
 (0)