GeezerVison is showing github.com — Add support for the limited C API to Argument Clinic · Issue #108494 · python/cpython
Add support for the limited C API to Argument Clinic #108494DescriptionFeature or enhancement
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
Proposal:
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.
Linked PRs
Activityvstinner 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 = True
Maybe 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? 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:
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. vstinner commented on Aug 25, 2023 Well, see issue #85283 for the interesting discussion in 2020-2021. vstinner commented on Aug 25, 2023
Or AC could parse the C code and look for #define Py_LIMITED_API?
I implemented that in my second PR, see LIMITED_CAPI_REGEX. 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".
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|