https://github.com/python/cpython/commit/8565ddd288a86f76661823ee4b57cc37977c618e
commit: 8565ddd288a86f76661823ee4b57cc37977c618e
branch: main
author: Petr Viktorin <[email protected]>
committer: encukou <[email protected]>
date: 2026-01-07T13:09:48+01:00
summary:
gh-141671: PyMODINIT_FUNC: apply `__declspec(dllexport)` on Windows (GH-141672)
files:
A Misc/NEWS.d/next/C_API/2025-11-17-17-46-16.gh-issue-141671.cVXNW5.rst
M Include/exports.h
diff --git a/Include/exports.h b/Include/exports.h
index 62feb09ed2b433..97a674ec2403a4 100644
--- a/Include/exports.h
+++ b/Include/exports.h
@@ -35,6 +35,12 @@
#define Py_EXPORTED_SYMBOL
#define Py_LOCAL_SYMBOL
#endif
+ /* module init functions outside the core must be exported */
+ #if defined(Py_BUILD_CORE)
+ #define _PyINIT_EXPORTED_SYMBOL Py_EXPORTED_SYMBOL
+ #else
+ #define _PyINIT_EXPORTED_SYMBOL __declspec(dllexport)
+ #endif
#else
/*
* If we only ever used gcc >= 5, we could use __has_attribute(visibility)
@@ -52,19 +58,16 @@
#define Py_EXPORTED_SYMBOL
#define Py_LOCAL_SYMBOL
#endif
+ #define _PyINIT_EXPORTED_SYMBOL Py_EXPORTED_SYMBOL
#endif
/* only get special linkage if built as shared or platform is Cygwin */
#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
# if defined(HAVE_DECLSPEC_DLL)
# if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
-# define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL
RTYPE
/* module init functions inside the core need no external linkage */
/* except for Cygwin to handle embedding */
-# if defined(__CYGWIN__)
-# define _PyINIT_FUNC_DECLSPEC Py_EXPORTED_SYMBOL
-# else /* __CYGWIN__ */
+# if !defined(__CYGWIN__)
# define _PyINIT_FUNC_DECLSPEC
# endif /* __CYGWIN__ */
# else /* Py_BUILD_CORE */
@@ -77,12 +80,6 @@
# define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL
RTYPE
# endif /* !__CYGWIN__ */
# define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL
RTYPE
- /* module init functions outside the core must be exported */
-# if defined(__cplusplus)
-# define _PyINIT_FUNC_DECLSPEC extern "C"
Py_EXPORTED_SYMBOL
-# else /* __cplusplus */
-# define _PyINIT_FUNC_DECLSPEC Py_EXPORTED_SYMBOL
-# endif /* __cplusplus */
# endif /* Py_BUILD_CORE */
# endif /* HAVE_DECLSPEC_DLL */
#endif /* Py_ENABLE_SHARED */
@@ -96,13 +93,17 @@
#endif
#ifndef _PyINIT_FUNC_DECLSPEC
# if defined(__cplusplus)
-# define _PyINIT_FUNC_DECLSPEC extern "C" Py_EXPORTED_SYMBOL
+# define _PyINIT_FUNC_DECLSPEC extern "C" _PyINIT_EXPORTED_SYMBOL
# else /* __cplusplus */
-# define _PyINIT_FUNC_DECLSPEC Py_EXPORTED_SYMBOL
+# define _PyINIT_FUNC_DECLSPEC _PyINIT_EXPORTED_SYMBOL
# endif /* __cplusplus */
#endif
-#define PyMODINIT_FUNC _PyINIT_FUNC_DECLSPEC PyObject*
-#define PyMODEXPORT_FUNC _PyINIT_FUNC_DECLSPEC PyModuleDef_Slot*
+#ifndef PyMODINIT_FUNC
+ #define PyMODINIT_FUNC _PyINIT_FUNC_DECLSPEC PyObject*
+#endif
+#ifndef PyMODEXPORT_FUNC
+ #define PyMODEXPORT_FUNC _PyINIT_FUNC_DECLSPEC PyModuleDef_Slot*
+#endif
#endif /* Py_EXPORTS_H */
diff --git
a/Misc/NEWS.d/next/C_API/2025-11-17-17-46-16.gh-issue-141671.cVXNW5.rst
b/Misc/NEWS.d/next/C_API/2025-11-17-17-46-16.gh-issue-141671.cVXNW5.rst
new file mode 100644
index 00000000000000..304a6a5f75ff3b
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2025-11-17-17-46-16.gh-issue-141671.cVXNW5.rst
@@ -0,0 +1,2 @@
+:c:macro:`PyMODINIT_FUNC` (and the new :c:macro:`PyMODEXPORT_FUNC`) now adds
+a linkage declaration (``__declspec(dllexport)``) on Windows.
_______________________________________________
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]