Skip to content

Commit c0034b7

Browse files
committed
Merge branch 'main' into gh-115103-qsbr
2 parents 35cbc0e + d9f4cbe commit c0034b7

File tree

175 files changed

+8611
-3273
lines changed

Some content is hidden

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

175 files changed

+8611
-3273
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root = true
22

3-
[*.{py,c,cpp,h,rst,md,yml}]
3+
[*.{py,c,cpp,h,js,rst,md,yml}]
44
trim_trailing_whitespace = true
55
insert_final_newline = true
66
indent_style = space
@@ -11,5 +11,5 @@ indent_size = 4
1111
[*.rst]
1212
indent_size = 3
1313

14-
[*.yml]
14+
[*.{js,yml}]
1515
indent_size = 2

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Programs/test_frozenmain.h generated
9494
Python/Python-ast.c generated
9595
Python/executor_cases.c.h generated
9696
Python/generated_cases.c.h generated
97+
Python/tier2_redundancy_eliminator_bytecodes.c.h generated
9798
Python/opcode_targets.h generated
9899
Python/stdlib_module_names.h generated
99100
Tools/peg_generator/pegen/grammar_parser.py generated

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Python/flowgraph.c @markshannon @iritkatriel
3737
Python/ast_opt.c @isidentical
3838
Python/bytecodes.c @markshannon @gvanrossum
3939
Python/optimizer*.c @markshannon @gvanrossum
40+
Python/optimizer_analysis.c @Fidget-Spinner
41+
Python/tier2_redundancy_eliminator_bytecodes.c @Fidget-Spinner
4042
Lib/test/test_patma.py @brandtbucher
4143
Lib/test/test_type_*.py @JelleZijlstra
4244
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum

.github/workflows/build.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ jobs:
131131
- uses: actions/setup-python@v5
132132
with:
133133
python-version: '3.x'
134+
- name: Runner image version
135+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
134136
- name: Restore config.cache
135137
uses: actions/cache@v4
136138
with:
137139
path: config.cache
138-
key: ${{ github.job }}-${{ runner.os }}-${{ needs.check_source.outputs.config_hash }}-${{ env.pythonLocation }}
140+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ needs.check_source.outputs.config_hash }}-${{ env.pythonLocation }}
139141
- name: Install Dependencies
140142
run: sudo ./.github/workflows/posix-deps-apt.sh
141143
- name: Add ccache to PATH
@@ -258,11 +260,13 @@ jobs:
258260
LD_LIBRARY_PATH: ${{ github.workspace }}/multissl/openssl/${{ matrix.openssl_ver }}/lib
259261
steps:
260262
- uses: actions/checkout@v4
263+
- name: Runner image version
264+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
261265
- name: Restore config.cache
262266
uses: actions/cache@v4
263267
with:
264268
path: config.cache
265-
key: ${{ github.job }}-${{ runner.os }}-${{ needs.check_source.outputs.config_hash }}
269+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ needs.check_source.outputs.config_hash }}
266270
- name: Register gcc problem matcher
267271
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
268272
- name: Install Dependencies
@@ -341,11 +345,13 @@ jobs:
341345
run: mkdir -p $CPYTHON_RO_SRCDIR $CPYTHON_BUILDDIR
342346
- name: Bind mount sources read-only
343347
run: sudo mount --bind -o ro $GITHUB_WORKSPACE $CPYTHON_RO_SRCDIR
348+
- name: Runner image version
349+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
344350
- name: Restore config.cache
345351
uses: actions/cache@v4
346352
with:
347353
path: ${{ env.CPYTHON_BUILDDIR }}/config.cache
348-
key: ${{ github.job }}-${{ runner.os }}-${{ needs.check_source.outputs.config_hash }}
354+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ needs.check_source.outputs.config_hash }}
349355
- name: Configure CPython out-of-tree
350356
working-directory: ${{ env.CPYTHON_BUILDDIR }}
351357
run: |
@@ -420,11 +426,13 @@ jobs:
420426
ASAN_OPTIONS: detect_leaks=0:allocator_may_return_null=1:handle_segv=0
421427
steps:
422428
- uses: actions/checkout@v4
429+
- name: Runner image version
430+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
423431
- name: Restore config.cache
424432
uses: actions/cache@v4
425433
with:
426434
path: config.cache
427-
key: ${{ github.job }}-${{ runner.os }}-${{ needs.check_source.outputs.config_hash }}
435+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ needs.check_source.outputs.config_hash }}
428436
- name: Register gcc problem matcher
429437
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
430438
- name: Install Dependencies

.github/workflows/reusable-macos.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ jobs:
2828
runs-on: ${{ matrix.os }}
2929
steps:
3030
- uses: actions/checkout@v4
31+
- name: Runner image version
32+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
3133
- name: Restore config.cache
3234
uses: actions/cache@v4
3335
with:
3436
path: config.cache
35-
key: ${{ github.job }}-${{ matrix.os }}-${{ inputs.config_hash }}
37+
key: ${{ github.job }}-${{ matrix.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}
3638
- name: Install Homebrew dependencies
3739
run: brew install pkg-config openssl@3.0 xz gdbm tcl-tk
3840
- name: Configure CPython

.github/workflows/reusable-ubuntu.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ jobs:
5252
run: mkdir -p $CPYTHON_RO_SRCDIR $CPYTHON_BUILDDIR
5353
- name: Bind mount sources read-only
5454
run: sudo mount --bind -o ro $GITHUB_WORKSPACE $CPYTHON_RO_SRCDIR
55+
- name: Runner image version
56+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
5557
- name: Restore config.cache
5658
uses: actions/cache@v4
5759
with:
5860
path: ${{ env.CPYTHON_BUILDDIR }}/config.cache
59-
key: ${{ github.job }}-${{ runner.os }}-${{ inputs.config_hash }}
61+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}
6062
- name: Configure CPython out-of-tree
6163
working-directory: ${{ env.CPYTHON_BUILDDIR }}
6264
run: ${{ inputs.options }}

Doc/c-api/long.rst

+70
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,28 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
113113
retrieved from the resulting value using :c:func:`PyLong_AsVoidPtr`.
114114
115115
116+
.. c:function:: PyObject* PyLong_FromNativeBytes(const void* buffer, size_t n_bytes, int endianness)
117+
118+
Create a Python integer from the value contained in the first *n_bytes* of
119+
*buffer*, interpreted as a two's-complement signed number.
120+
121+
*endianness* may be passed ``-1`` for the native endian that CPython was
122+
compiled with, or else ``0`` for big endian and ``1`` for little.
123+
124+
.. versionadded:: 3.13
125+
126+
127+
.. c:function:: PyObject* PyLong_FromUnsignedNativeBytes(const void* buffer, size_t n_bytes, int endianness)
128+
129+
Create a Python integer from the value contained in the first *n_bytes* of
130+
*buffer*, interpreted as an unsigned number.
131+
132+
*endianness* may be passed ``-1`` for the native endian that CPython was
133+
compiled with, or else ``0`` for big endian and ``1`` for little.
134+
135+
.. versionadded:: 3.13
136+
137+
116138
.. XXX alias PyLong_AS_LONG (for now)
117139
.. c:function:: long PyLong_AsLong(PyObject *obj)
118140
@@ -332,6 +354,54 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
332354
Returns ``NULL`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
333355
334356
357+
.. c:function:: Py_ssize_t PyLong_AsNativeBytes(PyObject *pylong, void* buffer, Py_ssize_t n_bytes, int endianness)
358+
359+
Copy the Python integer value to a native *buffer* of size *n_bytes*::
360+
361+
int value;
362+
Py_ssize_t bytes = PyLong_AsNativeBytes(v, &value, sizeof(value), -1);
363+
if (bytes < 0) {
364+
// Error occurred
365+
return NULL;
366+
}
367+
else if (bytes <= (Py_ssize_t)sizeof(value)) {
368+
// Success!
369+
}
370+
else {
371+
// Overflow occurred, but 'value' contains truncated value
372+
}
373+
374+
*endianness* may be passed ``-1`` for the native endian that CPython was
375+
compiled with, or ``0`` for big endian and ``1`` for little.
376+
377+
Return ``-1`` with an exception raised if *pylong* cannot be interpreted as
378+
an integer. Otherwise, return the size of the buffer required to store the
379+
value. If this is equal to or less than *n_bytes*, the entire value was
380+
copied.
381+
382+
Unless an exception is raised, all *n_bytes* of the buffer will be written
383+
with as much of the value as can fit. This allows the caller to ignore all
384+
non-negative results if the intent is to match the typical behavior of a
385+
C-style downcast. No exception is set for this case.
386+
387+
Values are always copied as two's-complement, and sufficient buffer will be
388+
requested to include a sign bit. For example, this may cause an value that
389+
fits into 8 bytes when treated as unsigned to request 9 bytes, even though
390+
all eight bytes were copied into the buffer. What has been omitted is the
391+
zero sign bit, which is redundant when the intention is to treat the value as
392+
unsigned.
393+
394+
Passing zero to *n_bytes* will return the requested buffer size.
395+
396+
.. note::
397+
398+
When the value does not fit in the provided buffer, the requested size
399+
returned from the function may be larger than necessary. Passing 0 to this
400+
function is not an accurate way to determine the bit length of a value.
401+
402+
.. versionadded:: 3.13
403+
404+
335405
.. c:function:: int PyUnstable_Long_IsCompact(const PyLongObject* op)
336406
337407
Return 1 if *op* is compact, 0 otherwise.

Doc/c-api/time.rst

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
.. highlight:: c
2+
3+
PyTime C API
4+
============
5+
6+
.. versionadded:: 3.13
7+
8+
The clock C API provides access to system clocks.
9+
It is similar to the Python :mod:`time` module.
10+
11+
For C API related to the :mod:`datetime` module, see :ref:`datetimeobjects`.
12+
13+
14+
Types
15+
-----
16+
17+
.. c:type:: PyTime_t
18+
19+
A timestamp or duration in nanoseconds, represented as a signed 64-bit
20+
integer.
21+
22+
The reference point for timestamps depends on the clock used. For example,
23+
:c:func:`PyTime_Time` returns timestamps relative to the UNIX epoch.
24+
25+
The supported range is around [-292.3 years; +292.3 years].
26+
Using the Unix epoch (January 1st, 1970) as reference, the supported date
27+
range is around [1677-09-21; 2262-04-11].
28+
The exact limits are exposed as constants:
29+
30+
.. c:var:: PyTime_t PyTime_MIN
31+
32+
Minimum value of :c:type:`PyTime_t`.
33+
34+
.. c:var:: PyTime_t PyTime_MAX
35+
36+
Maximum value of :c:type:`PyTime_t`.
37+
38+
39+
Clock Functions
40+
---------------
41+
42+
The following functions take a pointer to a :c:expr:`PyTime_t` that they
43+
set to the value of a particular clock.
44+
Details of each clock are given in the documentation of the corresponding
45+
Python function.
46+
47+
The functions return ``0`` on success, or ``-1`` (with an exception set)
48+
on failure.
49+
50+
On integer overflow, they set the :c:data:`PyExc_OverflowError` exception and
51+
set ``*result`` to the value clamped to the ``[PyTime_MIN; PyTime_MAX]``
52+
range.
53+
(On current systems, integer overflows are likely caused by misconfigured
54+
system time.)
55+
56+
As any other C API (unless otherwise specified), the functions must be called
57+
with the :term:`GIL` held.
58+
59+
.. c:function:: int PyTime_Monotonic(PyTime_t *result)
60+
61+
Read the monotonic clock.
62+
See :func:`time.monotonic` for important details on this clock.
63+
64+
.. c:function:: int PyTime_PerfCounter(PyTime_t *result)
65+
66+
Read the performance counter.
67+
See :func:`time.perf_counter` for important details on this clock.
68+
69+
.. c:function:: int PyTime_Time(PyTime_t *result)
70+
71+
Read the “wall clock” time.
72+
See :func:`time.time` for details important on this clock.
73+
74+
75+
Conversion functions
76+
--------------------
77+
78+
.. c:function:: double PyTime_AsSecondsDouble(PyTime_t t)
79+
80+
Convert a timestamp to a number of seconds as a C :c:expr:`double`.
81+
82+
The function cannot fail, but note that :c:expr:`double` has limited
83+
accuracy for large values.

Doc/c-api/unicode.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,12 @@ wchar_t Support
854854
Copy the Unicode object contents into the :c:type:`wchar_t` buffer *wstr*. At most
855855
*size* :c:type:`wchar_t` characters are copied (excluding a possibly trailing
856856
null termination character). Return the number of :c:type:`wchar_t` characters
857-
copied or ``-1`` in case of an error. Note that the resulting :c:expr:`wchar_t*`
857+
copied or ``-1`` in case of an error.
858+
859+
When *wstr* is ``NULL``, instead return the *size* that would be required
860+
to store all of *unicode* including a terminating null.
861+
862+
Note that the resulting :c:expr:`wchar_t*`
858863
string may or may not be null-terminated. It is the responsibility of the caller
859864
to make sure that the :c:expr:`wchar_t*` string is null-terminated in case this is
860865
required by the application. Also, note that the :c:expr:`wchar_t*` string

Doc/c-api/utilities.rst

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ and parsing function arguments and constructing Python values from C values.
2020
hash.rst
2121
reflection.rst
2222
codec.rst
23+
time.rst
2324
perfmaps.rst

Doc/conf.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
import patchlevel
6565
version, release = patchlevel.get_version_info()
6666

67+
rst_epilog = f"""
68+
.. |python_version_literal| replace:: ``Python {version}``
69+
.. |python_x_dot_y_literal| replace:: ``python{version}``
70+
.. |usr_local_bin_python_x_dot_y_literal| replace:: ``/usr/local/bin/python{version}``
71+
"""
72+
6773
# There are two options for replacing |today|: either, you set today to some
6874
# non-false value, then it is used:
6975
today = ''
@@ -135,11 +141,14 @@
135141
('c:type', 'wchar_t'),
136142
('c:type', '__int64'),
137143
('c:type', 'unsigned __int64'),
144+
('c:type', 'double'),
138145
# Standard C structures
139146
('c:struct', 'in6_addr'),
140147
('c:struct', 'in_addr'),
141148
('c:struct', 'stat'),
142149
('c:struct', 'statvfs'),
150+
('c:struct', 'timeval'),
151+
('c:struct', 'timespec'),
143152
# Standard C macros
144153
('c:macro', 'LLONG_MAX'),
145154
('c:macro', 'LLONG_MIN'),
@@ -269,12 +278,12 @@
269278
('py:meth', 'index'), # list.index, tuple.index, etc.
270279
]
271280

272-
# gh-106948: Copy standard C types declared in the "c:type" domain to the
273-
# "c:identifier" domain, since "c:function" markup looks for types in the
274-
# "c:identifier" domain. Use list() to not iterate on items which are being
275-
# added
281+
# gh-106948: Copy standard C types declared in the "c:type" domain and C
282+
# structures declared in the "c:struct" domain to the "c:identifier" domain,
283+
# since "c:function" markup looks for types in the "c:identifier" domain. Use
284+
# list() to not iterate on items which are being added
276285
for role, name in list(nitpick_ignore):
277-
if role == 'c:type':
286+
if role in ('c:type', 'c:struct'):
278287
nitpick_ignore.append(('c:identifier', name))
279288
del role, name
280289

Doc/howto/logging-cookbook.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -1744,13 +1744,11 @@ to the above, as in the following example::
17441744
return self.fmt.format(*self.args)
17451745

17461746
class StyleAdapter(logging.LoggerAdapter):
1747-
def __init__(self, logger, extra=None):
1748-
super().__init__(logger, extra or {})
1749-
1750-
def log(self, level, msg, /, *args, **kwargs):
1747+
def log(self, level, msg, /, *args, stacklevel=1, **kwargs):
17511748
if self.isEnabledFor(level):
17521749
msg, kwargs = self.process(msg, kwargs)
1753-
self.logger._log(level, Message(msg, args), (), **kwargs)
1750+
self.logger.log(level, Message(msg, args), **kwargs,
1751+
stacklevel=stacklevel+1)
17541752

17551753
logger = StyleAdapter(logging.getLogger(__name__))
17561754

@@ -1762,7 +1760,7 @@ to the above, as in the following example::
17621760
main()
17631761

17641762
The above script should log the message ``Hello, world!`` when run with
1765-
Python 3.2 or later.
1763+
Python 3.8 or later.
17661764

17671765

17681766
.. currentmodule:: logging

Doc/library/datetime.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ Other constructor:
18111811
be truncated).
18121812
4. Fractional hours and minutes are not supported.
18131813

1814-
Examples::
1814+
Examples:
18151815

18161816
.. doctest::
18171817

0 commit comments

Comments
 (0)