From bb1c215f334caef2b4846c1c28c10642dddce22f Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 29 Sep 2026 14:02:45 +0200 Subject: [PATCH] gh-158098: Add Setuptools workaround to abi3t migration guide Also, use ``_`` consistently. --- Doc/howto/abi3t-migration.rst | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Doc/howto/abi3t-migration.rst b/Doc/howto/abi3t-migration.rst index ec78a33ed25820e..846d07eff3270a3 100644 --- a/Doc/howto/abi3t-migration.rst +++ b/Doc/howto/abi3t-migration.rst @@ -217,9 +217,9 @@ Module export hook Unless you've done this step already, your extension module defines a :ref:`module initialization function ` -named :samp:`PyInit_{}`. +named :samp:`PyInit_{}` (where ``modname`` is the name of your module). You will need to port it to a :ref:`module export hook `, -:samp:`PyModExport_{}`, a feature added in CPython 3.15 in +:samp:`PyModExport_{}`, a feature added in CPython 3.15 in :pep:`793`. Your existing init function should look like this (with your own names @@ -297,6 +297,34 @@ pointer to static data. If you cannot avoid additional code, refer to the :ref:`caveats in PyModExport documentation `. +.. note:: + + When building for Windows using the Setuptools_ build tool, + removing the :samp:`PyInit_{}` function may result in the linker error + :samp:`LINK : error LNK2001: unresolved external symbol PyInit_{}`. + This is caused by Setuptools passing an ``/EXPORT`` linker flag, which + is redundant since Python 3.15 (see :gh:`141671`). + A workaround is to add a dummy :samp:`PyInit_{}` function + to your code. + Python 3.15+ will never call this function if + :samp:`PyModExport_{}` is present, so it can always fail: + + .. code-block:: c + + // Workaround for https://github.com/pypa/distutils/issues/387 + PyMODINIT_FUNC + PyInit_(void) + { + PyErr_SetString(PyExc_SystemError, + "PyInit_* called for module with PyModExport_*"); + return NULL; + } + + (This issue is present in Setuptools 84.0.0; it might be fixed in newer + versions.) + +.. _Setuptools: https://setuptools.pypa.io/ + Existing slots --------------