Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-141671: PyMODINIT_FUNC: apply __declspec(dllexport) on Windows#141672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
encukou commented Nov 17, 2025 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
encukou commented Nov 17, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Include/exports.h Outdated
| #if defined(_WIN32) || defined(__CYGWIN__) | ||
| #if defined(Py_ENABLE_SHARED) | ||
| #if!defined(Py_BUILD_CORE) ||defined(Py_ENABLE_SHARED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure about this... don't we need it for our own exports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for Py_ENABLE_SHARED -- see #99888 that added the #else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see we do these checks again everywhere else we use the macros. No problem them.
pfmoore commented Nov 17, 2025
TBH, I have no view. My knowledge of C is very out of date, so I wouldn't trust anything I might say anyway... |
da-woods commented Nov 18, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
The (Edit: admittedly we also aren't the people that it's designed to help either) |
encukou commented Dec 16, 2025
Here's a version that removes some redundant defines (setting things to defaults). |
vstinner left a comment • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This change mostly moves code around, and just add __declspec(dllexport) on Windows.
| #definePyMODINIT_FUNC _PyINIT_FUNC_DECLSPEC PyObject* | ||
| #definePyMODEXPORT_FUNC _PyINIT_FUNC_DECLSPEC PyModuleDef_Slot* | ||
| #ifndefPyMODINIT_FUNC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supporting an already defined PyMODINIT_FUNC/PyMODEXPORT_FUNC is a new feature. Is it really worth it? I'm not against it, just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an escape hatch: if there's an unexpected problem with this PR, this can allow people to hotfix it without patching or waiting for a new release.
bedevere-bot commented Dec 19, 2025
🤖 New build scheduled with the buildbot fleet by @encukou for commit 5091b79 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F141672%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
| #if defined(Py_BUILD_CORE) | ||
| #define_PyINIT_EXPORTED_SYMBOL Py_EXPORTED_SYMBOL | ||
| #else | ||
| #define_PyINIT_EXPORTED_SYMBOL __declspec(dllexport) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better option instead is to define Py_EXPORTED_SYMBOL here and then use that.
Also I feel like an escape hatch like Py_EMBED_MODULE where it basically uses Py_LOCAL_SYMBOL instead could be an option as well for when one does not want the module init function exported due to intending to use PyImport_AppendInitTab within the exe that they directly build the module into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to change the meaning of Py_EXPORTED_SYMBOL.
For the inittab, you can avoid PyMODINIT_FUNC/PyMODEXPORT_FUNC, and just use a normal declaration.
8565ddd into python:mainUh oh!
There was an error while loading. Please reload this page.
PyMODINIT_FUNCdoes not apply__declspec(dllexport)on Windows #141671