Skip to content

Commit 967be20

Browse files
vstinnerAA-Turner
authored andcommitted
[3.12] gh-102304: doc: Add links to Stable ABI and Limited C API (#105345) (#105371)
* gh-102304: doc: Add links to Stable ABI and Limited C API (#105345) * Add "limited-c-api" and "stable-api" references. * Rename "stable-abi-list" reference to "limited-api-list". * Makefile: Document files regenerated by "make regen-limited-abi" * Remove first empty line in generated files: - Lib/test/test_stable_abi_ctypes.py - PC/python3dll.c (cherry picked from commit bae415a) * gh-102304: Fix up Simple ABI doc (GH-105351) (cherry picked from commit 0202aa0) (cherry picked from commit 82ab13c)
1 parent f764abb commit 967be20

15 files changed

+54
-37
lines changed

Doc/c-api/exceptions.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -806,15 +806,15 @@ because the :ref:`call protocol <call>` takes care of recursion handling.
806806
depth limit.
807807
808808
.. versionchanged:: 3.9
809-
This function is now also available in the limited API.
809+
This function is now also available in the :ref:`limited API <limited-c-api>`.
810810
811811
.. c:function:: void Py_LeaveRecursiveCall(void)
812812
813813
Ends a :c:func:`Py_EnterRecursiveCall`. Must be called once for each
814814
*successful* invocation of :c:func:`Py_EnterRecursiveCall`.
815815
816816
.. versionchanged:: 3.9
817-
This function is now also available in the limited API.
817+
This function is now also available in the :ref:`limited API <limited-c-api>`.
818818
819819
Properly implementing :c:member:`~PyTypeObject.tp_repr` for container types requires
820820
special recursion handling. In addition to protecting the stack,

Doc/c-api/stable.rst

+31-18
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ are private API that can change without notice even in patch releases.
2525
Stable Application Binary Interface
2626
===================================
2727

28+
For simplicity, this document talks about *extensions*, but the Limited API
29+
and Stable ABI work the same way for all uses of the API – for example,
30+
embedding Python.
31+
32+
.. _limited-c-api:
33+
34+
Limited C API
35+
-------------
36+
2837
Python 3.2 introduced the *Limited API*, a subset of Python's C API.
2938
Extensions that only use the Limited API can be
3039
compiled once and work with multiple versions of Python.
31-
Contents of the Limited API are :ref:`listed below <stable-abi-list>`.
32-
33-
To enable this, Python provides a *Stable ABI*: a set of symbols that will
34-
remain compatible across Python 3.x versions. The Stable ABI contains symbols
35-
exposed in the Limited API, but also other ones – for example, functions
36-
necessary to support older versions of the Limited API.
37-
38-
(For simplicity, this document talks about *extensions*, but the Limited API
39-
and Stable ABI work the same way for all uses of the API – for example,
40-
embedding Python.)
40+
Contents of the Limited API are :ref:`listed below <limited-api-list>`.
4141

4242
.. c:macro:: Py_LIMITED_API
4343
@@ -57,6 +57,19 @@ embedding Python.)
5757
You can also define ``Py_LIMITED_API`` to ``3``. This works the same as
5858
``0x03020000`` (Python 3.2, the version that introduced Limited API).
5959

60+
61+
.. _stable-abi:
62+
63+
Stable ABI
64+
----------
65+
66+
To enable this, Python provides a *Stable ABI*: a set of symbols that will
67+
remain compatible across Python 3.x versions.
68+
69+
The Stable ABI contains symbols exposed in the :ref:`Limited API
70+
<limited-c-api>`, but also other ones – for example, functions necessary to
71+
support older versions of the Limited API.
72+
6073
On Windows, extensions that use the Stable ABI should be linked against
6174
``python3.dll`` rather than a version-specific library such as
6275
``python39.dll``.
@@ -101,9 +114,9 @@ Limited API Caveats
101114
-------------------
102115

103116
Note that compiling with ``Py_LIMITED_API`` is *not* a complete guarantee that
104-
code conforms to the Limited API or the Stable ABI. ``Py_LIMITED_API`` only
105-
covers definitions, but an API also includes other issues, such as expected
106-
semantics.
117+
code conforms to the :ref:`Limited API <limited-c-api>` or the :ref:`Stable ABI
118+
<stable-abi>`. ``Py_LIMITED_API`` only covers definitions, but an API also
119+
includes other issues, such as expected semantics.
107120

108121
One issue that ``Py_LIMITED_API`` does not guard against is calling a function
109122
with arguments that are invalid in a lower Python version.
@@ -136,9 +149,9 @@ Platform Considerations
136149
=======================
137150

138151
ABI stability depends not only on Python, but also on the compiler used,
139-
lower-level libraries and compiler options. For the purposes of the Stable ABI,
140-
these details define a “platform”. They usually depend on the OS
141-
type and processor architecture
152+
lower-level libraries and compiler options. For the purposes of
153+
the :ref:`Stable ABI <stable-abi>`, these details define a “platform”. They
154+
usually depend on the OS type and processor architecture
142155

143156
It is the responsibility of each particular distributor of Python
144157
to ensure that all Python versions on a particular platform are built
@@ -147,12 +160,12 @@ This is the case with Windows and macOS releases from ``python.org`` and many
147160
third-party distributors.
148161

149162

150-
.. _stable-abi-list:
163+
.. _limited-api-list:
151164

152165
Contents of Limited API
153166
=======================
154167

155168

156-
Currently, the Limited API includes the following items:
169+
Currently, the :ref:`Limited API <limited-c-api>` includes the following items:
157170

158171
.. limited-api-list::

Doc/c-api/structures.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ There are these calling conventions:
318318
319319
.. versionchanged:: 3.10
320320
321-
``METH_FASTCALL`` is now part of the stable ABI.
321+
``METH_FASTCALL`` is now part of the :ref:`stable ABI <stable-abi>`.
322322
323323
324324
.. _METH_FASTCALL-METH_KEYWORDS:

Doc/c-api/type.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Type Objects
4242
Return the :c:member:`~PyTypeObject.tp_flags` member of *type*. This function is primarily
4343
meant for use with ``Py_LIMITED_API``; the individual flag bits are
4444
guaranteed to be stable across Python releases, but access to
45-
:c:member:`~PyTypeObject.tp_flags` itself is not part of the limited API.
45+
:c:member:`~PyTypeObject.tp_flags` itself is not part of the :ref:`limited API <limited-c-api>`.
4646
4747
.. versionadded:: 3.2
4848
@@ -301,7 +301,7 @@ The following functions and structs are used to create
301301
.. versionchanged:: 3.11
302302
:c:member:`~PyBufferProcs.bf_getbuffer` and
303303
:c:member:`~PyBufferProcs.bf_releasebuffer` are now available
304-
under the limited API.
304+
under the :ref:`limited API <limited-c-api>`.
305305
306306
.. c:member:: void *PyType_Slot.pfunc
307307

Doc/c-api/typeobj.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ This results in types that are limited relative to types defined in Python:
20822082
include any subinterpreter-specific state.
20832083

20842084
Also, since :c:type:`PyTypeObject` is only part of the :ref:`Limited API
2085-
<stable>` as an opaque struct, any extension modules using static types must be
2085+
<limited-c-api>` as an opaque struct, any extension modules using static types must be
20862086
compiled for a specific Python minor version.
20872087

20882088

Doc/c-api/unicode.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ These are the UTF-8 codec APIs:
10841084
The return type is now ``const char *`` rather of ``char *``.
10851085
10861086
.. versionchanged:: 3.10
1087-
This function is a part of the :ref:`limited API <stable>`.
1087+
This function is a part of the :ref:`limited API <limited-c-api>`.
10881088
10891089
10901090
.. c:function:: const char* PyUnicode_AsUTF8(PyObject *unicode)

Doc/howto/isolating-extensions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Module State Access from Slot Methods, Getters and Setters
461461

462462
.. After adding to limited API:
463463
464-
If you use the :ref:`limited API <stable>,
464+
If you use the :ref:`limited API <limited-c-api>`,
465465
you must update ``Py_LIMITED_API`` to ``0x030b0000``, losing ABI
466466
compatibility with earlier versions.
467467

Doc/library/test.rst

+6
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ The :mod:`test.support` module defines the following functions:
740740
Decorator for only running the test if :data:`HAVE_DOCSTRINGS`.
741741

742742

743+
.. decorator:: requires_limited_api
744+
745+
Decorator for only running the test if :ref:`Limited C API <limited-c-api>`
746+
is available.
747+
748+
743749
.. decorator:: cpython_only
744750

745751
Decorator for tests only applicable to CPython.

Doc/whatsnew/3.11.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ Removed
26542654
* :c:func:`PyMarshal_WriteObjectToString`
26552655
* the ``Py_MARSHAL_VERSION`` macro
26562656

2657-
These are not part of the :ref:`limited API <stable-abi-list>`.
2657+
These are not part of the :ref:`limited API <limited-api-list>`.
26582658

26592659
(Contributed by Victor Stinner in :issue:`45474`.)
26602660

Lib/test/test_stable_abi_ctypes.py

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/NEWS.d/3.11.0a1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4980,7 +4980,7 @@ Removed documentation for the removed ``PyParser_*`` C API.
49804980
.. nonce: fy0AXK
49814981
.. section: C API
49824982
4983-
The list in :ref:`stable-abi-list` now shows the public name
4983+
The list in :ref:`limited-api-list` now shows the public name
49844984
:c:struct:`PyFrameObject` rather than ``_frame``. The non-existing entry
49854985
``_node`` no longer appears in the list.
49864986

Misc/NEWS.d/3.11.0a2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ defined:
12341234
* :c:func:`PyMarshal_WriteObjectToString`
12351235
* the ``Py_MARSHAL_VERSION`` macro
12361236

1237-
These are not part of the :ref:`limited API <stable-abi-list>`.
1237+
These are not part of the :ref:`limited API <limited-api-list>`.
12381238

12391239
Patch by Victor Stinner.
12401240

Modules/_testcapi_feature_macros.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated by Tools/scripts/stable_abi.py
1+
// Generated by Tools/build/stable_abi.py
22

33
// Add an entry in dict `result` for each Stable ABI feature macro.
44

PC/python3dll.c

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/scripts/stable_abi.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _decorator(func):
183183
def gen_python3dll(manifest, args, outfile):
184184
"""Generate/check the source for the Windows stable ABI library"""
185185
write = partial(print, file=outfile)
186-
write(textwrap.dedent(r"""
186+
write(textwrap.dedent(r"""\
187187
/* Re-export stable Python ABI */
188188
189189
/* Generated by Tools/scripts/stable_abi.py */
@@ -265,8 +265,8 @@ def gen_doc_annotations(manifest, args, outfile):
265265
def gen_ctypes_test(manifest, args, outfile):
266266
"""Generate/check the ctypes-based test for exported symbols"""
267267
write = partial(print, file=outfile)
268-
write(textwrap.dedent('''
269-
# Generated by Tools/scripts/stable_abi.py
268+
write(textwrap.dedent(f'''\
269+
# Generated by {SCRIPT_NAME}
270270
271271
"""Test that all symbols of the Stable ABI are accessible using ctypes
272272
"""
@@ -339,7 +339,7 @@ def test_windows_feature_macros(self):
339339
def gen_testcapi_feature_macros(manifest, args, outfile):
340340
"""Generate/check the stable ABI list for documentation annotations"""
341341
write = partial(print, file=outfile)
342-
write('// Generated by Tools/scripts/stable_abi.py')
342+
write(f'// Generated by {SCRIPT_NAME}')
343343
write()
344344
write('// Add an entry in dict `result` for each Stable ABI feature macro.')
345345
write()

0 commit comments

Comments
 (0)