Repository navigation
Add support for the limited C API (Py_LIMITED_API) - #184
Conversation
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. Closes python#183
Cleanup test selection in setup.py.
PyObject_GC_IsTracked() and PyObject_GC_IsFinalized() are only added to limited C API 3.10 on Windows.
Tests fails on Windows with Python 3.15: "unresolved external symbol PyInit_test_pythoncapi_compat_cext_c11".
|
@ngoldbaum: Here is a large change to add support for the limited C API in pythoncapi-compat. Do you think that you would be able to test it in numpy? Like create a draft numpy PR updating pythoncapi-compat and check if the CI pass? |
|
ping @prathamhole14 can you take on Victor's request above? |
|
Note: this PR doesn't add Py_SETREF / Py_XSETREF to the limited C API. My plan is first to add these macros the limited C API in Python 3.16: capi-workgroup/decisions#110. Then merge this PR. And finally, add these macros to pythoncapi-compat. |
Yes, here is the PR to test numpy/numpy#32871 |
The CI says "92 successful checks". So it means that there is no big red warning from numpy side at least? (I would just like a confirmation :-)) |
|
Ok, I merged my PR. If there are bugs, well, we can fix them as usual :-) |
|
Follow-up to test limited C API on Python 3.15 on Windows: #185. |
Yes, in numpy LIMITED API build is tested in debug mode since everything is green there is nothing to worry about! Thanks. |
Examples of API not available in the limited C API:
Implementation notes:
test_pythoncapi_compat.py now reuses the setup module to list tests.
Closes #183