mirror of
https://github.com/python/cpython.git
synced 2026-04-13 07:10:50 +00:00
gh-145307: Defer loading psapi.dll until ctypes.util.dllist() is called. (GH-145308)
This commit is contained in:
parent
201d251567
commit
1cf5abedeb
2 changed files with 18 additions and 10 deletions
|
|
@ -85,15 +85,10 @@ def find_library(name):
|
|||
wintypes.DWORD,
|
||||
)
|
||||
|
||||
_psapi = ctypes.WinDLL('psapi', use_last_error=True)
|
||||
_enum_process_modules = _psapi["EnumProcessModules"]
|
||||
_enum_process_modules.restype = wintypes.BOOL
|
||||
_enum_process_modules.argtypes = (
|
||||
wintypes.HANDLE,
|
||||
ctypes.POINTER(wintypes.HMODULE),
|
||||
wintypes.DWORD,
|
||||
wintypes.LPDWORD,
|
||||
)
|
||||
# gh-145307: We defer loading psapi.dll until _get_module_handles is called.
|
||||
# Loading additional DLLs at startup for functionality that may never be
|
||||
# used is wasteful.
|
||||
_enum_process_modules = None
|
||||
|
||||
def _get_module_filename(module: wintypes.HMODULE):
|
||||
name = (wintypes.WCHAR * 32767)() # UNICODE_STRING_MAX_CHARS
|
||||
|
|
@ -101,8 +96,19 @@ def _get_module_filename(module: wintypes.HMODULE):
|
|||
return name.value
|
||||
return None
|
||||
|
||||
|
||||
def _get_module_handles():
|
||||
global _enum_process_modules
|
||||
if _enum_process_modules is None:
|
||||
_psapi = ctypes.WinDLL('psapi', use_last_error=True)
|
||||
_enum_process_modules = _psapi["EnumProcessModules"]
|
||||
_enum_process_modules.restype = wintypes.BOOL
|
||||
_enum_process_modules.argtypes = (
|
||||
wintypes.HANDLE,
|
||||
ctypes.POINTER(wintypes.HMODULE),
|
||||
wintypes.DWORD,
|
||||
wintypes.LPDWORD,
|
||||
)
|
||||
|
||||
process = _get_current_process()
|
||||
space_needed = wintypes.DWORD()
|
||||
n = 1024
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Defers loading of the ``psapi.dll`` module until it is used by
|
||||
:func:`ctypes.util.dllist`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue