fix(ctypes): share wintypes.MSG with platform_detector to avoid argtype races
WindowsShutdownGuard was binding user32.GetMessageW.argtypes with POINTER(_MSG) (project-local struct), while PlatformDetector's display- power monitor binds it with POINTER(wintypes.MSG). argtypes is a mutable global on the cached WinDLL handle, so whichever module imported last won, and the other module's byref() then tripped Python 3.13's strict argtype check with "expected LP_MSG instance instead of pointer to _MSG". The two structs are byte-identical (same field types in the same order, just pt vs pt_x/pt_y naming) and we never touch the pt field, so aliasing _MSG to wintypes.MSG eliminates the conflict — both modules now bind the same POINTER class, the writes become idempotent, and the full test suite passes regardless of import order. CI runs on Linux so this never fired in release builds, but it broke the local Windows test run.
This commit is contained in:
@@ -101,16 +101,15 @@ class _WNDCLASS(ctypes.Structure):
|
||||
]
|
||||
|
||||
|
||||
class _MSG(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("hwnd", wintypes.HWND),
|
||||
("message", wintypes.UINT),
|
||||
("wParam", wintypes.WPARAM),
|
||||
("lParam", wintypes.LPARAM),
|
||||
("time", wintypes.DWORD),
|
||||
("pt_x", wintypes.LONG),
|
||||
("pt_y", wintypes.LONG),
|
||||
]
|
||||
# Use the stdlib wintypes.MSG (rather than a project-local _MSG) so the
|
||||
# POINTER(MSG) type is shared with any other module that binds
|
||||
# user32.GetMessageW.argtypes — argtypes is a global on the cached DLL
|
||||
# handle, and two modules binding it with different POINTER classes for
|
||||
# the same C function fight each other (last writer wins, the other one's
|
||||
# byref() then trips Python 3.13's strict argtype check). PlatformDetector's
|
||||
# display-power monitor binds with POINTER(wintypes.MSG); aligning here
|
||||
# means whichever loads last produces the same binding.
|
||||
_MSG = wintypes.MSG
|
||||
|
||||
|
||||
def _bind_winapi() -> None:
|
||||
|
||||
Reference in New Issue
Block a user