Skip to content

Commit c032cf8

Browse files
authored
Merge branch 'main' into patch-1
2 parents 0240959 + 3cc5ae5 commit c032cf8

104 files changed

Lines changed: 922 additions & 660 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/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ jobs:
301301
- name: SSL tests
302302
run: ./python Lib/test/ssltests.py
303303

304+
build_wasi:
305+
name: 'WASI'
306+
needs: check_source
307+
if: needs.check_source.outputs.run_tests == 'true'
308+
uses: ./.github/workflows/reusable-wasi.yml
309+
with:
310+
config_hash: ${{ needs.check_source.outputs.config_hash }}
311+
304312
test_hypothesis:
305313
name: "Hypothesis tests on Ubuntu"
306314
runs-on: ubuntu-20.04
@@ -525,6 +533,7 @@ jobs:
525533
- build_ubuntu
526534
- build_ubuntu_free_threading
527535
- build_ubuntu_ssltests
536+
- build_wasi
528537
- build_windows
529538
- build_windows_free_threading
530539
- test_hypothesis
@@ -558,6 +567,7 @@ jobs:
558567
build_ubuntu,
559568
build_ubuntu_free_threading,
560569
build_ubuntu_ssltests,
570+
build_wasi,
561571
build_windows,
562572
build_windows_free_threading,
563573
build_asan,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
config_hash:
5+
required: true
6+
type: string
7+
8+
jobs:
9+
build_wasi_reusable:
10+
name: 'build and test'
11+
timeout-minutes: 60
12+
runs-on: ubuntu-20.04
13+
env:
14+
WASMTIME_VERSION: 18.0.2
15+
WASI_SDK_VERSION: 20
16+
WASI_SDK_PATH: /opt/wasi-sdk
17+
CROSS_BUILD_PYTHON: cross-build/build
18+
CROSS_BUILD_WASI: cross-build/wasm32-wasi
19+
steps:
20+
- uses: actions/checkout@v4
21+
# No problem resolver registered as one doesn't currently exist for Clang.
22+
- name: "Install wasmtime"
23+
uses: jcbhmr/setup-wasmtime@v2
24+
with:
25+
wasmtime-version: ${{ env.WASMTIME_VERSION }}
26+
- name: "Restore WASI SDK"
27+
id: cache-wasi-sdk
28+
uses: actions/cache@v4
29+
with:
30+
path: ${{ env.WASI_SDK_PATH }}
31+
key: ${{ runner.os }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}
32+
- name: "Install WASI SDK"
33+
if: steps.cache-wasi-sdk.outputs.cache-hit != 'true'
34+
run: |
35+
mkdir ${{ env.WASI_SDK_PATH }} && \
36+
curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ env.WASI_SDK_VERSION }}/wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-linux.tar.gz | \
37+
tar --strip-components 1 --directory ${{ env.WASI_SDK_PATH }} --extract --gunzip
38+
- name: "Configure ccache action"
39+
uses: hendrikmuhs/ccache-action@v1.2
40+
with:
41+
save: ${{ github.event_name == 'push' }}
42+
max-size: "200M"
43+
- name: "Add ccache to PATH"
44+
run: echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
45+
- name: "Install Python"
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: '3.x'
49+
- name: "Restore Python build config.cache"
50+
uses: actions/cache@v4
51+
with:
52+
path: ${{ env.CROSS_BUILD_PYTHON }}/config.cache
53+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}
54+
- name: "Configure build Python"
55+
run: python3 Tools/wasm/wasi.py configure-build-python -- --config-cache --with-pydebug
56+
- name: "Make build Python"
57+
run: python3 Tools/wasm/wasi.py make-build-python
58+
- name: "Restore host config.cache"
59+
uses: actions/cache@v4
60+
with:
61+
path: ${{ env.CROSS_BUILD_WASI }}/config.cache
62+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}-${{ inputs.config_hash }}
63+
- name: "Configure host"
64+
# `--with-pydebug` inferred from configure-build-python
65+
run: python3 Tools/wasm/wasi.py configure-host -- --config-cache
66+
- name: "Make host"
67+
run: python3 Tools/wasm/wasi.py make-host
68+
- name: "Display build info"
69+
run: make --directory ${{ env.CROSS_BUILD_WASI }} pythoninfo
70+
- name: "Test"
71+
run: make --directory ${{ env.CROSS_BUILD_WASI }} test

Doc/library/sys.rst

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,47 +1367,42 @@ always available.
13671367

13681368
.. data:: platform
13691369

1370-
This string contains a platform identifier that can be used to append
1371-
platform-specific components to :data:`sys.path`, for instance.
1372-
1373-
For Unix systems, except on Linux and AIX, this is the lowercased OS name as
1374-
returned by ``uname -s`` with the first part of the version as returned by
1375-
``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
1376-
when Python was built*. Unless you want to test for a specific system
1377-
version, it is therefore recommended to use the following idiom::
1378-
1379-
if sys.platform.startswith('freebsd'):
1380-
# FreeBSD-specific code here...
1381-
elif sys.platform.startswith('linux'):
1382-
# Linux-specific code here...
1383-
elif sys.platform.startswith('aix'):
1384-
# AIX-specific code here...
1385-
1386-
For other systems, the values are:
1370+
A string containing a platform identifier. Known values are:
13871371

13881372
================ ===========================
13891373
System ``platform`` value
13901374
================ ===========================
13911375
AIX ``'aix'``
1376+
Android ``'android'``
13921377
Emscripten ``'emscripten'``
1378+
iOS ``'ios'``
13931379
Linux ``'linux'``
1394-
WASI ``'wasi'``
1380+
macOS ``'darwin'``
13951381
Windows ``'win32'``
13961382
Windows/Cygwin ``'cygwin'``
1397-
macOS ``'darwin'``
1383+
WASI ``'wasi'``
13981384
================ ===========================
13991385

1386+
On Unix systems not listed in the table, the value is the lowercased OS name
1387+
as returned by ``uname -s``, with the first part of the version as returned by
1388+
``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
1389+
when Python was built*. Unless you want to test for a specific system
1390+
version, it is therefore recommended to use the following idiom::
1391+
1392+
if sys.platform.startswith('freebsd'):
1393+
# FreeBSD-specific code here...
1394+
14001395
.. versionchanged:: 3.3
14011396
On Linux, :data:`sys.platform` doesn't contain the major version anymore.
1402-
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``. Since
1403-
older Python versions include the version number, it is recommended to
1404-
always use the ``startswith`` idiom presented above.
1397+
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``.
14051398

14061399
.. versionchanged:: 3.8
14071400
On AIX, :data:`sys.platform` doesn't contain the major version anymore.
1408-
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``. Since
1409-
older Python versions include the version number, it is recommended to
1410-
always use the ``startswith`` idiom presented above.
1401+
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``.
1402+
1403+
.. versionchanged:: 3.13
1404+
On Android, :data:`sys.platform` now returns ``'android'`` rather than
1405+
``'linux'``.
14111406

14121407
.. seealso::
14131408

Doc/tutorial/errors.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ complaint you get while you are still learning Python::
2020
>>> while True print('Hello world')
2121
File "<stdin>", line 1
2222
while True print('Hello world')
23-
^
23+
^^^^^
2424
SyntaxError: invalid syntax
2525

26-
The parser repeats the offending line and displays a little 'arrow' pointing at
27-
the earliest point in the line where the error was detected. The error is
28-
caused by (or at least detected at) the token *preceding* the arrow: in the
26+
The parser repeats the offending line and displays little 'arrow's pointing
27+
at the token in the line where the error was detected. The error may be
28+
caused by the absence of a token *before* the indicated token. In the
2929
example, the error is detected at the function :func:`print`, since a colon
3030
(``':'``) is missing before it. File name and line number are printed so you
3131
know where to look in case the input came from a script.

Doc/using/cmdline.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ Miscellaneous options
559559
:mod:`__main__`. This can be used to execute code early during Python
560560
initialization. Python needs to be :ref:`built in debug mode <debug-build>`
561561
for this option to exist. See also :envvar:`PYTHON_PRESITE`.
562+
* :samp:`-X gil={0,1}` forces the GIL to be disabled or enabled,
563+
respectively. Only available in builds configured with
564+
:option:`--disable-gil`. See also :envvar:`PYTHON_GIL`.
562565

563566
It also allows passing arbitrary values and retrieving them through the
564567
:data:`sys._xoptions` dictionary.
@@ -601,6 +604,9 @@ Miscellaneous options
601604
.. versionchanged:: 3.13
602605
Added the ``-X cpu_count`` and ``-X presite`` options.
603606

607+
.. versionchanged:: 3.13
608+
Added the ``-X gil`` option.
609+
604610
.. _using-on-controlling-color:
605611

606612
Controlling color
@@ -1138,6 +1144,18 @@ conflict.
11381144

11391145
.. versionadded:: 3.13
11401146

1147+
.. envvar:: PYTHON_GIL
1148+
1149+
If this variable is set to ``1``, the global interpreter lock (GIL) will be
1150+
forced on. Setting it to ``0`` forces the GIL off.
1151+
1152+
See also the :option:`-X gil <-X>` command-line option, which takes
1153+
precedence over this variable.
1154+
1155+
Needs Python configured with the :option:`--disable-gil` build option.
1156+
1157+
.. versionadded:: 3.13
1158+
11411159
Debug-mode variables
11421160
~~~~~~~~~~~~~~~~~~~~
11431161

Include/cpython/initconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ typedef struct PyConfig {
181181
int int_max_str_digits;
182182

183183
int cpu_count;
184+
#ifdef Py_GIL_DISABLED
185+
int enable_gil;
186+
#endif
184187

185188
/* --- Path configuration inputs ------------ */
186189
int pathconfig_warnings;

Include/internal/pycore_gil.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ extern "C" {
2020
#define FORCE_SWITCHING
2121

2222
struct _gil_runtime_state {
23+
#ifdef Py_GIL_DISABLED
24+
/* Whether or not this GIL is being used. Can change from 0 to 1 at runtime
25+
if, for example, a module that requires the GIL is loaded. */
26+
int enabled;
27+
#endif
2328
/* microseconds (the Python API uses seconds, though) */
2429
unsigned long interval;
2530
/* Last PyThreadState holding / having held the GIL. This helps us

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ struct _Py_global_strings {
472472
STRUCT_FOR_ID(hi)
473473
STRUCT_FOR_ID(hook)
474474
STRUCT_FOR_ID(hour)
475-
STRUCT_FOR_ID(id)
476475
STRUCT_FOR_ID(ident)
477476
STRUCT_FOR_ID(identity_hint)
478477
STRUCT_FOR_ID(ignore)

Include/internal/pycore_initconfig.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ typedef enum {
153153
_PyConfig_INIT_ISOLATED = 3
154154
} _PyConfigInitEnum;
155155

156+
typedef enum {
157+
/* For now, this means the GIL is enabled.
158+
159+
gh-116329: This will eventually change to "the GIL is disabled but can
160+
be reenabled by loading an incompatible extension module." */
161+
_PyConfig_GIL_DEFAULT = -1,
162+
163+
/* The GIL has been forced off or on, and will not be affected by module loading. */
164+
_PyConfig_GIL_DISABLE = 0,
165+
_PyConfig_GIL_ENABLE = 1,
166+
} _PyConfigGILEnum;
167+
156168
// Export for '_testembed' program
157169
PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
158170

0 commit comments

Comments
 (0)