Skip to content

Commit 7d82c86

Browse files
committed
Close python#15465: Document C API version macros
Mostly moving the existing macro docs over from the standard library docs to the C API docs where they belong. Patch by Kushal Das.
1 parent 4f19744 commit 7d82c86

File tree

5 files changed

+55
-32
lines changed

5 files changed

+55
-32
lines changed

Doc/c-api/apiabiversion.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. highlightlang:: c
2+
3+
.. _apiabiversion:
4+
5+
***********************
6+
API and ABI Versioning
7+
***********************
8+
9+
``PY_VERSION_HEX`` is the Python version number encoded in a single integer.
10+
11+
For example if the ``PY_VERSION_HEX`` is set to ``0x030401a2``, the underlying
12+
version information can be found by treating it as a 32 bit number in
13+
the following manner:
14+
15+
+-------+-------------------------+------------------------------------------------+
16+
| Bytes | Bits (big endian order) | Meaning |
17+
+=======+=========================+================================================+
18+
| ``1`` | ``1-8`` | ``PY_MAJOR_VERSION`` (the ``3`` in |
19+
| | | ``3.4.1a2``) |
20+
+-------+-------------------------+------------------------------------------------+
21+
| ``2`` | ``9-16`` | ``PY_MINOR_VERSION`` (the ``4`` in |
22+
| | | ``3.4.1a2``) |
23+
+-------+-------------------------+------------------------------------------------+
24+
| ``3`` | ``17-24`` | ``PY_MICRO_VERSION`` (the ``1`` in |
25+
| | | ``3.4.1a2``) |
26+
+-------+-------------------------+------------------------------------------------+
27+
| ``4`` | ``25-28`` | ``PY_RELEASE_LEVEL`` (``0xA`` for alpha, |
28+
| | | ``0xB`` for beta, ``0xC`` for release |
29+
| | | candidate and ``0xF`` for final), in this |
30+
| | | case it is alpha. |
31+
| +-------------------------+------------------------------------------------+
32+
| | ``29-32`` | ``PY_RELEASE_SERIAL`` (the ``2`` in |
33+
| | | ``3.4.1a2``, zero for final releases) |
34+
+-------+-------------------------+------------------------------------------------+
35+
36+
Thus ``3.4.1a2`` is hexversion ``0x030401a2``.
37+
38+
All the given macros are defined in :source:`Include/patchlevel.h`.
39+

Doc/c-api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ document the API functions in detail.
2323
memory.rst
2424
objimpl.rst
2525
stable.rst
26+
apiabiversion.rst

Doc/c-api/stable.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
.. _stable:
44

5-
**********************************
6-
Stable Appliction Binary Interface
7-
**********************************
5+
***********************************
6+
Stable Application Binary Interface
7+
***********************************
88

99
Traditionally, the C API of Python will change with every release.
1010
Most changes will be source-compatible, typically by only adding API,
@@ -23,13 +23,15 @@ need to be recompiled to link with a newer one.
2323

2424
Since Python 3.2, a subset of the API has been declared to guarantee
2525
a stable ABI. Extension modules wishing to use this API need to define
26-
Py_LIMITED_API. A number of interpreter details then become hidden
26+
``Py_LIMITED_API``. A number of interpreter details then become hidden
2727
from the extension module; in return, a module is built that works
28-
on any 3.x version (x>=2) without recompilation. In some cases, the
29-
stable ABI needs to be extended with new functions. Extensions modules
30-
wishing to use these new APIs need to set Py_LIMITED_API to the
31-
PY_VERSION_HEX value of the minimum Python version they want to
32-
support (e.g. 0x03030000 for Python 3.3). Such modules will work
28+
on any 3.x version (x>=2) without recompilation.
29+
30+
In some cases, the stable ABI needs to be extended with new functions.
31+
Extension modules wishing to use these new APIs need to set
32+
``Py_LIMITED_API`` to the ``PY_VERSION_HEX`` value (see
33+
:ref:`apiabiversion`) of the minimum Python version they want to
34+
support (e.g. ``0x03030000`` for Python 3.3). Such modules will work
3335
on all subsequent Python releases, but fail to load (because of
3436
missing symbols) on the older releases.
3537

Doc/library/sys.rst

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -598,29 +598,7 @@ always available.
598598
:term:`struct sequence` :data:`sys.version_info` may be used for a more
599599
human-friendly encoding of the same information.
600600

601-
The ``hexversion`` is a 32-bit number with the following layout:
602-
603-
+-------------------------+------------------------------------------------+
604-
| Bits (big endian order) | Meaning |
605-
+=========================+================================================+
606-
| :const:`1-8` | ``PY_MAJOR_VERSION`` (the ``2`` in |
607-
| | ``2.1.0a3``) |
608-
+-------------------------+------------------------------------------------+
609-
| :const:`9-16` | ``PY_MINOR_VERSION`` (the ``1`` in |
610-
| | ``2.1.0a3``) |
611-
+-------------------------+------------------------------------------------+
612-
| :const:`17-24` | ``PY_MICRO_VERSION`` (the ``0`` in |
613-
| | ``2.1.0a3``) |
614-
+-------------------------+------------------------------------------------+
615-
| :const:`25-28` | ``PY_RELEASE_LEVEL`` (``0xA`` for alpha, |
616-
| | ``0xB`` for beta, ``0xC`` for release |
617-
| | candidate and ``0xF`` for final) |
618-
+-------------------------+------------------------------------------------+
619-
| :const:`29-32` | ``PY_RELEASE_SERIAL`` (the ``3`` in |
620-
| | ``2.1.0a3``, zero for final releases) |
621-
+-------------------------+------------------------------------------------+
622-
623-
Thus ``2.1.0a3`` is hexversion ``0x020100a3``.
601+
More details of ``hexversion`` can be found at :ref:`apiabiversion`
624602

625603

626604
.. data:: implementation

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ Tools/Demos
797797
Documentation
798798
-------------
799799

800+
- Issue #15465: Document the versioning macros in the C API docs rather than
801+
the standard library docs. Patch by Kushal Das.
802+
800803
- Issue #16406: Combine the pages for uploading and registering to PyPI.
801804

802805
- Issue #16403: Document how distutils uses the maintainer field in

0 commit comments

Comments
 (0)