From e33d672345d54e6c978b741319f50540927b722c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horv=C3=A1t?= Date: Sat, 28 Nov 2026 14:38:16 +0000 Subject: [PATCH 1/3] build: target the Python 3.11 limited API 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 --- CHANGELOG.md | 3 +++ setup.py | 10 +++++----- src/_igraph/preamble.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a259f12..f88b09459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ - Dropped support for Python 3.9 and 3.10 as they have reached their end of life. The minimum supported Python version is now 3.11. +- The `abi3` wheels now target the stable ABI of Python 3.11 and are tagged + `cp311-abi3` instead of `cp39-abi3`. + ## 1.0.1 - 2025-12-26 ### Changed diff --git a/setup.py b/setup.py index 9af9599f2..6cc95866b 100644 --- a/setup.py +++ b/setup.py @@ -907,19 +907,19 @@ class bdist_wheel_abi3(bdist_wheel): def get_tag(self): python, abi, plat = super().get_tag() if python.startswith("cp"): - # on CPython, our wheels are abi3 and compatible back to 3.9 - return "cp39", "abi3", plat + # on CPython, our wheels are abi3 and compatible back to 3.11 + return "cp311", "abi3", plat return python, abi, plat else: bdist_wheel_abi3 = None -# We are going to build an abi3 wheel if we are at least on CPython 3.9. +# We are going to build an abi3 wheel if we are at least on CPython 3.11. should_build_abi3_wheel = ( bdist_wheel_abi3 and platform.python_implementation() == "CPython" - and sys.version_info >= (3, 9) + and sys.version_info >= (3, 11) ) ########################################################################### @@ -939,7 +939,7 @@ def get_tag(self): sources.append(os.path.join("src", "_igraph", "force_cpp_linker.cpp")) macros = [] if should_build_abi3_wheel: - macros.append(("Py_LIMITED_API", "0x03090000")) + macros.append(("Py_LIMITED_API", "0x030B0000")) igraph_extension = Extension( "igraph._igraph", sources=sources, diff --git a/src/_igraph/preamble.h b/src/_igraph/preamble.h index e70f91c0a..cdd662007 100644 --- a/src/_igraph/preamble.h +++ b/src/_igraph/preamble.h @@ -25,7 +25,7 @@ #ifndef PY_IGRAPH_ALLOW_ENTIRE_PYTHON_API # ifndef Py_LIMITED_API -# define Py_LIMITED_API 0x03090000 +# define Py_LIMITED_API 0x030B0000 # endif #endif From a1843280331cc5bca22682d1dbccdc1837e5ffc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horv=C3=A1t?= Date: Sat, 28 Nov 2026 15:07:42 +0000 Subject: [PATCH 2/3] fix: adapt the C extension to the Python 3.11 limited API headers With Py_LIMITED_API set to 3.11 or later, Python.h no longer includes , , and , 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 --- src/_igraph/bfsiter.c | 6 +++--- src/_igraph/dfsiter.c | 6 +++--- src/_igraph/edgeobject.c | 4 ++-- src/_igraph/edgeseqobject.c | 6 +++--- src/_igraph/graphobject.c | 10 +++++----- src/_igraph/preamble.h | 7 +++++++ src/_igraph/pyhelpers.h | 2 +- src/_igraph/vertexobject.c | 4 ++-- src/_igraph/vertexseqobject.c | 6 +++--- 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/_igraph/bfsiter.c b/src/_igraph/bfsiter.c index c8b814f88..908755752 100644 --- a/src/_igraph/bfsiter.c +++ b/src/_igraph/bfsiter.c @@ -51,7 +51,7 @@ PyObject* igraphmodule_BFSIter_new(igraphmodule_GraphObject *g, PyObject *root, return NULL; } - Py_INCREF(g); + Py_INCREF((PyObject*)g); self->gref = g; self->graph = &g->g; @@ -121,7 +121,7 @@ static int igraphmodule_BFSIter_traverse(igraphmodule_BFSIterObject *self, visitproc visit, void *arg) { RC_TRAVERSE("BFSIter", self); Py_VISIT(self->gref); - Py_VISIT(Py_TYPE(self)); + Py_VISIT(Py_TYPE((PyObject*)self)); return 0; } @@ -156,7 +156,7 @@ static void igraphmodule_BFSIter_dealloc(igraphmodule_BFSIterObject* self) { } static PyObject* igraphmodule_BFSIter_iter(igraphmodule_BFSIterObject* self) { - Py_INCREF(self); + Py_INCREF((PyObject*)self); return (PyObject*)self; } diff --git a/src/_igraph/dfsiter.c b/src/_igraph/dfsiter.c index 08a7fedea..0cc1a991a 100644 --- a/src/_igraph/dfsiter.c +++ b/src/_igraph/dfsiter.c @@ -51,7 +51,7 @@ PyObject* igraphmodule_DFSIter_new(igraphmodule_GraphObject *g, PyObject *root, return NULL; } - Py_INCREF(g); + Py_INCREF((PyObject*)g); self->gref = g; self->graph = &g->g; @@ -122,7 +122,7 @@ static int igraphmodule_DFSIter_traverse(igraphmodule_DFSIterObject *self, visitproc visit, void *arg) { RC_TRAVERSE("DFSIter", self); Py_VISIT(self->gref); - Py_VISIT(Py_TYPE(self)); + Py_VISIT(Py_TYPE((PyObject*)self)); return 0; } @@ -155,7 +155,7 @@ static void igraphmodule_DFSIter_dealloc(igraphmodule_DFSIterObject* self) { } static PyObject* igraphmodule_DFSIter_iter(igraphmodule_DFSIterObject* self) { - Py_INCREF(self); + Py_INCREF((PyObject*)self); return (PyObject*)self; } diff --git a/src/_igraph/edgeobject.c b/src/_igraph/edgeobject.c index 1d36eebcf..d1df1d421 100644 --- a/src/_igraph/edgeobject.c +++ b/src/_igraph/edgeobject.c @@ -587,7 +587,7 @@ PyObject* igraphmodule_Edge_get_vertex_tuple(igraphmodule_EdgeObject* self, void * Returns the graph where the edge belongs */ PyObject* igraphmodule_Edge_get_graph(igraphmodule_EdgeObject* self, void* closure) { - Py_INCREF(self->gref); + Py_INCREF((PyObject*)self->gref); return (PyObject*)self->gref; } @@ -598,7 +598,7 @@ PyObject* igraphmodule_Edge_get_graph(igraphmodule_EdgeObject* self, void* closu \ /* Prepend ourselves to args */ \ new_args = PyTuple_New(num_args); \ - Py_INCREF(self); \ + Py_INCREF((PyObject*)self); \ PyTuple_SetItem(new_args, 0, (PyObject*)self); \ for (i = 1; i < num_args; i++) { \ item = PyTuple_GetItem(args, i - 1); \ diff --git a/src/_igraph/edgeseqobject.c b/src/_igraph/edgeseqobject.c index fddc61d51..ec99fb40f 100644 --- a/src/_igraph/edgeseqobject.c +++ b/src/_igraph/edgeseqobject.c @@ -58,7 +58,7 @@ igraphmodule_EdgeSeqObject* igraphmodule_EdgeSeq_copy(igraphmodule_EdgeSeqObject* o) { igraphmodule_EdgeSeqObject *copy; - copy = (igraphmodule_EdgeSeqObject*) PyType_GenericNew(Py_TYPE(o), 0, 0); + copy = (igraphmodule_EdgeSeqObject*) PyType_GenericNew(Py_TYPE((PyObject*)o), 0, 0); if (copy == NULL) { return NULL; } @@ -81,7 +81,7 @@ igraphmodule_EdgeSeq_copy(igraphmodule_EdgeSeqObject* o) { copy->gref = o->gref; if (o->gref) { - Py_INCREF(o->gref); + Py_INCREF((PyObject*)o->gref); } RC_ALLOC("EdgeSeq(copy)", copy); @@ -1015,7 +1015,7 @@ PyMethodDef igraphmodule_EdgeSeq_methods[] = { */ PyObject* igraphmodule_EdgeSeq_get_graph(igraphmodule_EdgeSeqObject* self, void* closure) { - Py_INCREF(self->gref); + Py_INCREF((PyObject*)self->gref); return (PyObject*)self->gref; } diff --git a/src/_igraph/graphobject.c b/src/_igraph/graphobject.c index 620818ed2..a97ab05fe 100644 --- a/src/_igraph/graphobject.c +++ b/src/_igraph/graphobject.c @@ -47,7 +47,7 @@ PyTypeObject* igraphmodule_GraphType; #define CREATE_GRAPH(py_graph, c_graph) { \ py_graph = (igraphmodule_GraphObject*) igraphmodule_Graph_subclass_from_igraph_t( \ - Py_TYPE(self), &c_graph \ + Py_TYPE((PyObject*)self), &c_graph \ ); \ if (py_graph == NULL) { igraph_destroy(&c_graph); } \ } @@ -140,7 +140,7 @@ int igraphmodule_Graph_traverse(igraphmodule_GraphObject * self, } } - Py_VISIT(Py_TYPE(self)); + Py_VISIT(Py_TYPE((PyObject*)self)); return 0; } @@ -4582,7 +4582,7 @@ PyObject *igraphmodule_Graph_bipartite_projection(igraphmodule_GraphObject * sel if (p_g2) { CREATE_GRAPH(result2, g2); if (result2 == NULL) { - Py_XDECREF(result1); + Py_XDECREF((PyObject*)result1); return NULL; } } @@ -5152,7 +5152,7 @@ PyObject *igraphmodule_Graph_decompose(igraphmodule_GraphObject * self, /* We have to create a Python igraph object for every graph returned. During * the conversion, the graph list will be emptied as the Python list we return * from the conversion function takes ownership of all the graphs */ - list = igraphmodule_graph_list_t_to_PyList(&components, Py_TYPE(self)); + list = igraphmodule_graph_list_t_to_PyList(&components, Py_TYPE((PyObject*)self)); if (!list) { igraph_graph_list_destroy(&components); return 0; @@ -7054,7 +7054,7 @@ PyObject *igraphmodule_Graph_simplify(igraphmodule_GraphObject * self, } igraph_attribute_combination_destroy(&comb); - Py_INCREF(self); + Py_INCREF((PyObject*)self); return (PyObject *) self; } diff --git a/src/_igraph/preamble.h b/src/_igraph/preamble.h index cdd662007..b78fc1451 100644 --- a/src/_igraph/preamble.h +++ b/src/_igraph/preamble.h @@ -32,4 +32,11 @@ #define PY_SSIZE_T_CLEAN #include +/* Python.h stops including these standard headers when Py_LIMITED_API is + * 3.11 or later, but the extension relies on them. */ +#include +#include +#include +#include + #endif /* PYTHON_IGRAPH_PREAMBLE_H */ diff --git a/src/_igraph/pyhelpers.h b/src/_igraph/pyhelpers.h index 2dba07a44..030581c37 100644 --- a/src/_igraph/pyhelpers.h +++ b/src/_igraph/pyhelpers.h @@ -52,7 +52,7 @@ char* igraphmodule_PyUnicode_CopyAsString(PyObject* string); /* Calling Py_DECREF() on heap-allocated types in tp_dealloc was not needed * before Python 3.8 (see Python issue 35810) */ #define PY_FREE_AND_DECREF_TYPE(obj, base_type) { \ - PyTypeObject* _tp = Py_TYPE(obj); \ + PyTypeObject* _tp = Py_TYPE((PyObject*)(obj)); \ ((freefunc)PyType_GetSlot(_tp, Py_tp_free))(obj); \ Py_DECREF(_tp); \ } diff --git a/src/_igraph/vertexobject.c b/src/_igraph/vertexobject.c index 45490c63b..bc9073a50 100644 --- a/src/_igraph/vertexobject.c +++ b/src/_igraph/vertexobject.c @@ -581,7 +581,7 @@ igraph_int_t igraphmodule_Vertex_get_index_igraph_integer(igraphmodule_VertexObj */ PyObject* igraphmodule_Vertex_get_graph(igraphmodule_VertexObject* self, void* closure) { - Py_INCREF(self->gref); + Py_INCREF((PyObject*)self->gref); return (PyObject*)self->gref; } @@ -695,7 +695,7 @@ static PyObject* _convert_to_vertex_list(igraphmodule_VertexObject* vertex, PyOb \ /* Prepend ourselves to args */ \ new_args = PyTuple_New(num_args); \ - Py_INCREF(self); \ + Py_INCREF((PyObject*)self); \ PyTuple_SetItem(new_args, 0, (PyObject*)self); \ for (i = 1; i < num_args; i++) { \ item = PyTuple_GetItem(args, i - 1); \ diff --git a/src/_igraph/vertexseqobject.c b/src/_igraph/vertexseqobject.c index cb9ca3470..81b76098c 100644 --- a/src/_igraph/vertexseqobject.c +++ b/src/_igraph/vertexseqobject.c @@ -58,7 +58,7 @@ igraphmodule_VertexSeqObject* igraphmodule_VertexSeq_copy(igraphmodule_VertexSeqObject* o) { igraphmodule_VertexSeqObject *copy; - copy = (igraphmodule_VertexSeqObject*) PyType_GenericNew(Py_TYPE(o), 0, 0); + copy = (igraphmodule_VertexSeqObject*) PyType_GenericNew(Py_TYPE((PyObject*)o), 0, 0); if (copy == NULL) { return NULL; } @@ -80,7 +80,7 @@ igraphmodule_VertexSeq_copy(igraphmodule_VertexSeqObject* o) { } copy->gref = o->gref; - if (o->gref) Py_INCREF(o->gref); + if (o->gref) Py_INCREF((PyObject*)o->gref); RC_ALLOC("VertexSeq(copy)", copy); return copy; @@ -981,7 +981,7 @@ int igraphmodule_VertexSeq_to_vector_t(igraphmodule_VertexSeqObject *self, */ PyObject* igraphmodule_VertexSeq_get_graph(igraphmodule_VertexSeqObject* self, void* closure) { - Py_INCREF(self->gref); + Py_INCREF((PyObject*)self->gref); return (PyObject*)self->gref; } From 066e7a0c8273eb47509350e8d1fb518503b55b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horv=C3=A1t?= Date: Sat, 28 Nov 2026 15:27:40 +0000 Subject: [PATCH 3/3] fix: include Python.h before any standard header 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 , and first, which makes the Python 3.15 headers warn about _POSIX_C_SOURCE being redefined. Also include 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 --- src/_igraph/common.h | 4 ++-- src/_igraph/convert.c | 5 ++++- src/_igraph/preamble.h | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/_igraph/common.h b/src/_igraph/common.h index fda85c948..a0871e21f 100644 --- a/src/_igraph/common.h +++ b/src/_igraph/common.h @@ -23,10 +23,10 @@ #ifndef IGRAPHMODULE_COMMON_H #define IGRAPHMODULE_COMMON_H -#include - #include "preamble.h" +#include + #ifdef RC_DEBUG # define RC_ALLOC(T, P) fprintf(stderr, "[ alloc ] " T " @ %p\n", P) # define RC_DECREF(T, P) fprintf(stderr, "[ ref - ] " T " @ %p (was: %d)\n", P, (int)P->ob_refcnt); diff --git a/src/_igraph/convert.c b/src/_igraph/convert.c index 2f8f0eee6..d0848c1f2 100644 --- a/src/_igraph/convert.c +++ b/src/_igraph/convert.c @@ -22,8 +22,11 @@ /************************ Conversion functions *************************/ -#include +#include "preamble.h" + #include +#include + #include "attributes.h" #include "convert.h" #include "edgeseqobject.h" diff --git a/src/_igraph/preamble.h b/src/_igraph/preamble.h index b78fc1451..fae0554e9 100644 --- a/src/_igraph/preamble.h +++ b/src/_igraph/preamble.h @@ -33,8 +33,11 @@ #include /* Python.h stops including these standard headers when Py_LIMITED_API is - * 3.11 or later, but the extension relies on them. */ + * 3.11 (: 3.13) or later, but the extension relies on them. + * Python.h must be included before any standard header, so include them + * here instead of at the top of individual source files. */ #include +#include #include #include #include