Skip to content

Commit b9dc6d2

Browse files
committed
Mark up Py_LIMITED_API as a macro
1 parent 61cf858 commit b9dc6d2

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Doc/c-api/stable.rst

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

33
.. _stable:
44

5-
*******************
6-
C API Compatibility
7-
*******************
5+
***************
6+
C API Stability
7+
***************
88

99
Python's C API is covered by the Backwards Compatibility Policy, :pep:`387`.
1010
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.
3939
and Stable ABI work the same way for all uses of the API – for example,
4040
embedding Python.)
4141

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
4443
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.
4846

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.
5557

5658
On Windows, extensions that use the Stable ABI should be linked against
5759
``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
8183
details of the list object.
8284

8385
Without ``Py_LIMITED_API`` defined, some C API functions are inlined or
84-
replaced by similar macros.
86+
replaced by macros.
8587
Defining ``Py_LIMITED_API`` disables this inlining, allowing stability as
8688
Python's data structures are improved, but possibly reducing performance.
8789

8890
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.
9193
Compiling with ``Py_LIMITED_API`` will then yield an extension that can be
9294
distributed where a version-specific one is not available – for example,
9395
for prereleases of an upcoming Python version.

0 commit comments

Comments
 (0)