|
2 | 2 |
|
3 | 3 | .. _stable:
|
4 | 4 |
|
5 |
| -******************* |
6 |
| -C API Compatibility |
7 |
| -******************* |
| 5 | +*************** |
| 6 | +C API Stability |
| 7 | +*************** |
8 | 8 |
|
9 | 9 | Python's C API is covered by the Backwards Compatibility Policy, :pep:`387`.
|
10 | 10 | While the C API will change with every minor release (e.g. from 3.9 to 3.10),
|
@@ -39,19 +39,21 @@ necessary to support older versions of the Limited API.
|
39 | 39 | and Stable ABI work the same way for all uses of the API – for example,
|
40 | 40 | embedding Python.)
|
41 | 41 |
|
42 |
| -To opt in to use the Limited API, define the macro ``Py_LIMITED_API`` |
43 |
| -before including ``Python.h``. |
| 42 | +.. c:macro:: Py_LIMITED_API |
44 | 43 |
|
45 |
| -Defining ``Py_LIMITED_API`` to ``3`` will limit the available API so that |
46 |
| -the extension will work without recompilation with all Python 3.x releases |
47 |
| -(x>=2) on the particular :ref:`platform <stable-abi-platform>`. |
| 44 | + Define this macro ``Py_LIMITED_API`` before including ``Python.h`` to |
| 45 | + opt in to only use the Limited API. |
48 | 46 |
|
49 |
| -Defining ``Py_LIMITED_API`` to a value of :c:data:`PY_VERSION_HEX` will |
50 |
| -do the same, but allow additional API added up to specified version, |
51 |
| -and lose compatibility with earlier versions. |
52 |
| -Rather than using the macro directly, hardcode a minimum minor version |
53 |
| -(e.g. ``0x030A0000`` for Python 3.10) for stability when compiling with |
54 |
| -future Python versions. |
| 47 | + Defining ``Py_LIMITED_API`` to ``3`` will limit the available API so that |
| 48 | + the extension will work without recompilation with all Python 3.x releases |
| 49 | + (x>=2) on the particular :ref:`platform <stable-abi-platform>`. |
| 50 | + |
| 51 | + Defining ``Py_LIMITED_API`` to a value of :c:data:`PY_VERSION_HEX` will |
| 52 | + do the same, but allow additional API added up to specified version, |
| 53 | + and lose compatibility with earlier versions. |
| 54 | + Rather than using the macro directly, hardcode a minimum minor version |
| 55 | + (e.g. ``0x030A0000`` for Python 3.10) for stability when compiling with |
| 56 | + future Python versions. |
55 | 57 |
|
56 | 58 | On Windows, extensions that use the Stable ABI should be linked against
|
57 | 59 | ``python3.dll`` rather than a version-specific library such as
|
@@ -81,13 +83,13 @@ The macro can be faster because it can rely on version-specific implementation
|
81 | 83 | details of the list object.
|
82 | 84 |
|
83 | 85 | Without ``Py_LIMITED_API`` defined, some C API functions are inlined or
|
84 |
| -replaced by similar macros. |
| 86 | +replaced by macros. |
85 | 87 | Defining ``Py_LIMITED_API`` disables this inlining, allowing stability as
|
86 | 88 | Python's data structures are improved, but possibly reducing performance.
|
87 | 89 |
|
88 | 90 | By leaving out the ``Py_LIMITED_API`` definition, it is possible to compile
|
89 |
| -a Limited API extension with a version-specific ABI, gaining performance |
90 |
| -but limiting compatibility. |
| 91 | +a Limited API extension with a version-specific ABI. This can improve |
| 92 | +performance for that Python version, but will limit compatibility. |
91 | 93 | Compiling with ``Py_LIMITED_API`` will then yield an extension that can be
|
92 | 94 | distributed where a version-specific one is not available – for example,
|
93 | 95 | for prereleases of an upcoming Python version.
|
|
0 commit comments