Skip to content

Commit cae9e7f

Browse files
Deploy preview for PR 1211 🛫
1 parent 742d970 commit cae9e7f

File tree

591 files changed

+845
-674
lines changed

Some content is hidden

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

591 files changed

+845
-674
lines changed

pr-preview/pr-1211/_sources/c-api/memory.rst.txt

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ The following function sets, modeled after the ANSI C standard, but specifying
208208
behavior when requesting zero bytes, are available for allocating and releasing
209209
memory from the Python heap.
210210
211-
The :ref:`default memory allocator <default-memory-allocators>` uses the
212-
:ref:`pymalloc memory allocator <pymalloc>`.
211+
In the GIL-enabled build (default build) the
212+
:ref:`default memory allocator <default-memory-allocators>` uses the
213+
:ref:`pymalloc memory allocator <pymalloc>`, whereas in the
214+
:term:`free-threaded build`, the default is the
215+
:ref:`mimalloc memory allocator <mimalloc>` instead.
213216
214217
.. warning::
215218
@@ -219,6 +222,11 @@ The :ref:`default memory allocator <default-memory-allocators>` uses the
219222
220223
The default allocator is now pymalloc instead of system :c:func:`malloc`.
221224
225+
.. versionchanged:: 3.13
226+
227+
In the :term:`free-threaded <free threading>` build, the default allocator
228+
is now :ref:`mimalloc <mimalloc>`.
229+
222230
.. c:function:: void* PyMem_Malloc(size_t n)
223231
224232
Allocates *n* bytes and returns a pointer of type :c:expr:`void*` to the
@@ -344,7 +352,9 @@ memory from the Python heap.
344352
the :ref:`Customize Memory Allocators <customize-memory-allocators>` section.
345353
346354
The :ref:`default object allocator <default-memory-allocators>` uses the
347-
:ref:`pymalloc memory allocator <pymalloc>`.
355+
:ref:`pymalloc memory allocator <pymalloc>`. In the
356+
:term:`free-threaded <free threading>` build, the default is the
357+
:ref:`mimalloc memory allocator <mimalloc>` instead.
348358
349359
.. warning::
350360
@@ -424,23 +434,24 @@ Default Memory Allocators
424434
425435
Default memory allocators:
426436
427-
=============================== ==================== ================== ===================== ====================
428-
Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
429-
=============================== ==================== ================== ===================== ====================
430-
Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc``
431-
Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug
432-
Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc``
433-
Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug
434-
=============================== ==================== ================== ===================== ====================
437+
=================================== ======================= ==================== ====================== ======================
438+
Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
439+
=================================== ======================= ==================== ====================== ======================
440+
Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc``
441+
Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug
442+
Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc``
443+
Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug
444+
Free-threaded build ``"mimalloc"`` ``mimalloc`` ``mimalloc`` ``mimalloc``
445+
Free-threaded debug build ``"mimalloc_debug"`` ``mimalloc`` + debug ``mimalloc`` + debug ``mimalloc`` + debug
446+
=================================== ======================= ==================== ====================== ======================
435447
436448
Legend:
437449
438450
* Name: value for :envvar:`PYTHONMALLOC` environment variable.
439451
* ``malloc``: system allocators from the standard C library, C functions:
440452
:c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`.
441453
* ``pymalloc``: :ref:`pymalloc memory allocator <pymalloc>`.
442-
* ``mimalloc``: :ref:`mimalloc memory allocator <mimalloc>`. The pymalloc
443-
allocator will be used if mimalloc support isn't available.
454+
* ``mimalloc``: :ref:`mimalloc memory allocator <mimalloc>`.
444455
* "+ debug": with :ref:`debug hooks on the Python memory allocators
445456
<pymem-debug-hooks>`.
446457
* "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
=================

pr-preview/pr-1211/_sources/library/email.parser.rst.txt

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`

pr-preview/pr-1211/_sources/library/exceptions.rst.txt

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

pr-preview/pr-1211/_sources/library/functions.rst.txt

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

599599
This function executes arbitrary code. Calling it with
600-
user-supplied input may lead to security vulnerabilities.
600+
untrusted user-supplied input will lead to security vulnerabilities.
601601

602602
The *source* argument is parsed and evaluated as a Python expression
603603
(technically speaking, a condition list) using the *globals* and *locals*
604604
mappings as global and local namespace. If the *globals* dictionary is
605605
present and does not contain a value for the key ``__builtins__``, a
606606
reference to the dictionary of the built-in module :mod:`builtins` is
607-
inserted under that key before *source* is parsed. That way you can
608-
control what builtins are available to the executed code by inserting your
609-
own ``__builtins__`` dictionary into *globals* before passing it to
610-
:func:`eval`. If the *locals* mapping is omitted it defaults to the
607+
inserted under that key before *source* is parsed.
608+
Overriding ``__builtins__`` can be used to restrict or change the available
609+
names, but this is **not** a security mechanism: the executed code can
610+
still access all builtins.
611+
If the *locals* mapping is omitted it defaults to the
611612
*globals* dictionary. If both mappings are omitted, the source is
612613
executed with the *globals* and *locals* in the environment where
613614
:func:`eval` is called. Note, *eval()* will only have access to the
@@ -658,7 +659,7 @@ are always available. They are listed here in alphabetical order.
658659
.. warning::
659660

660661
This function executes arbitrary code. Calling it with
661-
user-supplied input may lead to security vulnerabilities.
662+
untrusted user-supplied input will lead to security vulnerabilities.
662663

663664
This function supports dynamic execution of Python code. *source* must be
664665
either a string or a code object. If it is a string, the string is parsed as
@@ -689,9 +690,10 @@ are always available. They are listed here in alphabetical order.
689690

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

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

pr-preview/pr-1211/_sources/library/os.rst.txt

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

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

13031303
.. versionchanged:: 3.3
13041304
Added the *dir_fd* parameter.
@@ -1652,7 +1652,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
16521652
descriptor as returned by :func:`os.open` or :func:`pipe`. To read a
16531653
"file object" returned by the built-in function :func:`open` or by
16541654
:func:`popen` or :func:`fdopen`, or :data:`sys.stdin`, use its
1655-
:meth:`~file.read` or :meth:`~file.readline` methods.
1655+
:meth:`~io.TextIOBase.read` or :meth:`~io.IOBase.readline` methods.
16561656

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

18921892
.. versionchanged:: 3.5
18931893
If the system call is interrupted and the signal handler does not raise an
@@ -4326,7 +4326,7 @@ to be ignored.
43264326
The current process is replaced immediately. Open file objects and
43274327
descriptors are not flushed, so if there may be data buffered
43284328
on these open files, you should flush them using
4329-
:func:`sys.stdout.flush` or :func:`os.fsync` before calling an
4329+
:func:`~io.IOBase.flush` or :func:`os.fsync` before calling an
43304330
:func:`exec\* <execl>` function.
43314331

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

pr-preview/pr-1211/_sources/library/stdtypes.rst.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,10 @@ The conversion types are:
31903190
| | character in the result. | |
31913191
+------------+-----------------------------------------------------+-------+
31923192

3193+
For floating-point formats, the result should be correctly rounded to a given
3194+
precision ``p`` of digits after the decimal point. The rounding mode matches
3195+
that of the :func:`round` builtin.
3196+
31933197
Notes:
31943198

31953199
(1)

pr-preview/pr-1211/_sources/reference/datamodel.rst.txt

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,12 +1417,28 @@ also :func:`os.popen`, :func:`os.fdopen`, and the
14171417
:meth:`~socket.socket.makefile` method of socket objects (and perhaps by
14181418
other functions or methods provided by extension modules).
14191419

1420+
File objects implement common methods, listed below, to simplify usage in
1421+
generic code. They are expected to be :ref:`context-managers`.
1422+
14201423
The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are
14211424
initialized to file objects corresponding to the interpreter's standard
14221425
input, output and error streams; they are all open in text mode and
14231426
therefore follow the interface defined by the :class:`io.TextIOBase`
14241427
abstract class.
14251428

1429+
.. method:: file.read(size=-1, /)
1430+
1431+
Retrieve up to *size* data from the file. As a convenience if *size* is
1432+
unspecified or -1 retrieve all data available.
1433+
1434+
.. method:: file.write(data, /)
1435+
1436+
Store *data* to the file.
1437+
1438+
.. method:: file.close()
1439+
1440+
Flush any buffers and close the underlying file.
1441+
14261442

14271443
Internal types
14281444
--------------
@@ -3226,21 +3242,6 @@ through the object's keys; for sequences, it should iterate through the values.
32263242
.. versionadded:: 3.4
32273243

32283244

3229-
.. index:: pair: object; slice
3230-
3231-
.. note::
3232-
3233-
Slicing is done exclusively with the following three methods. A call like ::
3234-
3235-
a[1:2] = b
3236-
3237-
is translated to ::
3238-
3239-
a[slice(1, 2, None)] = b
3240-
3241-
and so forth. Missing slice items are always filled in with ``None``.
3242-
3243-
32443245
.. method:: object.__getitem__(self, subscript)
32453246

32463247
Called to implement *subscription*, that is, ``self[subscript]``.
@@ -3263,6 +3264,22 @@ through the object's keys; for sequences, it should iterate through the values.
32633264
should raise an :exc:`LookupError` or one of its subclasses
32643265
(:exc:`IndexError` for sequences; :exc:`KeyError` for mappings).
32653266

3267+
.. index:: pair: object; slice
3268+
3269+
.. note::
3270+
3271+
Slicing is handled by :meth:`!__getitem__`, :meth:`~object.__setitem__`,
3272+
and :meth:`~object.__delitem__`.
3273+
A call like ::
3274+
3275+
a[1:2] = b
3276+
3277+
is translated to ::
3278+
3279+
a[slice(1, 2, None)] = b
3280+
3281+
and so forth. Missing slice items are always filled in with ``None``.
3282+
32663283
.. note::
32673284

32683285
The sequence iteration protocol (used, for example, in :keyword:`for`

pr-preview/pr-1211/_sources/using/cmdline.rst.txt

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

1048+
.. note::
1049+
1050+
In the :term:`free-threaded <free threading>` build, the ``malloc``,
1051+
``malloc_debug``, ``pymalloc``, and ``pymalloc_debug`` values are not
1052+
supported. Only ``default``, ``debug``, ``mimalloc``, and
1053+
``mimalloc_debug`` are accepted.
1054+
10481055
.. versionadded:: 3.6
10491056

10501057
.. versionchanged:: 3.7
@@ -1054,12 +1061,13 @@ conflict.
10541061
.. envvar:: PYTHONMALLOCSTATS
10551062

10561063
If set to a non-empty string, Python will print statistics of the
1057-
:ref:`pymalloc memory allocator <pymalloc>` every time a new pymalloc object
1058-
arena is created, and on shutdown.
1064+
:ref:`pymalloc memory allocator <pymalloc>` or the
1065+
:ref:`mimalloc memory allocator <mimalloc>` (whichever is in use)
1066+
every time a new object arena is created, and on shutdown.
10591067

10601068
This variable is ignored if the :envvar:`PYTHONMALLOC` environment variable
10611069
is used to force the :c:func:`malloc` allocator of the C library, or if
1062-
Python is configured without ``pymalloc`` support.
1070+
Python is configured without both ``pymalloc`` and ``mimalloc`` support.
10631071

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

pr-preview/pr-1211/_sources/using/configure.rst.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ also be used to improve performance.
747747
Disable the fast :ref:`mimalloc <mimalloc>` allocator
748748
(enabled by default).
749749

750+
This option cannot be used together with :option:`--disable-gil`
751+
because the :term:`free-threaded <free threading>` build requires mimalloc.
752+
750753
See also :envvar:`PYTHONMALLOC` environment variable.
751754

752755
.. option:: --without-pymalloc

pr-preview/pr-1211/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ <h3>導航</h3>
356356
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
357357
<br>
358358
<br>
359-
最後更新於 3月 11, 2026 (00:22 UTC)。
359+
最後更新於 3月 12, 2026 (00:22 UTC)。
360360

361361
<a href="/bugs.html">發現 bug</a>
362362

0 commit comments

Comments
 (0)