API 和 ABI 版本管理
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.
See C API Stability for a discussion of API and ABI stability across versions.
PY_MAJOR_VERSION
The 3
in 3.4.1a2
.
PY_MINOR_VERSION
The 4
in 3.4.1a2
.
PY_MICRO_VERSION
The 1
in 3.4.1a2
.
PY_RELEASE_LEVEL
The a
in 3.4.1a2
. This can be 0xA
for alpha, 0xB
for beta, 0xC
for release candidate or 0xF
for final.
PY_RELEASE_SERIAL
The 2
in 3.4.1a2
. Zero for final releases.
PY_VERSION_HEX
The Python version number encoded in a single integer.
The underlying version information can be found by treating it as a 32 bit number in the following manner:
字节串 | 位数(大端字节序) | 含意 | Value for |
---|---|---|---|
1 | 1-8 |
|
|
2 | 9-16 |
|
|
3 | 17-24 |
|
|
4 | 25-28 |
|
|
29-32 |
|
|
Thus 3.4.1a2
is hexversion 0x030401a2
and 3.10.0
is hexversion 0x030a00f0
.
所有提到的宏都定义在 Include/patchlevel.h。