Skip to content

Commit 0702cb3

Browse files
authored
Merge branch 'main' into support-halffloat-arrays/146238
2 parents b98ebb0 + a933e9c commit 0702cb3

File tree

111 files changed

+1807
-1435
lines changed

Some content is hidden

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

111 files changed

+1807
-1435
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ jobs:
369369
sudo xcode-select --switch /Applications/Xcode_15.4.app
370370
371371
- name: Build and test
372-
run: python3 Apple ci iOS --fast-ci --simulator 'iPhone SE (3rd generation),OS=17.5'
372+
run: python3 Platforms/Apple ci iOS --fast-ci --simulator 'iPhone SE (3rd generation),OS=17.5'
373373

374374
build-emscripten:
375375
name: 'Emscripten'

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ repos:
33
rev: a27a2e47c7751b639d2b5badf0ef6ff11fee893f # frozen: v0.15.4
44
hooks:
55
- id: ruff-check
6-
name: Run Ruff (lint) on Apple/
7-
args: [--exit-non-zero-on-fix, --config=Apple/.ruff.toml]
8-
files: ^Apple/
6+
name: Run Ruff (lint) on Platforms/Apple/
7+
args: [--exit-non-zero-on-fix, --config=Platforms/Apple/.ruff.toml]
8+
files: ^Platforms/Apple/
99
- id: ruff-check
1010
name: Run Ruff (lint) on Doc/
1111
args: [--exit-non-zero-on-fix]
@@ -39,9 +39,9 @@ repos:
3939
args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml]
4040
files: ^Tools/wasm/
4141
- id: ruff-format
42-
name: Run Ruff (format) on Apple/
43-
args: [--exit-non-zero-on-fix, --config=Apple/.ruff.toml]
44-
files: ^Apple
42+
name: Run Ruff (format) on Platforms/Apple/
43+
args: [--exit-non-zero-on-fix, --config=Platforms/Apple/.ruff.toml]
44+
files: ^Platforms/Apple/
4545
- id: ruff-format
4646
name: Run Ruff (format) on Doc/
4747
args: [--exit-non-zero-on-fix]

Doc/c-api/bytearray.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Direct API functions
4444
4545
On failure, return ``NULL`` with an exception set.
4646
47+
.. note::
48+
If the object implements the buffer protocol, then the buffer
49+
must not be mutated while the bytearray object is being created.
50+
4751
4852
.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
4953
@@ -58,6 +62,10 @@ Direct API functions
5862
5963
On failure, return ``NULL`` with an exception set.
6064
65+
.. note::
66+
If the object implements the buffer protocol, then the buffer
67+
must not be mutated while the bytearray object is being created.
68+
6169
6270
.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
6371
@@ -70,6 +78,9 @@ Direct API functions
7078
``NULL`` pointer. The returned array always has an extra
7179
null byte appended.
7280
81+
.. note::
82+
It is not thread-safe to mutate the bytearray object while using the returned char array.
83+
7384
7485
.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
7586
@@ -89,6 +100,9 @@ These macros trade safety for speed and they don't check pointers.
89100
90101
Similar to :c:func:`PyByteArray_AsString`, but without error checking.
91102
103+
.. note::
104+
It is not thread-safe to mutate the bytearray object while using the returned char array.
105+
92106
93107
.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
94108

Doc/c-api/bytes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ called with a non-bytes parameter.
127127
Return the bytes representation of object *o* that implements the buffer
128128
protocol.
129129
130+
.. note::
131+
If the object implements the buffer protocol, then the buffer
132+
must not be mutated while the bytes object is being created.
133+
130134
131135
.. c:function:: Py_ssize_t PyBytes_Size(PyObject *o)
132136
@@ -185,13 +189,20 @@ called with a non-bytes parameter.
185189
created, the old reference to *bytes* will still be discarded and the value
186190
of *\*bytes* will be set to ``NULL``; the appropriate exception will be set.
187191
192+
.. note::
193+
If *newpart* implements the buffer protocol, then the buffer
194+
must not be mutated while the new bytes object is being created.
188195
189196
.. c:function:: void PyBytes_ConcatAndDel(PyObject **bytes, PyObject *newpart)
190197
191198
Create a new bytes object in *\*bytes* containing the contents of *newpart*
192199
appended to *bytes*. This version releases the :term:`strong reference`
193200
to *newpart* (i.e. decrements its reference count).
194201
202+
.. note::
203+
If *newpart* implements the buffer protocol, then the buffer
204+
must not be mutated while the new bytes object is being created.
205+
195206
196207
.. c:function:: PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable)
197208
@@ -210,6 +221,9 @@ called with a non-bytes parameter.
210221
211222
.. versionadded:: 3.14
212223
224+
.. note::
225+
If *iterable* objects implement the buffer protocol, then the buffers
226+
must not be mutated while the new bytes object is being created.
213227
214228
.. c:function:: int _PyBytes_Resize(PyObject **bytes, Py_ssize_t newsize)
215229

Doc/data/threadsafety.dat

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,61 @@ PyList_Reverse:shared:
6666
# is a list
6767
PyList_SetSlice:shared:
6868

69-
# Sort - per-object lock held; comparison callbacks may execute
70-
# arbitrary Python code
69+
# Sort - per-object lock held; the list is emptied before sorting
70+
# so other threads may observe an empty list, but they won't see the
71+
# intermediate states of the sort
7172
PyList_Sort:shared:
7273

7374
# Extend - lock target list; also lock source when it is a
7475
# list, set, or dict
7576
PyList_Extend:shared:
77+
78+
# Creation - pure allocation, no shared state
79+
PyBytes_FromString:atomic:
80+
PyBytes_FromStringAndSize:atomic:
81+
PyBytes_DecodeEscape:atomic:
82+
83+
# Creation from formatting C primitives - pure allocation, no shared state
84+
PyBytes_FromFormat:atomic:
85+
PyBytes_FromFormatV:atomic:
86+
87+
# Creation from object - uses buffer protocol so may call arbitrary code;
88+
# safe as long as the buffer is not mutated by another thread during the operation
89+
PyBytes_FromObject:shared:
90+
91+
# Size - uses atomic load on free-threaded builds
92+
PyBytes_Size:atomic:
93+
PyBytes_GET_SIZE:atomic:
94+
95+
# Raw data - no locking; mutating it is unsafe if the bytes object is shared between threads
96+
PyBytes_AsString:compatible:
97+
PyBytes_AS_STRING:compatible:
98+
PyBytes_AsStringAndSize:compatible:
99+
100+
# Concatenation - uses buffer protocol; safe as long as buffer is not mutated by another thread during the operation
101+
PyBytes_Concat:shared:
102+
PyBytes_ConcatAndDel:shared:
103+
PyBytes_Join:shared:
104+
105+
# Resizing - safe if the object is unique
106+
_PyBytes_Resize:distinct:
107+
108+
# Repr - atomic as bytes are immutable
109+
PyBytes_Repr:atomic:
110+
111+
# Creation from object - may call arbitrary code
112+
PyByteArray_FromObject:shared:
113+
114+
# Creation - pure allocation, no shared state
115+
PyByteArray_FromStringAndSize:atomic:
116+
117+
# Concatenation - uses buffer protocol; safe as long as buffer is not mutated by another thread during the operation
118+
PyByteArray_Concat:shared:
119+
120+
# Size - uses atomic load on free-threaded builds
121+
PyByteArray_Size:atomic:
122+
PyByteArray_GET_SIZE:atomic:
123+
124+
# Raw data - no locking; mutating it is unsafe if the bytearray object is shared between threads
125+
PyByteArray_AsString:compatible:
126+
PyByteArray_AS_STRING:compatible:

Doc/library/json.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Basic Usage
264264

265265
.. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, \
266266
parse_int=None, parse_constant=None, \
267-
object_pairs_hook=None, **kw)
267+
object_pairs_hook=None, array_hook=None, **kw)
268268
269269
Deserialize *fp* to a Python object
270270
using the :ref:`JSON-to-Python conversion table <json-to-py-table>`.
@@ -301,6 +301,15 @@ Basic Usage
301301
Default ``None``.
302302
:type object_pairs_hook: :term:`callable` | None
303303

304+
:param array_hook:
305+
If set, a function that is called with the result of
306+
any JSON array literal decoded with as a Python list.
307+
The return value of this function will be used
308+
instead of the :class:`list`.
309+
This feature can be used to implement custom decoders.
310+
Default ``None``.
311+
:type array_hook: :term:`callable` | None
312+
304313
:param parse_float:
305314
If set, a function that is called with
306315
the string of every JSON float to be decoded.
@@ -349,7 +358,10 @@ Basic Usage
349358
conversion length limitation <int_max_str_digits>` to help avoid denial
350359
of service attacks.
351360

352-
.. function:: loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
361+
.. versionchanged:: next
362+
Added the optional *array_hook* parameter.
363+
364+
.. function:: loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, array_hook=None, **kw)
353365

354366
Identical to :func:`load`, but instead of a file-like object,
355367
deserialize *s* (a :class:`str`, :class:`bytes` or :class:`bytearray`
@@ -367,7 +379,7 @@ Basic Usage
367379
Encoders and Decoders
368380
---------------------
369381

370-
.. class:: JSONDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)
382+
.. class:: JSONDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None, array_hook=None)
371383

372384
Simple JSON decoder.
373385

@@ -412,6 +424,14 @@ Encoders and Decoders
412424
.. versionchanged:: 3.1
413425
Added support for *object_pairs_hook*.
414426

427+
*array_hook* is an optional function that will be called with the
428+
result of every JSON array decoded as a list. The return value of
429+
*array_hook* will be used instead of the :class:`list`. This feature can be
430+
used to implement custom decoders.
431+
432+
.. versionchanged:: next
433+
Added support for *array_hook*.
434+
415435
*parse_float* is an optional function that will be called with the string of
416436
every JSON float to be decoded. By default, this is equivalent to
417437
``float(num_str)``. This can be used to use another datatype or parser for

Doc/library/math.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,7 @@ Constants
848848

849849
The :mod:`!math` module consists mostly of thin wrappers around the platform C
850850
math library functions. Behavior in exceptional cases follows Annex F of
851-
the C99 standard, if :attr:`sys.float_info.iec_60559` is true.
852-
The current implementation will raise
851+
the C99 standard where appropriate. The current implementation will raise
853852
:exc:`ValueError` for invalid operations like ``sqrt(-1.0)`` or ``log(0.0)``
854853
(where C99 Annex F recommends signaling invalid operation or divide-by-zero),
855854
and :exc:`OverflowError` for results that overflow (for example,

Doc/library/struct.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ platform-dependent.
254254
+--------+--------------------------+--------------------+----------------+------------+
255255
| ``N`` | :c:type:`size_t` | integer | | \(3) |
256256
+--------+--------------------------+--------------------+----------------+------------+
257-
| ``e`` | \(6) | float | 2 | \(4) |
257+
| ``e`` | :c:expr:`_Float16` | float | 2 | \(4), \(6) |
258258
+--------+--------------------------+--------------------+----------------+------------+
259259
| ``f`` | :c:expr:`float` | float | 4 | \(4) |
260260
+--------+--------------------------+--------------------+----------------+------------+
@@ -328,7 +328,9 @@ Notes:
328328
revision of the `IEEE 754 standard <ieee 754 standard_>`_. It has a sign
329329
bit, a 5-bit exponent and 11-bit precision (with 10 bits explicitly stored),
330330
and can represent numbers between approximately ``6.1e-05`` and ``6.5e+04``
331-
at full precision. This type is not widely supported by C compilers: on a
331+
at full precision. This type is not widely supported by C compilers:
332+
it's available as :c:expr:`_Float16` type, if the compiler supports the Annex H
333+
of the C23 standard. On a
332334
typical machine, an unsigned short can be used for storage, but not for math
333335
operations. See the Wikipedia page on the `half-precision floating-point
334336
format <half precision format_>`_ for more information.

Doc/library/sys.rst

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
694694
A :term:`named tuple` holding information about the float type. It
695695
contains low level information about the precision and internal
696696
representation. The values correspond to the various floating-point
697-
constants defined by C implementation and in the standard header file
698-
:file:`float.h` for the 'C' programming language; see Annex F and section
699-
5.2.4.2.2 of the 1999 ISO/IEC C standard [C99]_, 'Characteristics of
700-
floating types', for details.
697+
constants defined in the standard header file :file:`float.h` for the 'C'
698+
programming language; see section 5.2.4.2.2 of the 1999 ISO/IEC C standard
699+
[C99]_, 'Characteristics of floating types', for details.
701700

702701
.. list-table:: Attributes of the :data:`!float_info` :term:`named tuple`
703702
:header-rows: 1
704703

705704
* - attribute
706-
- C macro
705+
- float.h macro
707706
- explanation
708707

709708
* - .. attribute:: float_info.epsilon
@@ -772,12 +771,6 @@ always available. Unless explicitly noted otherwise, all variables are read-only
772771
All other values for :c:macro:`!FLT_ROUNDS` characterize
773772
implementation-defined rounding behavior.
774773

775-
* - .. attribute:: float_info.iec_60559
776-
- :c:macro:`!__STDC_IEC_559__`
777-
- A boolean, indicating support the IEC 60559 floating-point standard.
778-
If true, the :class:`float` type characteristics and behavior matches
779-
the IEC 60559 double format.
780-
781774
The attribute :attr:`sys.float_info.dig` needs further explanation. If
782775
``s`` is any string representing a decimal number with at most
783776
:attr:`!sys.float_info.dig` significant digits, then converting ``s`` to a

Doc/whatsnew/3.15.rst

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ Summary -- Release highlights
8484
<whatsnew315-pybyteswriter>`
8585
* :ref:`The JIT compiler has been significantly upgraded <whatsnew315-jit>`
8686
* :ref:`Improved error messages <whatsnew315-improved-error-messages>`
87-
87+
* :ref:`The official Windows 64-bit binaries now use the tail-calling interpreter
88+
<whatsnew315-windows-tail-calling-interpreter>`
8889

8990
New features
9091
============
@@ -805,6 +806,17 @@ inspect
805806
for :func:`~inspect.getdoc`.
806807
(Contributed by Serhiy Storchaka in :gh:`132686`.)
807808

809+
json
810+
----
811+
812+
* Add the *array_hook* parameter to :func:`~json.load` and
813+
:func:`~json.loads` functions:
814+
allow a callback for JSON literal array types to customize Python lists in
815+
the resulting decoded object. Passing combined :class:`frozendict` to
816+
*object_pairs_hook* param and :class:`tuple` to ``array_hook`` will yield a
817+
deeply nested immutable Python structure representing the JSON data.
818+
(Contributed by Joao S. O. Bueno in :gh:`146440`)
819+
808820

809821
locale
810822
------
@@ -1032,11 +1044,6 @@ sys
10321044
* Add :data:`sys.abi_info` namespace to improve access to ABI information.
10331045
(Contributed by Klaus Zimmermann in :gh:`137476`.)
10341046

1035-
* Add :data:`sys.float_info.iec_60559 <sys.float_info>`: a boolean flag,
1036-
indicating support the IEC 60559 floating-point standard (as specified by the
1037-
Annex F of C99).
1038-
(Contributed by Sergey B Kirpichev in :gh:`138580`.)
1039-
10401047

10411048
tarfile
10421049
-------
@@ -1292,18 +1299,6 @@ zlib
12921299
Optimizations
12931300
=============
12941301

1295-
* Builds using Visual Studio 2026 (MSVC 18) may now use the new
1296-
:ref:`tail-calling interpreter <whatsnew314-tail-call-interpreter>`.
1297-
Results on Visual Studio 18.1.1 report between
1298-
`15-20% <https://github.com/faster-cpython/ideas/blob/main/results/5800X-msvc.pgo2-vs-msvc.pgo.tc.svg>`__
1299-
speedup on the geometric mean of pyperformance on Windows x86-64 over
1300-
the switch-case interpreter on an AMD Ryzen 7 5800X. We have
1301-
observed speedups ranging from 14% for large pure-Python libraries
1302-
to 40% for long-running small pure-Python scripts on Windows.
1303-
This was made possible by a new feature introduced in MSVC 18.
1304-
(Contributed by Chris Eibl, Ken Jin, and Brandt Bucher in :gh:`143068`.
1305-
Special thanks to the MSVC team including Hulon Jenkins.)
1306-
13071302
* ``mimalloc`` is now used as the default allocator for
13081303
for raw memory allocations such as via :c:func:`PyMem_RawMalloc`
13091304
for better performance on :term:`free-threaded builds <free-threaded build>`.
@@ -1960,6 +1955,23 @@ Build changes
19601955
and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode <debug-build>`.
19611956
(Contributed by Donghee Na in :gh:`141770`.)
19621957

1958+
.. _whatsnew315-windows-tail-calling-interpreter:
1959+
1960+
* 64-bit builds using Visual Studio 2026 (MSVC 18) may now use the new
1961+
:ref:`tail-calling interpreter <whatsnew314-tail-call-interpreter>`.
1962+
Results on Visual Studio 18.1.1 report between
1963+
`15-20% <https://github.com/faster-cpython/ideas/blob/main/results/5800X-msvc.pgo2-vs-msvc.pgo.tc.svg>`__
1964+
speedup on the geometric mean of pyperformance on Windows x86-64 over
1965+
the switch-case interpreter on an AMD Ryzen 7 5800X. We have
1966+
observed speedups ranging from 14% for large pure-Python libraries
1967+
to 40% for long-running small pure-Python scripts on Windows.
1968+
This was made possible by a new feature introduced in MSVC 18,
1969+
which the official Windows 64-bit binaries on python.org__ now use.
1970+
(Contributed by Chris Eibl, Ken Jin, and Brandt Bucher in :gh:`143068`.
1971+
Special thanks to Steve Dower, and the MSVC team including Hulon Jenkins.)
1972+
1973+
__ https://www.python.org/downloads/windows/
1974+
19631975

19641976
Porting to Python 3.15
19651977
======================

0 commit comments

Comments
 (0)