-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Description
The macro is documented as:
Declare an extension module initialization function. This macro:
- specifies the PyObject* return type,
- adds any special linkage declarations required by the platform, and
- for C++, declares the function as extern "C".
Specifically, the special linkage declarations should be __attribute__ ((visibility ("default"))) on GCC/clang, and __declspec(dllexport) on Windows.
However, the definition assumes we're building CPython itself, and only adds a linkage declaration with Py_ENABLE_SHARED -- that is, when Python itself is built with a shared library.
According to MSVC docs:
There are four methods for exporting a definition, listed in recommended order of use:
__declspec(dllexport)in the source code- An EXPORTS statement in a .def file
- An /EXPORT specification in a LINK command
- A comment directive in the source code, of the form
#pragma comment(linker, "/export: definition ").
Setuptools, and historically distutils, does (2) -- and so does, presumably, any other build system for native extensions on Windows.
However, this breaks for modules that define the PEP-793 PyModExport hook.
It would be great to switch to the preferred (1), and then tell Setuptools to avoid /EXPORT for 3.15+.