Stéphane Wirtel | cbb6484 | 2019-05-17 11:55:34 +0200 | [diff] [blame] | 1 | .. highlight:: c |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 2 | |
| 3 | .. _apiabiversion: |
| 4 | |
| 5 | *********************** |
| 6 | API and ABI Versioning |
| 7 | *********************** |
| 8 | |
Miss Islington (bot) | 3739371 | 2021-05-13 22:29:09 -0700 | [diff] [blame^] | 9 | CPython exposes its version number in the following macros. |
| 10 | Note that these correspond to the version code is **built** with, |
| 11 | not necessarily the version used at **run time**. |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 12 | |
Miss Islington (bot) | 3739371 | 2021-05-13 22:29:09 -0700 | [diff] [blame^] | 13 | See :ref:`stable` for a discussion of API and ABI stability across versions. |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 14 | |
Miss Islington (bot) | 3739371 | 2021-05-13 22:29:09 -0700 | [diff] [blame^] | 15 | .. c:macro:: PY_MAJOR_VERSION |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 16 | |
Miss Islington (bot) | 3739371 | 2021-05-13 22:29:09 -0700 | [diff] [blame^] | 17 | The ``3`` in ``3.4.1a2``. |
| 18 | |
| 19 | .. c:macro:: PY_MINOR_VERSION |
| 20 | |
| 21 | The ``4`` in ``3.4.1a2``. |
| 22 | |
| 23 | .. c:macro:: PY_MICRO_VERSION |
| 24 | |
| 25 | The ``1`` in ``3.4.1a2``. |
| 26 | |
| 27 | .. c:macro:: PY_RELEASE_LEVEL |
| 28 | |
| 29 | The ``a`` in ``3.4.1a2``. |
| 30 | This can be ``0xA`` for alpha, ``0xB`` for beta, ``0xC`` for release |
| 31 | candidate or ``0xF`` for final. |
| 32 | |
| 33 | .. c:macro:: PY_RELEASE_SERIAL |
| 34 | |
| 35 | The ``2`` in ``3.4.1a2``. Zero for final releases. |
| 36 | |
| 37 | .. c:macro:: PY_VERSION_HEX |
| 38 | |
| 39 | The Python version number encoded in a single integer. |
| 40 | |
| 41 | The underlying version information can be found by treating it as a 32 bit |
| 42 | number in the following manner: |
| 43 | |
| 44 | +-------+-------------------------+-------------------------+--------------------------+ |
| 45 | | Bytes | Bits (big endian order) | Meaning | Value for ``3.4.1a2`` | |
| 46 | +=======+=========================+=========================+==========================+ |
| 47 | | 1 | 1-8 | ``PY_MAJOR_VERSION`` | ``0x03`` | |
| 48 | +-------+-------------------------+-------------------------+--------------------------+ |
| 49 | | 2 | 9-16 | ``PY_MINOR_VERSION`` | ``0x04`` | |
| 50 | +-------+-------------------------+-------------------------+--------------------------+ |
| 51 | | 3 | 17-24 | ``PY_MICRO_VERSION`` | ``0x01`` | |
| 52 | +-------+-------------------------+-------------------------+--------------------------+ |
| 53 | | 4 | 25-28 | ``PY_RELEASE_LEVEL`` | ``0xA`` | |
| 54 | + +-------------------------+-------------------------+--------------------------+ |
| 55 | | | 29-32 | ``PY_RELEASE_SERIAL`` | ``0x2`` | |
| 56 | +-------+-------------------------+-------------------------+--------------------------+ |
| 57 | |
| 58 | Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is |
| 59 | hexversion ``0x030a00f0``. |
| 60 | |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 61 | |
| 62 | All the given macros are defined in :source:`Include/patchlevel.h`. |