@@ -27,22 +27,25 @@ def _kill(self, sig):
2727 # subprocess to the parent that the interpreter is ready. When it
2828 # becomes ready, send *sig* via os.kill to the subprocess and check
2929 # that the return code is equal to *sig*.
30- import ctypes
30+ import ctypes . util
3131 from ctypes import wintypes
3232 import msvcrt
3333
3434 # Since we can't access the contents of the process' stdout until the
3535 # process has exited, use PeekNamedPipe to see what's inside stdout
3636 # without waiting. This is done so we can tell that the interpreter
3737 # is started and running at a point where it could handle a signal.
38- PeekNamedPipe = ctypes .windll .kernel32 .PeekNamedPipe
39- PeekNamedPipe .restype = wintypes .BOOL
40- PeekNamedPipe .argtypes = (wintypes .HANDLE , # Pipe handle
41- ctypes .POINTER (ctypes .c_char ), # stdout buf
42- wintypes .DWORD , # Buffer size
43- ctypes .POINTER (wintypes .DWORD ), # bytes read
44- ctypes .POINTER (wintypes .DWORD ), # bytes avail
45- ctypes .POINTER (wintypes .DWORD )) # bytes left
38+ @ctypes .util .wrap_dll_function (ctypes .windll .kernel32 )
39+ def PeekNamedPipe (
40+ hNamedPipe : wintypes .HANDLE ,
41+ lpBuffer : ctypes .POINTER (ctypes .c_char ),
42+ nBufferSize : wintypes .DWORD ,
43+ lpBytesRead : ctypes .POINTER (wintypes .DWORD ),
44+ lpTotalBytesAvail : ctypes .POINTER (wintypes .DWORD ),
45+ lpBytesLeftThisMessage : ctypes .POINTER (wintypes .DWORD ),
46+ ) -> wintypes .BOOL :
47+ pass
48+
4649 msg = "running"
4750 proc = subprocess .Popen ([sys .executable , "-c" ,
4851 "import sys;"
@@ -126,10 +129,11 @@ def test_CTRL_C_EVENT(self):
126129
127130 # Make a NULL value by creating a pointer with no argument.
128131 NULL = ctypes .POINTER (ctypes .c_int )()
129- SetConsoleCtrlHandler = ctypes .windll .kernel32 .SetConsoleCtrlHandler
130- SetConsoleCtrlHandler .argtypes = (ctypes .POINTER (ctypes .c_int ),
131- wintypes .BOOL )
132- SetConsoleCtrlHandler .restype = wintypes .BOOL
132+
133+ @ctypes .util .wrap_dll_function (ctypes .windll .kernel32 )
134+ def SetConsoleCtrlHandler (HandlerRoutine : ctypes .POINTER (ctypes .c_int ),
135+ Add : wintypes .BOOL ) -> wintypes .BOOL :
136+ pass
133137
134138 # Calling this with NULL and FALSE causes the calling process to
135139 # handle Ctrl+C, rather than ignore it. This property is inherited
@@ -458,17 +462,20 @@ def test_getfinalpathname_handles(self):
458462 import ctypes .wintypes # noqa: F811
459463
460464 kernel = ctypes .WinDLL ('Kernel32.dll' , use_last_error = True )
461- kernel .GetCurrentProcess .restype = ctypes .wintypes .HANDLE
465+ @ctypes .util .wrap_dll_function (kernel )
466+ def GetCurrentProcess () -> ctypes .wintypes .HANDLE :
467+ pass
462468
463- kernel .GetProcessHandleCount .restype = ctypes .wintypes .BOOL
464- kernel .GetProcessHandleCount .argtypes = (ctypes .wintypes .HANDLE ,
465- ctypes .wintypes .LPDWORD )
469+ @ctypes .util .wrap_dll_function (kernel )
470+ def GetProcessHandleCount (khProcess : ctypes .wintypes .HANDLE ,
471+ pdwHandleCount : ctypes .wintypes .LPDWORD ) -> ctypes .wintypes .BOOL :
472+ pass
466473
467474 # This is a pseudo-handle that doesn't need to be closed
468- hproc = kernel . GetCurrentProcess ()
475+ hproc = GetCurrentProcess ()
469476
470477 handle_count = ctypes .wintypes .DWORD ()
471- ok = kernel . GetProcessHandleCount (hproc , ctypes .byref (handle_count ))
478+ ok = GetProcessHandleCount (hproc , ctypes .byref (handle_count ))
472479 self .assertEqual (1 , ok )
473480
474481 before_count = handle_count .value
0 commit comments