I propose adding support for the limited C API to Argument Clinic. Since Argument Clinic supports a wide diversity of parameter types and object types, I propose to add the support incrementally (step by step).
The final goal is to restrict some stdlib C extensions to the limited C API.
My change added support for limited C API version 3.13. If we consider supporting older Python versions, this issue should be carefully reviewed: #71686 "PY_SSIZE_T_CLEAN conflicts with Py_LIMITED_API". Maybe it has been fixed in the meanwhile, I'm not sure. The goal here would be to be able build a C extension with Python 3.13 which works on Python 3.2 to 3.12.
METH_FASTCALL is the part of the stable ABI in #23009.
I don't in which Python version it was usable as part of the stable ABI. My current implementation is limited to METH_VARARGS and METH_VARARGS | METH_KEYWORDS to focus on backward compatibility first.
Thanks to @serhiy-storchaka, Argument Clinic now supports all formats for the limited C API. I'm sure that we will find code which doesn't work and room for improvement. It can be done later. I close the issue. Thanks to everybody who helped me to make it possible :-)
Activity
pythongh-108494: Argument Clinic partial supports of Limited C API
gh-108494: Argument Clinic partial supports of Limited C API (#108495)
vstinner commented on Aug 25, 2023
My first change adds this code to build _testclinic_limited.c with the limited C API:
# XXX Temporary solution if os.path.basename(filename) == '_testclinic_limited.c': print(f"{filename} uses limited C API") limited_capi = TrueMaybe we could add a marker using Argument Clinic syntax to announce "hey, I want the limited C API"!
Or AC could parse the C code and look for #define Py_LIMITED_API?
pythongh-108494: AC supports pos-only args in limited C API
pythongh-108494: AC supports pos-only args in limited C API
vstinner commented on Aug 25, 2023
My change added support for limited C API version 3.13. If we consider supporting older Python versions, this issue should be carefully reviewed: #71686 "PY_SSIZE_T_CLEAN conflicts with Py_LIMITED_API". Maybe it has been fixed in the meanwhile, I'm not sure. The goal here would be to be able build a C extension with Python 3.13 which works on Python 3.2 to 3.12.
vstinner commented on Aug 25, 2023
Something else to consider, @shihai1991 wrote:
I don't in which Python version it was usable as part of the stable ABI. My current implementation is limited to METH_VARARGS and METH_VARARGS | METH_KEYWORDS to focus on backward compatibility first.
vstinner commented on Aug 25, 2023
Well, see issue #85283 for the interesting discussion in 2020-2021.
gh-108494: AC supports pos-only args in limited C API (#108498)
vstinner commented on Aug 25, 2023
I implemented that in my second PR, see LIMITED_CAPI_REGEX.
pythongh-108494: AC: change parse_file() API
pythongh-108494: AC: change parse_file() API
pythongh-108494: Fix AC limited C API for kwargs
30 remaining items
pythongh-108494: Document how to add a project in PCbuild/readme.txt (p…
pythongh-108494: Document how to add a project in PCbuild/readme.txt (p…
pythongh-108494: Document how to add a project in PCbuild/readme.txt (p…
[3.11] gh-108494: Document how to add a project in PCbuild/readme.txt (…
[3.12] gh-108494: Document how to add a project in PCbuild/readme.txt (…
vstinner commented on Oct 17, 2023
Thanks to @serhiy-storchaka, Argument Clinic now supports all formats for the limited C API. I'm sure that we will find code which doesn't work and room for improvement. It can be done later. I close the issue. Thanks to everybody who helped me to make it possible :-)
vstinner commented on Oct 17, 2023
Follow-up: PR #110964 "[C API] Move undocumented private _PyArg C API to pycore_modsupport.h internal C API".
pythongh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX
pythongh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX
pythongh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX
gh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX (#116610)
pythongh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX (python#116610)
pythongh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX (python#116610)
pythongh-108494: Document how to add a project in PCbuild/readme.txt (p…