Skip to content

Commit 2f699c7

Browse files
committed
Merge branch 'main' of github.com:python/cpython into mimallocv3
2 parents 3c8be4f + f5bd077 commit 2f699c7

215 files changed

Lines changed: 3923 additions & 1548 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/CODEOWNERS‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,10 @@ Programs/_bootstrap_python.c @ericsnowcurrently @FFY00
283283
Programs/python.c @ericsnowcurrently @FFY00
284284

285285
# JIT
286-
.github/workflows/jit.yml @savannahostrowski
287-
Include/internal/pycore_jit.h @brandtbucher @savannahostrowski @diegorusso
288-
Python/jit.c @brandtbucher @savannahostrowski @diegorusso
289-
Tools/jit/ @brandtbucher @savannahostrowski @diegorusso
290-
InternalDocs/jit.md @brandtbucher @savannahostrowski @diegorusso @AA-Turner
286+
Include/internal/pycore_jit.h @brandtbucher @diegorusso
287+
Python/jit.c @brandtbucher @diegorusso
288+
Tools/jit/ @brandtbucher @diegorusso
289+
InternalDocs/jit.md @brandtbucher @diegorusso @AA-Turner
291290

292291
# Lazy imports (PEP 810)
293292
.github/workflows/reusable-test-lazy-imports-all.yml @yhg1s @DinoV @pablogsal
@@ -297,9 +296,9 @@ Lib/test/test_lazy_import @yhg1s @DinoV @pablogsal
297296

298297
# Micro-op / μop / Tier 2 Optimiser
299298
Python/optimizer.c @markshannon @Fidget-Spinner
300-
Python/optimizer_analysis.c @markshannon @tomasr8 @Fidget-Spinner @savannahostrowski
301-
Python/optimizer_bytecodes.c @markshannon @tomasr8 @Fidget-Spinner @savannahostrowski
302-
Python/optimizer_symbols.c @markshannon @tomasr8 @Fidget-Spinner @savannahostrowski
299+
Python/optimizer_analysis.c @markshannon @tomasr8 @Fidget-Spinner
300+
Python/optimizer_bytecodes.c @markshannon @tomasr8 @Fidget-Spinner
301+
Python/optimizer_symbols.c @markshannon @tomasr8 @Fidget-Spinner
303302

304303
# Parser, Lexer, and Grammar
305304
Grammar/python.gram @pablogsal @lysnikolaou

‎Doc/c-api/extension-modules.rst‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,32 @@ This is typically done using :c:func:`PyModule_Create` and functions like
313313
Single-phase initialization differs from the :ref:`default <multi-phase-initialization>`
314314
in the following ways:
315315
316-
* Single-phase modules are, or rather *contain*, “singletons”.
316+
* Single-phase modules with :c:member:`PyModuleDef.m_size` set to -1 are,
317+
or rather *contain*, “singletons”.
317318
318-
When the module is first initialized, Python saves the contents of
319+
When such a module is first initialized, Python saves the contents of
319320
the module's ``__dict__`` (that is, typically, the module's functions and
320321
types).
321322
322323
For subsequent imports, Python does not call the initialization function
323324
again.
324325
Instead, it creates a new module object with a new ``__dict__``, and copies
325326
the saved contents to it.
327+
Modules are matched to the saved contents by a (*module_name*, *file_name*)
328+
tuple where:
329+
330+
- *module_name* is the module's full dotted name, taken from
331+
:py:attr:`ModuleSpec.name <importlib.machinery.ModuleSpec.name>`
332+
(or the equivalent argument of the importing function).
333+
Note that names that the initialization function uses to create the module
334+
(for example, :c:member:`PyModuleDef.m_name`) are not taken into account.
335+
- *file_name* is the extension's file name.
336+
It is unset for modules not loaded from a file, such as built-ins and
337+
modules added with :c:func:`PyImport_CreateModuleFromInitfunc` or
338+
:c:func:`PyImport_AppendInittab`.
339+
340+
As part of the first initialization, Python also adds the module to
341+
:data:`sys.modules` under its name.
326342
For example, given a single-phase module ``_testsinglephase``
327343
[#testsinglephase]_ that defines a function ``sum`` and an exception class
328344
``error``:
@@ -344,6 +360,16 @@ in the following ways:
344360
345361
The exact behavior should be considered a CPython implementation detail.
346362

363+
* For single-phase modules with non-negative :c:member:`PyModuleDef.m_size`,
364+
Python may cache a pointer to the initialization function under the
365+
(*module_name*, *file_name*) key as for ``m_size == -1``.
366+
367+
Subsequent imports that specify a different initialization function
368+
(for example, using :c:func:`PyImport_CreateModuleFromInitfunc`)
369+
may call either the cached function or the provided "new" one.
370+
371+
The exact behavior should again be considered a CPython implementation detail.
372+
347373
* To work around the fact that ``PyInit_modulename`` does not take a *spec*
348374
argument, some state of the import machinery is saved and applied to the
349375
first suitable module created during the ``PyInit_modulename`` call.

‎Doc/c-api/file.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ the :mod:`io` APIs instead.
6060
raised if the end of the file is reached immediately.
6161
6262
63+
.. c:function:: char* Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
64+
65+
Read a line from the C stream *stream* into the buffer *buf*, like the
66+
C standard library function :c:func:`!fgets`, but treating all of ``\n``,
67+
``\r`` and ``\r\n`` as line endings (see :term:`universal newlines`).
68+
Any ``\r`` or ``\r\n`` read from the stream is stored in *buf* as a
69+
single ``\n``.
70+
71+
At most ``n - 1`` characters are stored in *buf*; reading stops after a
72+
newline has been stored or when the end of the file is reached.
73+
The result is always null-terminated.
74+
*stream* should be opened in binary mode, so that the C library does not
75+
perform its own newline translation.
76+
77+
Return *buf* on success.
78+
Return ``NULL`` if no characters could be read, because *stream* is at
79+
end of file, a read error occurred, or *n* is less than 2.
80+
Like :c:func:`!fgets`, this function does not distinguish between end of
81+
file and a read error, and it does not set an exception.
82+
83+
*fobj* exists only for backward compatibility and must be ``NULL``.
84+
85+
6386
.. c:function:: int PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction handler)
6487
6588
Overrides the normal behavior of :func:`io.open_code` to pass its parameter

‎Doc/c-api/float.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Pack functions
214214
The pack routines write 2, 4 or 8 bytes, starting at *p*. *le* is an
215215
:c:expr:`int` argument, non-zero if you want the bytes string in little-endian
216216
format (exponent last, at ``p+1``, ``p+3``, or ``p+6`` and ``p+7``), zero if you
217-
want big-endian format (exponent first, at *p*). Use the :c:macro:`!PY_LITTLE_ENDIAN`
217+
want big-endian format (exponent first, at *p*). Use the :c:macro:`PY_LITTLE_ENDIAN`
218218
constant to select the native endian: it is equal to ``0`` on big
219219
endian processor, or ``1`` on little endian processor.
220220
@@ -240,7 +240,7 @@ Unpack functions
240240
The unpack routines read 2, 4 or 8 bytes, starting at *p*. *le* is an
241241
:c:expr:`int` argument, non-zero if the bytes string is in little-endian format
242242
(exponent last, at ``p+1``, ``p+3`` or ``p+6`` and ``p+7``), zero if big-endian
243-
(exponent first, at *p*). Use the :c:macro:`!PY_LITTLE_ENDIAN` constant to
243+
(exponent first, at *p*). Use the :c:macro:`PY_LITTLE_ENDIAN` constant to
244244
select the native endian: it is equal to ``0`` on big endian processor, or ``1``
245245
on little endian processor.
246246

‎Doc/c-api/import.rst‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Importing Modules
408408
409409
*spec* must be a :class:`~importlib.machinery.ModuleSpec` object.
410410
411-
*initfunc* must be an :ref:`initialization function <extension-export-hook>`,
411+
*initfunc* must be an :ref:`initialization function <extension-pyinit>`,
412412
the same as for :c:func:`PyImport_AppendInittab`.
413413
414414
On success, create and return a module object.
@@ -417,10 +417,27 @@ Importing Modules
417417
(Custom importers should do this in their
418418
:py:meth:`~importlib.abc.Loader.exec_module` method.)
419419
420-
If the spec's name is dotted and *initfunc* creates the module using only
421-
the last component of the name, the module's :attr:`~module.__name__`
422-
is set to the full name from the spec.
423-
424420
On error, return NULL with an exception set.
425421
422+
For modules using :ref:`legacy single-phase initialization <single-phase-initialization>`,
423+
most of the import process is done in this function, rather than in
424+
extra steps that importers typically take after
425+
:py:meth:`~importlib.abc.Loader.create_module`.
426+
Specifically:
427+
428+
- The module is added to :data:`sys.modules` under the *spec*'s
429+
:py:attr:`~importlib.machinery.ModuleSpec.name` as part of initialization.
430+
- If a single-phase module was previously imported under the
431+
same :py:attr:`~importlib.machinery.ModuleSpec.name` by this function
432+
or as a built-in module (for example, one registered with
433+
:c:func:`PyImport_AppendInittab`), Python may reuse the previous module's
434+
contents instead of calling *initfunc* again.
435+
- The module will be fully initialized by *initfunc*.
436+
Calling :c:func:`PyModule_Exec` on it will have no effect, though it is
437+
still recommended, in case the module later switches to
438+
:ref:`multi-phase initialization <multi-phase-initialization>`.
439+
- Also, if the *spec*'s :py:attr:`!name` contains dots, this name is used
440+
for prepending a parent package to the new module's
441+
:attr:`~module.__name__`.
442+
426443
.. versionadded:: 3.15

‎Doc/c-api/interp-lifecycle.rst‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,48 @@ Initializing and finalizing the interpreter
265265
first initialized).
266266
267267
268+
.. c:function:: int Py_FrozenMain(int argc, char **argv)
269+
270+
.. index:: single: freeze utility
271+
272+
The main program for a "frozen" Python program (an executable that embeds
273+
the interpreter together with the bytecode of the program's modules, as
274+
produced by the :program:`freeze` utility; see :source:`Tools/freeze`).
275+
276+
This function initializes the interpreter, imports the frozen module named
277+
``__main__``, and finalizes the interpreter.
278+
The frozen modules must have been registered in
279+
:c:var:`PyImport_FrozenModules` before calling this function;
280+
it is a fatal error if ``__main__`` is not among them.
281+
282+
*argc* and *argv* are byte strings like the arguments of a C program's
283+
``main`` function, and are passed to the interpreter with
284+
:c:func:`PyConfig_SetBytesArgv`.
285+
Unlike :c:func:`Py_Main`, the arguments are not parsed as Python command
286+
line options (:c:member:`PyConfig.parse_argv` is ``0``), so all of them
287+
are made available to the program in :data:`sys.argv`.
288+
Apart from that, the interpreter uses the
289+
:ref:`Python Configuration <init-python-config>`, so environment variables
290+
such as :envvar:`PYTHONPATH` are honored.
291+
Warnings about the path configuration
292+
(:c:member:`PyConfig.pathconfig_warnings`) are suppressed.
293+
If :envvar:`PYTHONINSPECT` is set and standard input is a terminal, an
294+
interactive prompt is run after ``__main__`` has finished, as with the
295+
:option:`-i` option.
296+
297+
Return ``0`` if ``__main__`` ran without an unhandled exception, ``1``
298+
otherwise, and ``120`` if finalizing the interpreter failed (see
299+
:c:func:`Py_FinalizeEx`).
300+
An unhandled :exc:`SystemExit` terminates the process.
301+
If the interpreter cannot be initialized, the process exits via
302+
:c:func:`Py_ExitStatusException`.
303+
304+
On Windows, this function is not exported by the Python DLL.
305+
The :program:`freeze` utility compiles :file:`Python/frozenmain.c` into the
306+
frozen program instead, together with the Windows-specific hooks that the
307+
function requires.
308+
309+
268310
.. c:function:: int Py_RunMain(void)
269311
270312
Executes the main module in a fully configured CPython runtime.

‎Doc/c-api/intro.rst‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ Numeric utilities
299299
Argument must be a character or an integer in the range [-128, 127] or [0,
300300
255]. This macro returns ``c`` cast to an ``unsigned char``.
301301

302+
.. c:macro:: PY_BIG_ENDIAN
303+
PY_LITTLE_ENDIAN
304+
305+
Constants describing the byte order of the platform that Python was built
306+
for. Exactly one of them is ``1`` and the other is ``0``.
307+
302308

303309
Assertion utilities
304310
^^^^^^^^^^^^^^^^^^^
@@ -916,8 +922,13 @@ use them.
916922
917923
A signed integral type such that ``sizeof(Py_ssize_t) == sizeof(size_t)``.
918924
C99 doesn't define such a thing directly (size_t is an unsigned integral type).
919-
See :pep:`353` for details. ``PY_SSIZE_T_MAX`` is the largest positive value
920-
of type :c:type:`Py_ssize_t`.
925+
See :pep:`353` for details.
926+
927+
.. c:macro:: PY_SSIZE_T_MAX
928+
PY_SSIZE_T_MIN
929+
930+
The limit values (largest positive one and smallest negative one,
931+
respecitvely) of type :c:type:`Py_ssize_t`.
921932

922933

923934
.. _api-exceptions:

‎Doc/c-api/structures.rst‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,20 @@ The following flags can be used with :c:member:`PyMemberDef.flags`:
760760
.. versionchanged:: 3.12
761761
762762
The :c:macro:`!READONLY` macro was renamed to :c:macro:`Py_READONLY`.
763-
The :c:macro:`!PY_AUDIT_READ` macro was renamed with the ``Py_`` prefix.
763+
The :c:macro:`PY_AUDIT_READ` macro was renamed with the ``Py_`` prefix.
764764
The new names are now always available.
765765
Previously, these required ``#include "structmember.h"``.
766766
The header is still available and it provides the old names.
767767
768+
.. c:macro:: PY_AUDIT_READ
769+
770+
Soft-deprecated alias of :c:macro:`Py_AUDIT_READ` (note capitalization of
771+
the ``y``).
772+
Only available with ``#include "structmember.h"``.
773+
774+
.. soft-deprecated:: 3.12
775+
Use :c:macro:`Py_AUDIT_READ` instead.
776+
768777
.. _PyMemberDef-types:
769778
770779
Member types

‎Doc/library/bdb.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The following exception is defined:
1717

1818
Exception raised by the :class:`Bdb` class for quitting the debugger.
1919

20+
.. versionchanged:: 3.16
21+
:exc:`BdbQuit` now inherits from :exc:`BaseException` instead of
22+
:exc:`Exception`.
23+
2024

2125
The :mod:`!bdb` module also defines two classes:
2226

0 commit comments

Comments
 (0)