Skip to content

Commit d7da0f8

Browse files
Merge branch 'main' into deprecate-struct-init
2 parents 6d60b16 + 4722202 commit d7da0f8

Some content is hidden

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

61 files changed

+750
-796
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ Tools/c-analyzer/ @ericsnowcurrently
132132
Tools/check-c-api-docs/ @ZeroIntensity
133133

134134
# Fuzzing
135-
Modules/_xxtestfuzz/ @ammaraskar
135+
Modules/_xxtestfuzz/ @python/fuzzers
136+
Lib/test/test_xxtestfuzz.py @python/fuzzers
137+
.github/workflows/reusable-cifuzz.yml @python/fuzzers
136138

137139
# Limited C API & Stable ABI
138140
Doc/c-api/stable.rst @encukou

Doc/c-api/float.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,6 @@ endian processor, or ``0`` on little endian processor.
224224
Return value: ``0`` if all is OK, ``-1`` if error (and an exception is set,
225225
most likely :exc:`OverflowError`).
226226
227-
There are two problems on non-IEEE platforms:
228-
229-
* What this does is undefined if *x* is a NaN or infinity.
230-
* ``-0.0`` and ``+0.0`` produce the same bytes string.
231-
232227
.. c:function:: int PyFloat_Pack2(double x, char *p, int le)
233228
234229
Pack a C double as the IEEE 754 binary16 half-precision format.
@@ -256,9 +251,6 @@ Return value: The unpacked double. On error, this is ``-1.0`` and
256251
:c:func:`PyErr_Occurred` is true (and an exception is set, most likely
257252
:exc:`OverflowError`).
258253
259-
Note that on a non-IEEE platform this will refuse to unpack a bytes string that
260-
represents a NaN or infinity.
261-
262254
.. c:function:: double PyFloat_Unpack2(const char *p, int le)
263255
264256
Unpack the IEEE 754 binary16 half-precision format as a C double.

Doc/c-api/memory.rst

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,11 @@ The following function sets, modeled after the ANSI C standard, but specifying
204204
behavior when requesting zero bytes, are available for allocating and releasing
205205
memory from the Python heap.
206206
207-
The :ref:`default memory allocator <default-memory-allocators>` uses the
208-
:ref:`pymalloc memory allocator <pymalloc>`.
207+
In the GIL-enabled build (default build) the
208+
:ref:`default memory allocator <default-memory-allocators>` uses the
209+
:ref:`pymalloc memory allocator <pymalloc>`, whereas in the
210+
:term:`free-threaded build`, the default is the
211+
:ref:`mimalloc memory allocator <mimalloc>` instead.
209212
210213
.. warning::
211214
@@ -215,6 +218,11 @@ The :ref:`default memory allocator <default-memory-allocators>` uses the
215218
216219
The default allocator is now pymalloc instead of system :c:func:`malloc`.
217220
221+
.. versionchanged:: 3.13
222+
223+
In the :term:`free-threaded <free threading>` build, the default allocator
224+
is now :ref:`mimalloc <mimalloc>`.
225+
218226
.. c:function:: void* PyMem_Malloc(size_t n)
219227
220228
Allocates *n* bytes and returns a pointer of type :c:expr:`void*` to the
@@ -340,7 +348,9 @@ memory from the Python heap.
340348
the :ref:`Customize Memory Allocators <customize-memory-allocators>` section.
341349
342350
The :ref:`default object allocator <default-memory-allocators>` uses the
343-
:ref:`pymalloc memory allocator <pymalloc>`.
351+
:ref:`pymalloc memory allocator <pymalloc>`. In the
352+
:term:`free-threaded <free threading>` build, the default is the
353+
:ref:`mimalloc memory allocator <mimalloc>` instead.
344354
345355
.. warning::
346356
@@ -420,23 +430,24 @@ Default Memory Allocators
420430
421431
Default memory allocators:
422432
423-
=============================== ==================== ================== ===================== ====================
424-
Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
425-
=============================== ==================== ================== ===================== ====================
426-
Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc``
427-
Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug
428-
Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc``
429-
Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug
430-
=============================== ==================== ================== ===================== ====================
433+
=================================== ======================= ==================== ====================== ======================
434+
Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
435+
=================================== ======================= ==================== ====================== ======================
436+
Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc``
437+
Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug
438+
Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc``
439+
Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug
440+
Free-threaded build ``"mimalloc"`` ``mimalloc`` ``mimalloc`` ``mimalloc``
441+
Free-threaded debug build ``"mimalloc_debug"`` ``mimalloc`` + debug ``mimalloc`` + debug ``mimalloc`` + debug
442+
=================================== ======================= ==================== ====================== ======================
431443
432444
Legend:
433445
434446
* Name: value for :envvar:`PYTHONMALLOC` environment variable.
435447
* ``malloc``: system allocators from the standard C library, C functions:
436448
:c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`.
437449
* ``pymalloc``: :ref:`pymalloc memory allocator <pymalloc>`.
438-
* ``mimalloc``: :ref:`mimalloc memory allocator <mimalloc>`. The pymalloc
439-
allocator will be used if mimalloc support isn't available.
450+
* ``mimalloc``: :ref:`mimalloc memory allocator <mimalloc>`.
440451
* "+ debug": with :ref:`debug hooks on the Python memory allocators
441452
<pymem-debug-hooks>`.
442453
* "Debug build": :ref:`Python build in debug mode <debug-build>`.
@@ -733,9 +744,27 @@ The mimalloc allocator
733744
734745
.. versionadded:: 3.13
735746
736-
Python supports the mimalloc allocator when the underlying platform support is available.
737-
mimalloc "is a general purpose allocator with excellent performance characteristics.
738-
Initially developed by Daan Leijen for the runtime systems of the Koka and Lean languages."
747+
Python supports the `mimalloc <https://github.com/microsoft/mimalloc/>`__
748+
allocator when the underlying platform support is available.
749+
mimalloc is a general purpose allocator with excellent performance
750+
characteristics, initially developed by Daan Leijen for the runtime systems
751+
of the Koka and Lean languages.
752+
753+
Unlike :ref:`pymalloc <pymalloc>`, which is optimized for small objects (512
754+
bytes or fewer), mimalloc handles allocations of any size.
755+
756+
In the :term:`free-threaded <free threading>` build, mimalloc is the default
757+
and **required** allocator for the :c:macro:`PYMEM_DOMAIN_MEM` and
758+
:c:macro:`PYMEM_DOMAIN_OBJ` domains. It cannot be disabled in free-threaded
759+
builds. The free-threaded build uses per-thread mimalloc heaps, which allows
760+
allocation and deallocation to proceed without locking in most cases.
761+
762+
In the default (non-free-threaded) build, mimalloc is available but not the
763+
default allocator. It can be selected at runtime using
764+
:envvar:`PYTHONMALLOC`\ ``=mimalloc`` (or ``mimalloc_debug`` to include
765+
:ref:`debug hooks <pymem-debug-hooks>`). It can be disabled at build time
766+
using the :option:`--without-mimalloc` configure option, but this option
767+
cannot be combined with :option:`--disable-gil`.
739768
740769
tracemalloc C API
741770
=================

Doc/library/email.parser.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ message body, instead setting the payload to the raw body.
155155

156156
Read all the data from the binary file-like object *fp*, parse the
157157
resulting bytes, and return the message object. *fp* must support
158-
both the :meth:`~io.IOBase.readline` and the :meth:`~io.IOBase.read`
158+
both the :meth:`~io.IOBase.readline` and the :meth:`~io.BufferedIOBase.read`
159159
methods.
160160

161161
The bytes contained in *fp* must be formatted as a block of :rfc:`5322`

Doc/library/exceptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ The following exceptions are the exceptions that are usually raised.
221221
.. exception:: EOFError
222222

223223
Raised when the :func:`input` function hits an end-of-file condition (EOF)
224-
without reading any data. (Note: the :meth:`!io.IOBase.read` and
224+
without reading any data. (Note: the :meth:`io.TextIOBase.read` and
225225
:meth:`io.IOBase.readline` methods return an empty string when they hit EOF.)
226226

227227

Doc/library/functions.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -606,17 +606,18 @@ are always available. They are listed here in alphabetical order.
606606
.. warning::
607607

608608
This function executes arbitrary code. Calling it with
609-
user-supplied input may lead to security vulnerabilities.
609+
untrusted user-supplied input will lead to security vulnerabilities.
610610

611611
The *source* argument is parsed and evaluated as a Python expression
612612
(technically speaking, a condition list) using the *globals* and *locals*
613613
mappings as global and local namespace. If the *globals* dictionary is
614614
present and does not contain a value for the key ``__builtins__``, a
615615
reference to the dictionary of the built-in module :mod:`builtins` is
616-
inserted under that key before *source* is parsed. That way you can
617-
control what builtins are available to the executed code by inserting your
618-
own ``__builtins__`` dictionary into *globals* before passing it to
619-
:func:`eval`. If the *locals* mapping is omitted it defaults to the
616+
inserted under that key before *source* is parsed.
617+
Overriding ``__builtins__`` can be used to restrict or change the available
618+
names, but this is **not** a security mechanism: the executed code can
619+
still access all builtins.
620+
If the *locals* mapping is omitted it defaults to the
620621
*globals* dictionary. If both mappings are omitted, the source is
621622
executed with the *globals* and *locals* in the environment where
622623
:func:`eval` is called. Note, *eval()* will only have access to the
@@ -671,7 +672,7 @@ are always available. They are listed here in alphabetical order.
671672
.. warning::
672673

673674
This function executes arbitrary code. Calling it with
674-
user-supplied input may lead to security vulnerabilities.
675+
untrusted user-supplied input will lead to security vulnerabilities.
675676

676677
This function supports dynamic execution of Python code. *source* must be
677678
either a string or a code object. If it is a string, the string is parsed as
@@ -702,9 +703,10 @@ are always available. They are listed here in alphabetical order.
702703

703704
If the *globals* dictionary does not contain a value for the key
704705
``__builtins__``, a reference to the dictionary of the built-in module
705-
:mod:`builtins` is inserted under that key. That way you can control what
706-
builtins are available to the executed code by inserting your own
707-
``__builtins__`` dictionary into *globals* before passing it to :func:`exec`.
706+
:mod:`builtins` is inserted under that key.
707+
Overriding ``__builtins__`` can be used to restrict or change the available
708+
names, but this is **not** a security mechanism: the executed code can
709+
still access all builtins.
708710

709711
The *closure* argument specifies a closure--a tuple of cellvars.
710712
It's only valid when the *object* is a code object containing

Doc/library/os.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,8 @@ as internal buffering of data.
12941294

12951295
This function is intended for low-level I/O. For normal usage, use the
12961296
built-in function :func:`open`, which returns a :term:`file object` with
1297-
:meth:`~file.read` and :meth:`~file.write` methods (and many more). To
1298-
wrap a file descriptor in a file object, use :func:`fdopen`.
1297+
:meth:`~io.BufferedIOBase.read` and :meth:`~io.BufferedIOBase.write` methods.
1298+
To wrap a file descriptor in a file object, use :func:`fdopen`.
12991299

13001300
.. versionchanged:: 3.3
13011301
Added the *dir_fd* parameter.
@@ -1670,7 +1670,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
16701670
descriptor as returned by :func:`os.open` or :func:`pipe`. To read a
16711671
"file object" returned by the built-in function :func:`open` or by
16721672
:func:`popen` or :func:`fdopen`, or :data:`sys.stdin`, use its
1673-
:meth:`~file.read` or :meth:`~file.readline` methods.
1673+
:meth:`~io.TextIOBase.read` or :meth:`~io.IOBase.readline` methods.
16741674

16751675
.. versionchanged:: 3.5
16761676
If the system call is interrupted and the signal handler does not raise an
@@ -1905,7 +1905,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
19051905
descriptor as returned by :func:`os.open` or :func:`pipe`. To write a "file
19061906
object" returned by the built-in function :func:`open` or by :func:`popen` or
19071907
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its
1908-
:meth:`~file.write` method.
1908+
:meth:`~io.TextIOBase.write` method.
19091909

19101910
.. versionchanged:: 3.5
19111911
If the system call is interrupted and the signal handler does not raise an
@@ -4720,7 +4720,7 @@ to be ignored.
47204720
The current process is replaced immediately. Open file objects and
47214721
descriptors are not flushed, so if there may be data buffered
47224722
on these open files, you should flush them using
4723-
:func:`sys.stdout.flush` or :func:`os.fsync` before calling an
4723+
:func:`~io.IOBase.flush` or :func:`os.fsync` before calling an
47244724
:func:`exec\* <execl>` function.
47254725

47264726
The "l" and "v" variants of the :func:`exec\* <execl>` functions differ in how

Doc/library/stdtypes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,10 @@ The conversion types are:
32023202
| | character in the result. | |
32033203
+------------+-----------------------------------------------------+-------+
32043204

3205+
For floating-point formats, the result should be correctly rounded to a given
3206+
precision ``p`` of digits after the decimal point. The rounding mode matches
3207+
that of the :func:`round` builtin.
3208+
32053209
Notes:
32063210

32073211
(1)

Doc/reference/datamodel.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,12 +1401,28 @@ also :func:`os.popen`, :func:`os.fdopen`, and the
14011401
:meth:`~socket.socket.makefile` method of socket objects (and perhaps by
14021402
other functions or methods provided by extension modules).
14031403

1404+
File objects implement common methods, listed below, to simplify usage in
1405+
generic code. They are expected to be :ref:`context-managers`.
1406+
14041407
The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are
14051408
initialized to file objects corresponding to the interpreter's standard
14061409
input, output and error streams; they are all open in text mode and
14071410
therefore follow the interface defined by the :class:`io.TextIOBase`
14081411
abstract class.
14091412

1413+
.. method:: file.read(size=-1, /)
1414+
1415+
Retrieve up to *size* data from the file. As a convenience if *size* is
1416+
unspecified or -1 retrieve all data available.
1417+
1418+
.. method:: file.write(data, /)
1419+
1420+
Store *data* to the file.
1421+
1422+
.. method:: file.close()
1423+
1424+
Flush any buffers and close the underlying file.
1425+
14101426

14111427
Internal types
14121428
--------------

Doc/using/cmdline.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,13 @@ conflict.
10851085
* ``pymalloc_debug``: same as ``pymalloc`` but also install debug hooks.
10861086
* ``mimalloc_debug``: same as ``mimalloc`` but also install debug hooks.
10871087

1088+
.. note::
1089+
1090+
In the :term:`free-threaded <free threading>` build, the ``malloc``,
1091+
``malloc_debug``, ``pymalloc``, and ``pymalloc_debug`` values are not
1092+
supported. Only ``default``, ``debug``, ``mimalloc``, and
1093+
``mimalloc_debug`` are accepted.
1094+
10881095
.. versionadded:: 3.6
10891096

10901097
.. versionchanged:: 3.7
@@ -1094,12 +1101,13 @@ conflict.
10941101
.. envvar:: PYTHONMALLOCSTATS
10951102

10961103
If set to a non-empty string, Python will print statistics of the
1097-
:ref:`pymalloc memory allocator <pymalloc>` every time a new pymalloc object
1098-
arena is created, and on shutdown.
1104+
:ref:`pymalloc memory allocator <pymalloc>` or the
1105+
:ref:`mimalloc memory allocator <mimalloc>` (whichever is in use)
1106+
every time a new object arena is created, and on shutdown.
10991107

11001108
This variable is ignored if the :envvar:`PYTHONMALLOC` environment variable
11011109
is used to force the :c:func:`malloc` allocator of the C library, or if
1102-
Python is configured without ``pymalloc`` support.
1110+
Python is configured without both ``pymalloc`` and ``mimalloc`` support.
11031111

11041112
.. versionchanged:: 3.6
11051113
This variable can now also be used on Python compiled in release mode.

0 commit comments

Comments
 (0)