GeezerVison is showing github.com — Support the limited API? · Issue #183 · python/pythoncapi-compat
Support the limited API? #183Description
|
#ifdef Py_LIMITED_API |
|
# error "Py_LIMITED_API is not supported" |
|
#endif |
seems to indicate that adding shims for the limited API is currently out of scope for the project.
I'm curious if there's any interest in adding support here. I'd particularly like to avoid adding extensive shims to NumPy to work around issues like in numpy/numpy#32864. Activityadded 2 commits that reference this issue on Oct 4, 2026This issue will close once commit 51310e1 is merged into the 'main' branch.51310e1 This issue will close once commit 7aefdb2 is merged into the 'main' branch.7aefdb2 vstinner commented on Oct 4, 2026 I wrote #184 to add support for the limited C API. added a commit that references this issue on Oct 5, 2026This issue will close once commit cb1eadf is merged into the 'main' branch.cb1eadf vstinner commented on Oct 5, 2026 It's now implemented in the main branch. vstinner commented on Oct 7, 2026 @ngoldbaum: I just merged Py_SETREF()/Py_XSETREF() into Python 3.16: python/cpython@ec14f81. Do you expect that pythoncapi-compat provides new limited C API functions to older Python versions? It sounds somehow to go against limited C API, no? I expect Py_SETREF()/Py_XSETREF() to be only available in Python 3.16 limited C API, even if pythoncapi-compat. Well, I'm not sure. What do you think? ngoldbaum commented on Oct 7, 2026 ContributorAuthor More actions
It sounds someone to go against limited C API, no?
I think it goes with the intention of this repo, which allows people to adopt idioms that are added in future Python versions. It's a bad idea to use those idioms if it hasn't been added in a future version but once it has, it makes sense to use internal details to implement backward compatibility shims.
Of course that may be difficult in practice for most things in the limited API because it will require new ABI surface. In this case, though, we can provide a shim. So I would say why not allow that?
Without support here, NumPy would add a shim somewhere internally in NumPy that only NumPy uses and may be buggy. IMO it's better to centralize compat shims here as much as possible. vstinner commented on Oct 7, 2026 @ngoldbaum: Hum. Supporting the limited C API on old Python versions is tricky to get it right, because of the stable ABI. I suggest to work on a case by case basis to add new limited C API to old Python versions. Py_SETREF() / Py_XSETREF() is special since it doesn't call (new) Python functions in its implementation, but only memcpy() which comes from the C library. So for these two macros, I think that it's safe to add them to old Python versions.
I created #187 to add Py_SETREF/Py_XSETREF to old limited C API versions.
Three years ago, I created https://github.com/vstinner/deadparrot experimental project: a shared library providing old and new Python C API functions to support all Python versions. But I didn't go far, and no one adopted it. The pythoncapi-compat "header file" approach seems to fit well developers needs and it's convenient to use (just include the header file, you're done).
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|