gh-85470: Delay load ole32.dll in the _ctypes module - #155435
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-85470: Delay load ole32.dll in the _ctypes module#155435serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
ole32.dll pulls in user32.dll, which makes the system treat the process as a GUI process and stop sending logoff and shutdown console control events to it. It is only needed for ProgIDFromCLSID() when formatting a COM error.
Member
Author
|
Verified the actual effect, not just the module list: two processes started from the same build in the same interactive session, one of them force-loading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Measured on Windows 11 with a debug x64 build --
import _ctypesbefore the change loadsuser32.dll,ole32.dll,gdi32.dll,win32u.dllandcombase.dll; after it, onlycombase.dllremains (pulled in byoleaut32, which does not depend onuser32). A plainpython.exealready loaded none of them, soctypeswas the last thing making the interpreter a GUI process -- and it is the module a console script needs in order to callSetConsoleCtrlHandler()in the first place.ProgIDFromCLSID()inSetComError()is the only ole32 use in_ctypes, and it is reached only when formatting an error from a COM interface method.PCbuild/_wmi.vcxprojalready delay loads the same DLL.test_ctypespasses (679 tests). This covers the PCbuild build only; resolvingProgIDFromCLSID()throughGetProcAddress()would also cover other toolchains, at the cost of some C code.