Skip to content

Commit c1d7fef

Browse files
committed
Manifest, annotations
1 parent 8e203eb commit c1d7fef

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

Doc/c-api/module.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,11 @@ remove it.
685685
Usually, there is only one variable of this type for each extension module
686686
defined this way.
687687
688+
In the :ref:`Stable ABI <stable-abi>` for Free-Threaded Builds (``abi3t``),
689+
this struct is opaque, and unusable in practice.
690+
The struct, including all members, is part of Stable ABI for
691+
non-free-threaded builds (``abi3``).
692+
688693
.. c:member:: PyModuleDef_Base m_base
689694
690695
Always initialize this member to :c:macro:`PyModuleDef_HEAD_INIT`:
@@ -695,6 +700,11 @@ remove it.
695700
696701
The type of :c:member:`!PyModuleDef.m_base`.
697702
703+
In the :ref:`Stable ABI <stable-abi>` for Free-Threaded Builds
704+
(``abi3t``), this struct is opaque, and unusable in practice.
705+
The struct is part of Stable ABI for
706+
non-free-threaded builds (``abi3``).
707+
698708
.. c:macro:: PyModuleDef_HEAD_INIT
699709
700710
The required initial value for :c:member:`!PyModuleDef.m_base`.

Doc/c-api/structures.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ under :ref:`reference counting <countingrefs>`.
3333
The members must not be accessed directly; instead use macros such as
3434
:c:macro:`Py_REFCNT` and :c:macro:`Py_TYPE`.
3535

36+
In the :ref:`Stable ABI <stable-abi>` for Free-Threaded Builds (``abi3t``),
37+
this struct is opaque; its size and layout may change between
38+
Python versions.
39+
In Stable ABI for non-free-threaded builds (``abi3``), the
40+
:c:member:`!ob_refcnt` and :c:member:`!ob_type` fields are available,
41+
but using them directly is discouraged.
42+
3643
.. c:member:: Py_ssize_t ob_refcnt
3744
3845
The object's reference count, as returned by :c:macro:`Py_REFCNT`.
@@ -72,6 +79,19 @@ under :ref:`reference counting <countingrefs>`.
7279
instead use macros such as :c:macro:`Py_SIZE`, :c:macro:`Py_REFCNT` and
7380
:c:macro:`Py_TYPE`.
7481

82+
In the :ref:`Stable ABI <stable-abi>` for Free-Threaded Builds (``abi3t``),
83+
this struct is opaque; its size and layout may change between
84+
Python versions.
85+
In Stable ABI for non-free-threaded builds (``abi3``), the
86+
:c:member:`!ob_base` and :c:member:`!ob_size` fields are available,
87+
but using them directly is discouraged.
88+
89+
.. c:member:: PyObject ob_base
90+
91+
Common object header.
92+
Typically, this field is not accessed directly; instead
93+
:c:type:`!PyVarObject` can be cast to :c:type:`PyObject`.
94+
7595
.. c:member:: Py_ssize_t ob_size
7696
7797
A size field, whose contents should be considered an object's internal

Doc/data/stable_abi.dat

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/tools/extensions/c_annotations.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,17 @@ def _stable_abi_annotation(
249249
reftype="ref",
250250
refexplicit="False",
251251
)
252-
struct_abi_kind = record.struct_abi_kind
253-
if struct_abi_kind in {"opaque", "members"}:
254-
ref_node += nodes.Text(sphinx_gettext("Limited API"))
255-
else:
256-
ref_node += nodes.Text(sphinx_gettext("Stable ABI"))
252+
ref_node += nodes.Text(sphinx_gettext("Stable ABI"))
257253
emph_node += ref_node
254+
struct_abi_kind = record.struct_abi_kind
258255
if struct_abi_kind == "opaque":
259256
emph_node += nodes.Text(" " + sphinx_gettext("(as an opaque struct)"))
260257
elif struct_abi_kind == "full-abi":
261258
emph_node += nodes.Text(
262259
" " + sphinx_gettext("(including all members)")
263260
)
261+
elif struct_abi_kind in {"members", "abi3t-opaque"}:
262+
emph_node += nodes.Text(" " + sphinx_gettext("(see below)"))
264263
if record.ifdef_note:
265264
emph_node += nodes.Text(f" {record.ifdef_note}")
266265
if stable_added == "3.2":
@@ -271,11 +270,7 @@ def _stable_abi_annotation(
271270
" " + sphinx_gettext("since version %s") % stable_added
272271
)
273272
emph_node += nodes.Text(".")
274-
if struct_abi_kind == "members":
275-
msg = " " + sphinx_gettext(
276-
"(Only some members are part of the stable ABI.)"
277-
)
278-
emph_node += nodes.Text(msg)
273+
279274
return emph_node
280275

281276

Misc/stable_abi.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file lists the contents of the Limited API and Stable ABI.
1+
# This file lists the contents of Limited API and Stable ABI.
22
# Please append new items at the end.
33

44
# The syntax of this file is not fixed.
@@ -46,15 +46,24 @@
4646
# - 'opaque': No members are part of the ABI, nor is the size. The Limited
4747
# API only handles these via pointers. The C definition should be
4848
# incomplete (opaque).
49-
# - 'members': Only specific members are part of the stable ABI.
50-
# The struct's size may change, so it can't be used in arrays.
49+
# - 'abi3t-opaque': 'full-abi' in abi3; 'opaque' in abi3t.
50+
# For docs, the generated annotation refers to details that need to
51+
# be added to the ReST file manually.
52+
# - 'members':
53+
# - 'opaque' in abi3t.
54+
# - In abi3, only specific members are part of the stable ABI.
55+
# The struct's size may change, so it can't be used in arrays.
5156
# Do not add new structs of this kind without an extremely good reason.
57+
# For docs, the generated annotation refers to details that need to
58+
# be added to the ReST file manually.
5259
# - members: For `struct` with struct_abi_kind = 'members', a list of the
5360
# exposed members.
5461
# - doc: for `feature_macro`, the blurb added in documentation
5562
# - windows: for `feature_macro`, this macro is defined on Windows.
5663
# (This info is used to generate the DLL manifest and needs to be available
5764
# on all platforms.)
65+
# - abi3t_opaque: In abi3t, this struct is opaque (as if `struct_abi_kind`
66+
# was 'opaque' and `members` was missing).
5867

5968
# Removing items from this file is generally not allowed, and additions should
6069
# be considered with that in mind. See the devguide for exact rules:
@@ -107,10 +116,10 @@
107116
struct_abi_kind = 'full-abi'
108117
[struct.PyModuleDef_Base]
109118
added = '3.2'
110-
struct_abi_kind = 'full-abi'
119+
struct_abi_kind = 'abi3t-opaque'
111120
[struct.PyModuleDef]
112121
added = '3.2'
113-
struct_abi_kind = 'full-abi'
122+
struct_abi_kind = 'abi3t-opaque'
114123
[struct.PyStructSequence_Field]
115124
added = '3.2'
116125
struct_abi_kind = 'full-abi'

0 commit comments

Comments
 (0)