Skip to content

Commit

Permalink
Merge branch 'main' into host_jit
Browse files Browse the repository at this point in the history
  • Loading branch information
savannahostrowski committed Jan 11, 2025
2 parents f016615 + 1b39b50 commit 2c8158e
Show file tree
Hide file tree
Showing 63 changed files with 1,139 additions and 396 deletions.
102 changes: 76 additions & 26 deletions Doc/c-api/apiabiversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
API and ABI Versioning
***********************


Build-time version constants
----------------------------

CPython exposes its version number in the following macros.
Note that these correspond to the version code is **built** with,
not necessarily the version used at **run time**.
Note that these correspond to the version code is **built** with.
See :c:var:`Py_Version` for the version used at **run time**.

See :ref:`stable` for a discussion of API and ABI stability across versions.

Expand Down Expand Up @@ -37,37 +41,83 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
.. c:macro:: PY_VERSION_HEX
The Python version number encoded in a single integer.
See :c:func:`Py_PACK_FULL_VERSION` for the encoding details.

The underlying version information can be found by treating it as a 32 bit
number in the following manner:

+-------+-------------------------+-------------------------+--------------------------+
| Bytes | Bits (big endian order) | Meaning | Value for ``3.4.1a2`` |
+=======+=========================+=========================+==========================+
| 1 | 1-8 | ``PY_MAJOR_VERSION`` | ``0x03`` |
+-------+-------------------------+-------------------------+--------------------------+
| 2 | 9-16 | ``PY_MINOR_VERSION`` | ``0x04`` |
+-------+-------------------------+-------------------------+--------------------------+
| 3 | 17-24 | ``PY_MICRO_VERSION`` | ``0x01`` |
+-------+-------------------------+-------------------------+--------------------------+
| 4 | 25-28 | ``PY_RELEASE_LEVEL`` | ``0xA`` |
+ +-------------------------+-------------------------+--------------------------+
| | 29-32 | ``PY_RELEASE_SERIAL`` | ``0x2`` |
+-------+-------------------------+-------------------------+--------------------------+
Use this for numeric comparisons, for example,
``#if PY_VERSION_HEX >= ...``.

Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is
hexversion ``0x030a00f0``.

Use this for numeric comparisons, e.g. ``#if PY_VERSION_HEX >= ...``.

This version is also available via the symbol :c:var:`Py_Version`.
Run-time version
----------------

.. c:var:: const unsigned long Py_Version
The Python runtime version number encoded in a single constant integer, with
the same format as the :c:macro:`PY_VERSION_HEX` macro.
The Python runtime version number encoded in a single constant integer.
See :c:func:`Py_PACK_FULL_VERSION` for the encoding details.
This contains the Python version used at run time.

Use this for numeric comparisons, for example, ``if (Py_Version >= ...)``.

.. versionadded:: 3.11

All the given macros are defined in :source:`Include/patchlevel.h`.

Bit-packing macros
------------------

.. c:function:: uint32_t Py_PACK_FULL_VERSION(int major, int minor, int micro, int release_level, int release_serial)
Return the given version, encoded as a single 32-bit integer with
the following structure:
+------------------+-------+----------------+-----------+--------------------------+
| | No. | | | Example values |
| | of | | +-------------+------------+
| Argument | bits | Bit mask | Bit shift | ``3.4.1a2`` | ``3.10.0`` |
+==================+=======+================+===========+=============+============+
| *major* | 8 | ``0xFF000000`` | 24 | ``0x03`` | ``0x03`` |
+------------------+-------+----------------+-----------+-------------+------------+
| *minor* | 8 | ``0x00FF0000`` | 16 | ``0x04`` | ``0x0A`` |
+------------------+-------+----------------+-----------+-------------+------------+
| *micro* | 8 | ``0x0000FF00`` | 8 | ``0x01`` | ``0x00`` |
+------------------+-------+----------------+-----------+-------------+------------+
| *release_level* | 4 | ``0x000000F0`` | 4 | ``0xA`` | ``0xF`` |
+------------------+-------+----------------+-----------+-------------+------------+
| *release_serial* | 4 | ``0x0000000F`` | 0 | ``0x2`` | ``0x0`` |
+------------------+-------+----------------+-----------+-------------+------------+
For example:
+-------------+------------------------------------+-----------------+
| Version | ``Py_PACK_FULL_VERSION`` arguments | Encoded version |
+=============+====================================+=================+
| ``3.4.1a2`` | ``(3, 4, 1, 0xA, 2)`` | ``0x030401a2`` |
+-------------+------------------------------------+-----------------+
| ``3.10.0`` | ``(3, 10, 0, 0xF, 0)`` | ``0x030a00f0`` |
+-------------+------------------------------------+-----------------+
Out-of range bits in the arguments are ignored.
That is, the macro can be defined as:
.. code-block:: c
#ifndef Py_PACK_FULL_VERSION
#define Py_PACK_FULL_VERSION(X, Y, Z, LEVEL, SERIAL) ( \
(((X) & 0xff) << 24) | \
(((Y) & 0xff) << 16) | \
(((Z) & 0xff) << 8) | \
(((LEVEL) & 0xf) << 4) | \
(((SERIAL) & 0xf) << 0))
#endif
``Py_PACK_FULL_VERSION`` is primarily a macro, intended for use in
``#if`` directives, but it is also available as an exported function.

.. versionadded:: 3.14

.. c:function:: uint32_t Py_PACK_VERSION(int major, int minor)
Equivalent to ``Py_PACK_FULL_VERSION(major, minor, 0, 0, 0)``.
The result does not correspond to any Python release, but is useful
in numeric comparisons.
.. versionadded:: 3.14
11 changes: 11 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,17 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
.. versionadded:: 3.8
.. c:function:: PyObject* PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *interp)
Return a :term:`strong reference` to the ``__main__`` `module object <moduleobjects>`_
for the given interpreter.
The caller must hold the GIL.
.. versionadded:: 3.13
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
Type of a frame evaluation function.
Expand Down
2 changes: 2 additions & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ Scheduling callbacks
another thread, this function *must* be used, since :meth:`call_soon` is not
thread-safe.

This function is safe to be called from a reentrant context or signal handler,
however, it is not safe or fruitful to use the returned handle in such contexts.

Raises :exc:`RuntimeError` if called on a loop that's been closed.
This can happen on a secondary thread when the main application is
shutting down.
Expand Down Expand Up @@ -967,6 +970,9 @@ Watching file descriptors
invoke *callback* with the specified arguments once *fd* is available for
reading.

Any preexisting callback registered for *fd* is cancelled and replaced by
*callback*.

.. method:: loop.remove_reader(fd)

Stop monitoring the *fd* file descriptor for read availability. Returns
Expand All @@ -978,6 +984,9 @@ Watching file descriptors
invoke *callback* with the specified arguments once *fd* is available for
writing.

Any preexisting callback registered for *fd* is cancelled and replaced by
*callback*.

Use :func:`functools.partial` :ref:`to pass keyword arguments
<asyncio-pass-keywords>` to *callback*.

Expand Down
6 changes: 3 additions & 3 deletions Doc/library/asyncio-queue.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ Queue

.. method:: task_done()

Indicate that a formerly enqueued task is complete.
Indicate that a formerly enqueued work item is complete.

Used by queue consumers. For each :meth:`~Queue.get` used to
fetch a task, a subsequent call to :meth:`task_done` tells the
queue that the processing on the task is complete.
fetch a work item, a subsequent call to :meth:`task_done` tells the
queue that the processing on the work item is complete.

If a :meth:`join` is currently blocking, it will resume when all
items have been processed (meaning that a :meth:`task_done`
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ The :mod:`functools` module defines the following functions:

If :data:`Placeholder` sentinels are present in *args*, they will be filled first
when :func:`!partial` is called. This makes it possible to pre-fill any positional
argument with a call to :func:`!partial`; without :data:`!Placeholder`, only the
first positional argument can be pre-filled.
argument with a call to :func:`!partial`; without :data:`!Placeholder`,
only the chosen number of leading positional arguments can be pre-filled.

If any :data:`!Placeholder` sentinels are present, all must be filled at call time:

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/importlib.resources.abc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
:const:`None`. An object compatible with this ABC should only be
returned when the specified module is a package.

.. deprecated-removed:: 3.12 3.14
.. deprecated:: 3.12
Use :class:`importlib.resources.abc.TraversableResources` instead.

.. abstractmethod:: open_resource(resource)
Expand Down
12 changes: 6 additions & 6 deletions Doc/library/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ Basic Usage
:raises JSONDecodeError:
When the data being deserialized is not a valid JSON document.

:raises UnicodeDecodeError:
When the data being deserialized does not contain
UTF-8, UTF-16 or UTF-32 encoded data.

.. versionchanged:: 3.1

* Added the optional *object_pairs_hook* parameter.
Expand All @@ -343,15 +347,11 @@ Basic Usage

.. function:: loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)

Deserialize *s* (a :class:`str`, :class:`bytes` or :class:`bytearray`
Identical to :func:`load`, but instead of a file-like object,
deserialize *s* (a :class:`str`, :class:`bytes` or :class:`bytearray`
instance containing a JSON document) to a Python object using this
:ref:`conversion table <json-to-py-table>`.

The other arguments have the same meaning as in :func:`load`.

If the data being deserialized is not a valid JSON document, a
:exc:`JSONDecodeError` will be raised.

.. versionchanged:: 3.6
*s* can now be of type :class:`bytes` or :class:`bytearray`. The
input encoding should be UTF-8, UTF-16 or UTF-32.
Expand Down
12 changes: 7 additions & 5 deletions Doc/library/pdb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ slightly different way:
.. versionadded:: 3.14
The *commands* argument.

.. function:: post_mortem(traceback=None)
.. function:: post_mortem(t=None)

Enter post-mortem debugging of the given *traceback* object. If no
*traceback* is given, it uses the one of the exception that is currently
being handled (an exception must be being handled if the default is to be
used).
Enter post-mortem debugging of the given exception or
:ref:`traceback object <traceback-objects>`. If no value is given, it uses
the exception that is currently being handled, or raises ``ValueError`` if
there isn’t one.

.. versionchanged:: 3.13
Support for exception objects was added.

.. function:: pm()

Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,10 @@ New features
file.
(Contributed by Victor Stinner in :gh:`127350`.)

* Add macros :c:func:`Py_PACK_VERSION` and :c:func:`Py_PACK_FULL_VERSION` for
bit-packing Python version numbers.
(Contributed by Petr Viktorin in :gh:`128629`.)


Porting to Python 3.14
----------------------
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;

extern void _Py_AddRefTotal(PyThreadState *, Py_ssize_t);
extern void _Py_IncRefTotal(PyThreadState *);
extern PyAPI_FUNC(void) _Py_IncRefTotal(PyThreadState *);
extern void _Py_DecRefTotal(PyThreadState *);

# define _Py_DEC_REFTOTAL(interp) \
Expand Down
26 changes: 20 additions & 6 deletions Include/patchlevel.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#ifndef _Py_PATCHLEVEL_H
#define _Py_PATCHLEVEL_H
/* Python version identification scheme.
When the major or minor version changes, the VERSION variable in
Expand Down Expand Up @@ -26,10 +27,23 @@
#define PY_VERSION "3.14.0a3+"
/*--end constants--*/


#define _Py_PACK_FULL_VERSION(X, Y, Z, LEVEL, SERIAL) ( \
(((X) & 0xff) << 24) | \
(((Y) & 0xff) << 16) | \
(((Z) & 0xff) << 8) | \
(((LEVEL) & 0xf) << 4) | \
(((SERIAL) & 0xf) << 0))

/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
#define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \
(PY_MINOR_VERSION << 16) | \
(PY_MICRO_VERSION << 8) | \
(PY_RELEASE_LEVEL << 4) | \
(PY_RELEASE_SERIAL << 0))
#define PY_VERSION_HEX _Py_PACK_FULL_VERSION( \
PY_MAJOR_VERSION, \
PY_MINOR_VERSION, \
PY_MICRO_VERSION, \
PY_RELEASE_LEVEL, \
PY_RELEASE_SERIAL)

// Public Py_PACK_VERSION is declared in pymacro.h; it needs <inttypes.h>.

#endif //_Py_PATCHLEVEL_H
9 changes: 9 additions & 0 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,13 @@
// "comparison of unsigned expression in '< 0' is always false".
#define _Py_IS_TYPE_SIGNED(type) ((type)(-1) <= 0)

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030E0000 // 3.14
// Version helpers. These are primarily macros, but have exported equivalents.
PyAPI_FUNC(uint32_t) Py_PACK_FULL_VERSION(int x, int y, int z, int level, int serial);
PyAPI_FUNC(uint32_t) Py_PACK_VERSION(int x, int y);
#define Py_PACK_FULL_VERSION _Py_PACK_FULL_VERSION
#define Py_PACK_VERSION(X, Y) Py_PACK_FULL_VERSION(X, Y, 0, 0, 0)
#endif // Py_LIMITED_API < 3.14


#endif /* Py_PYMACRO_H */
Loading

0 comments on commit 2c8158e

Please sign in to comment.