You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7aefdb2
Browse filesBrowse the repository at this point in the historyBrowse files
Add support for the limited C API (Py_LIMITED_API)
Examples of API not available in the limited C API:
* PyBytesWriter
* PyConfig_Get(), PyConfig_GetInt().
* PyDict_ContainsString().
* PyFrame_GetBack(), PyFrame_GetVar()
* PyLongWriter_Create() and PyLong_Export()
* PyObject_VisitManagedDict(), PyObject_ClearManagedDict()
* PyThreadState_GetUnchecked()
* PyTime_t API.
* PyUnicodeWriter
* PyUnstable_SetImmortal().
* Py_SETREF(), Py_XSETREF().
Implementation notes:
* PyUnicode_EqualToUTF8AndSize() has no ASCII fast path.
* PyLong_GetSign(), PyLong_IsPositive(), PyLong_IsNegative() and
PyLong_IsZero() are implemented with PyObject_RichCompareBool().
* PyBytes_Join() calls PyObject_CallMethod(sep, "join", iterable).
* Add PYTHONCAPI_COMPAT_EXPECT_TYPE() macro to raise TypeError.
There are 3 implementations depending on the API and Python
version.
test_pythoncapi_compat.py now reuses the setup module to list tests.
Closespython#183
Copy file name to clipboardExpand all lines: docs/api.rst
+82-7Lines changed: 82 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,8 @@ Python 3.15
40
40
41
41
See `PyBytesWriter documentation <https://docs.python.org/dev/c-api/bytes.html#pybyteswriter>`__.
See `PySys_GetAttr() documentation <https://docs.python.org/dev/c-api/sys.html#c.PySys_GetAttr>`__.
@@ -60,17 +62,22 @@ Python 3.15
60
62
61
63
See `PyTuple_FromArray() documentation <https://docs.python.org/dev/c-api/tuple.html#c.PyTuple_FromArray>`__.
See `PyUnstable_Unicode_GET_CACHED_HASH() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnstable_Unicode_GET_CACHED_HASH>`__.
66
70
67
71
On PyPy, always returns ``-1``.
68
72
73
+
Not available with the limited C API.
74
+
69
75
.. c:function:: int PyUnstable_SetImmortal(PyObject *op)
70
76
71
77
See `PyUnstable_SetImmortal() documentation <https://docs.python.org/dev/c-api/object.html#c.PyUnstable_SetImmortal>`__.
72
78
73
-
Availability: Python 3.13 and newer, not available on PyPy.
79
+
Availability: Python 3.13 and newer, not available on PyPy, not available
80
+
with the limited C API.
74
81
75
82
Python 3.14
76
83
-----------
@@ -79,38 +86,56 @@ Python 3.14
79
86
80
87
See `PyLongLayout documentation <https://docs.python.org/dev/c-api/long.html#c.PyLongLayout>`__.
See `PyLong_GetNativeLayout() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLong_GetNativeLayout>`__.
85
94
95
+
Not available with the limited C API.
96
+
86
97
.. c:struct:: PyLongExport
87
98
88
99
See `PyLongExport documentation <https://docs.python.org/dev/c-api/long.html#c.PyLongExport>`__.
89
100
101
+
Not available with the limited C API.
102
+
90
103
.. c:function:: int PyLong_Export(PyObject *obj, PyLongExport *export_long)
91
104
92
105
See `PyLong_Export() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLong_Export>`__.
See `PyLong_FreeExport() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLong_FreeExport>`__.
97
112
113
+
Not available with the limited C API.
114
+
98
115
.. c:struct:: PyLongWriter
99
116
100
117
See `PyLongWriter documentation <https://docs.python.org/dev/c-api/long.html#c.PyLongWriter>`__.
See `PyLongWriter_Create() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLongWriter_Create>`__.
See `PyLongWriter_Finish() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLongWriter_Finish>`__.
See `PyLongWriter_Discard() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLongWriter_Discard>`__.
113
136
137
+
Not available with the limited C API.
138
+
114
139
.. c:function:: int PyLong_IsPositive(PyObject *obj)
115
140
116
141
See `PyLong_IsPositive() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLong_IsPositive>`__.
@@ -147,46 +172,68 @@ Python 3.14
147
172
148
173
See `PyUnicodeWriter_Create() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_Create>`__.
See `PyUnicodeWriter_Finish() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_Finish>`__.
See `PyUnicodeWriter_Discard() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_Discard>`__.
157
186
187
+
Not available with the limited C API.
188
+
158
189
.. c:function:: int PyUnicodeWriter_WriteChar(PyUnicodeWriter *writer, Py_UCS4 ch)
159
190
160
191
See `PyUnicodeWriter_WriteChar() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteChar>`__.
161
192
193
+
Not available with the limited C API.
194
+
162
195
.. c:function:: int PyUnicodeWriter_WriteUTF8(PyUnicodeWriter *writer, const char *str, Py_ssize_t size)
163
196
164
197
See `PyUnicodeWriter_WriteUTF8() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteUTF8>`__.
165
198
199
+
Not available with the limited C API.
200
+
166
201
.. c:function:: int PyUnicodeWriter_WriteASCII(PyUnicodeWriter *writer, const char *str, Py_ssize_t size)
167
202
168
203
See `PyUnicodeWriter_WriteASCII() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteASCII>`__.
169
204
205
+
Not available with the limited C API.
206
+
170
207
.. c:function:: int PyUnicodeWriter_WriteWideChar(PyUnicodeWriter *writer, const wchar_t *str, Py_ssize_t size)
171
208
172
209
See `PyUnicodeWriter_WriteWideChar() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteWideChar>`__.
173
210
211
+
Not available with the limited C API.
212
+
174
213
.. c:function:: int PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
175
214
176
215
See `PyUnicodeWriter_WriteStr() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteStr>`__.
177
216
217
+
Not available with the limited C API.
218
+
178
219
.. c:function:: int PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
179
220
180
221
See `PyUnicodeWriter_WriteRepr() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteRepr>`__.
See `PyUnicodeWriter_WriteSubstring() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteSubstring>`__.
185
228
229
+
Not available with the limited C API.
230
+
186
231
.. c:function:: int PyUnicodeWriter_Format(PyUnicodeWriter *writer, const char *format, ...)
187
232
188
233
See `PyUnicodeWriter_Format() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_Format>`__.
189
234
235
+
Not available with the limited C API.
236
+
190
237
.. c:function:: int PyLong_AsInt32(PyObject *obj, int32_t *pvalue)
191
238
192
239
See `PyLong_AsInt32() documentation <https://docs.python.org/dev/c-api/long.html#c.PyLong_AsInt32>`__.
@@ -231,16 +278,22 @@ Python 3.14
231
278
232
279
See `PyConfig_Get() documentation <https://docs.python.org/dev/c-api/init_config.html#c.PyConfig_Get>`__.
233
280
281
+
Not available with the limited C API.
282
+
234
283
.. c:function:: int PyConfig_GetInt(const char *name, int *value)
235
284
236
285
See `PyConfig_GetInt() documentation <https://docs.python.org/dev/c-api/init_config.html#c.PyConfig_GetInt>`__.
237
286
287
+
Not available with the limited C API.
288
+
238
289
.. c:function:: int PyUnstable_Object_IsUniquelyReferenced(PyObject *op)
239
290
240
291
See `PyUnstable_Object_IsUniquelyReferenced() documentation <https://docs.python.org/dev/c-api/object.html#c.PyUnstable_Object_IsUniquelyReferenced>`__.
241
292
242
293
Not available on PyPy. ``Py_REFCNT()`` semantics is different on PyPy.
243
294
295
+
Not available with the limited C API.
296
+
244
297
.. c:function:: int PyUnstable_TryIncRef(PyObject *op)
245
298
246
299
See `PyUnstable_TryIncRef() documentation <https://docs.python.org/dev/c-api/object.html#c.PyUnstable_TryIncRef>`__.
@@ -336,7 +389,7 @@ Python 3.13
336
389
Return non-zero if the Python interpreter is shutting down, return 0
337
390
otherwise.
338
391
339
-
Availability: Python 3.3 and newer, PyPy 7.3 and newer.
392
+
Availability: Python 3.3 and newer, PyPy 7.3 and newer, limited C API 3.13.
340
393
341
394
See `Py_IsFinalizing() documentation <https://docs.python.org/dev/c-api/init.html#c.Py_IsFinalizing>`__.
342
395
@@ -352,15 +405,19 @@ Python 3.13
352
405
353
406
See `PyObject_VisitManagedDict() documentation <https://docs.python.org/dev/c-api/object.html#c.PyObject_VisitManagedDict>`__.
See `PyObject_ClearManagedDict() documentation <https://docs.python.org/dev/c-api/object.html#c.PyObject_ClearManagedDict>`__.
See `PyThreadState_GetUnchecked() documentation <https://docs.python.org/dev/c-api/init.html#c.PyThreadState_GetUnchecked>`__.
362
419
363
-
Available on Python 3.5.2 and newer.
420
+
Available on Python 3.5.2 and newer. Not available with the limited C API.
364
421
365
422
.. c:function:: int PyUnicode_EqualToUTF8(PyObject *unicode, const char *str)
366
423
@@ -390,35 +447,51 @@ Python 3.13
390
447
391
448
See `Py_HashPointer() documentation <https://docs.python.org/dev/c-api/hash.html#c.Py_HashPointer>`__.
392
449
450
+
Not available with the limited C API.
451
+
393
452
.. c:type:: PyTime_t
394
453
395
454
A timestamp or duration in nanoseconds, represented as a signed 64-bit
See `PyTime_AsSecondsDouble() documentation <https://docs.python.org/dev/c-api/time.html#c.PyTime_AsSecondsDouble>`__.
409
474
475
+
Not available with the limited C API.
476
+
410
477
.. c:function:: int PyTime_Monotonic(PyTime_t *result)
411
478
412
479
See `PyTime_Monotonic() documentation <https://docs.python.org/dev/c-api/time.html#c.PyTime_Monotonic>`__.
413
480
481
+
Not available with the limited C API.
482
+
414
483
.. c:function:: int PyTime_Time(PyTime_t *result)
415
484
416
485
See `PyTime_Time() documentation <https://docs.python.org/dev/c-api/time.html#c.PyTime_Time>`__.
417
486
487
+
Not available with the limited C API.
488
+
418
489
.. c:function:: int PyTime_PerfCounter(PyTime_t *result)
419
490
420
491
See `PyTime_PerfCounter() documentation <https://docs.python.org/dev/c-api/time.html#c.PyTime_PerfCounter>`__.
See `PyList_GetItemRef() documentation <https://docs.python.org/dev/c-api/list.html#c.PyList_GetItemRef>`__.
@@ -447,13 +520,13 @@ Python 3.12
447
520
448
521
See `PyFrame_GetVar() documentation <https://docs.python.org/dev/c-api/frame.html#c.PyFrame_GetVar>`__.
See `PyFrame_GetVarString() documentation <https://docs.python.org/dev/c-api/frame.html#c.PyFrame_GetVarString>`__.
455
528
456
-
Not available on PyPy.
529
+
Not available on PyPy nor with the limited C API.
457
530
458
531
.. c:function:: PyObject* Py_GetConstant(unsigned int constant_id)
459
532
@@ -689,7 +762,7 @@ PyFrameObject
689
762
690
763
See `PyFrame_GetBack() documentation <https://docs.python.org/dev/c-api/reflection.html#c.PyFrame_GetBack>`__.
0 commit comments