@@ -101,8 +101,44 @@ No changes that break the Stable ABI are allowed.
101
101
The Limited API should be defined in ``Include/ ``, excluding the
102
102
``cpython `` and ``internal `` subdirectories.
103
103
104
- Guidelines for changing the Limited API
105
- ---------------------------------------
104
+
105
+ Guidelines for changing the Limited API, and removing items from it
106
+ -------------------------------------------------------------------
107
+
108
+ While the *Stable ABI * must not be broken, the existing Limited API can be
109
+ changed, and items can be removed from it, if:
110
+
111
+ - the Backwards Compatibility Policy (:pep: `387 `) is followed, and
112
+ - the Stable ABI is not broken -- that is, extensions compiled with
113
+ Limited API of older versions of Python continue to work on
114
+ newer versions of Python.
115
+
116
+ This is tricky to do and requires careful thought.
117
+ Some examples:
118
+
119
+ - Functions, structs etc. accessed by macros in *any version * of the
120
+ Limited API are part of the Stable ABI, even if they are named with
121
+ an underscore. They must not be removed and their signature must not change.
122
+ (Their implementation may change, though.)
123
+ - Structs members cannot be rearranged if they were part of any version of
124
+ the Limited API.
125
+ - If the Limited API allows users to allocate a struct directly,
126
+ its size must not change.
127
+ - Exported symbols (functions and data) must continue to be available
128
+ as exported symbols. Specifically, a function can only be converted
129
+ to a ``static inline `` function (or macro) if Python also continues to
130
+ provide the actual function.
131
+ For an example, see the ``Py_NewRef `` `macro `_ and `redefinition `_ in 3.10.
132
+
133
+ .. _macro : https://github.com/python/cpython/blob/v3.10.1/Include/object.h#L591-L595
134
+ .. _redefinition : https://github.com/python/cpython/blob/v3.10.1/Objects/object.c#L2298-L2308
135
+
136
+ It is possible to remove items marked as part of the Stable ABI, but only
137
+ if there was no way to use them in any past version of the Limited API.
138
+
139
+
140
+ Guidelines for adding to the Limited API
141
+ ----------------------------------------
106
142
107
143
- Guidelines for the general :ref: `public-capi ` apply.
108
144
0 commit comments