Repository navigation
build: target the Python 3.11 limited API - #898
Merged
Merged
Conversation
Python 3.9 and 3.10 are no longer supported, so there is no reason to restrict the extension to the 3.9 limited API. Set Py_LIMITED_API to 3.11 and tag abi3 wheels as cp311-abi3. This makes the limited API functions added in 3.10 and 3.11 available to the extension. Assisted-by: Claude Opus 5.5
With Py_LIMITED_API set to 3.11 or later, Python.h no longer includes <errno.h>, <stdio.h>, <stdlib.h> and <string.h>, and Py_TYPE(), Py_INCREF() and friends are functions taking PyObject* instead of macros that cast their argument. Newer GCC versions reject both as errors. MSVC only warns, but the implicitly declared strdup() returns int, which truncates the pointer on 64-bit Windows and crashes as soon as a string argument is converted. Include the standard headers in preamble.h and cast object pointers to PyObject* where they are passed to these functions. Assisted-by: Claude Opus 5.5
Python requires Python.h to be included before standard headers, because pyconfig.h sets feature test macros such as _POSIX_C_SOURCE. convert.c and common.h included <limits.h>, <ctype.h> and <stdbool.h> first, which makes the Python 3.15 headers warn about _POSIX_C_SOURCE being redefined. Also include <stddef.h> explicitly in preamble.h, since Python.h no longer includes it with the 3.13 or later limited API and offsetof() is used for member definitions. With this, the extension compiles cleanly against the limited API of every version from 3.11 up to 3.15. Assisted-by: Claude Opus 5.5
Member
|
PyObject_GetBuffer() is the real gain here and I've been waiting for that for a long time. This can be done in a follow-up PR so I'm definitely in favour of merging this. |
ntamas
approved these changes
Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The value of the API version bump seems low at the moment. The main reason for doing it is consistency. I'll leave the decision to you, @ntamas. This PR does not block any work.
Here's agent assessment of what useful things become available from the later API.
Description: