Skip to content

build: target the Python 3.11 limited API - #898

Merged
ntamas merged 4 commits into
igraph:mainfrom
szhorvat:build/limited-api-3.11
Nov 29, 2026
Merged

ntamas merged 4 commits into
igraph:mainfrom
szhorvat:build/limited-api-3.11

Conversation

@szhorvat

@szhorvat szhorvat commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

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.

More of the stable API becomes available. The ones that would matter for python-igraph:

  • PyUnicode_AsUTF8AndSize() (3.10). igraphmodule_PyUnicode_CopyAsString could use it instead of building an intermediate bytes object.
  • Py_NewRef() / Py_XNewRef(), Py_Is*() and PyModule_AddObjectRef() (3.10). These make the reference counting easier to read and less error-prone.
  • The buffer protocol, PyObject_GetBuffer() (3.11). It would let the code read NumPy and other array data directly instead of iterating over Python sequences. This is the only one that could improve performance, and only if someone writes that code.
  • PyType_GetName() / PyType_GetQualName() (3.11). These help with error messages.

Description:

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

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
@szhorvat
szhorvat requested a review from ntamas November 28, 2026 15:33
@ntamas

ntamas commented Nov 29, 2026

Copy link
Copy Markdown
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
ntamas merged commit 1b2de73 into igraph:main Nov 29, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants