https://github.com/python/cpython/commit/965e2b734fbfd869178a318314f8d137d2ec2c1d commit: 965e2b734fbfd869178a318314f8d137d2ec2c1d branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: hugovk <[email protected]> date: 2026-10-06T16:46:14+03:00 summary:
[3.15] gh-158098: Add Setuptools workaround to abi3t migration guide (GH-158405) (#158601) Co-authored-by: Petr Viktorin <[email protected]> files: M Doc/howto/abi3t-migration.rst diff --git a/Doc/howto/abi3t-migration.rst b/Doc/howto/abi3t-migration.rst index ec78a33ed25820e..501106679b02bd9 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 <extension-pyinit>` -named :samp:`PyInit_{<module_name>}`. +named :samp:`PyInit_{<modname>}` (where ``modname`` is the name of your module). You will need to port it to a :ref:`module export hook <extension-export-hook>`, -:samp:`PyModExport_{<module name>}`, a feature added in CPython 3.15 in +:samp:`PyModExport_{<modname>}`, 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 <pymodexport-api-caveats>`. +.. note:: + + When building for Windows using the Setuptools_ build tool, + removing the :samp:`PyInit_{<modname>}` function may result in the linker error + :samp:`LINK : error LNK2001: unresolved external symbol PyInit_{<modname>}`. + 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_{<modname>}` function + to your code. + Python 3.15+ will never call this function if + :samp:`PyModExport_{<modname>}` is present, so it can always fail: + + .. code-block:: c + + // Workaround for https://github.com/pypa/distutils/issues/387 + PyMODINIT_FUNC + PyInit_<modname>(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 -------------- _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
