changeset 32857:d644e859d9da

killdaemons: explicitly set the ctypes signatures When I tried importing util.posixfile to work around removing a file opened by another process on Windows, it brought along the declarations in win32.py, which broke the error handling[1]. It doesn't seem worth hacking killdaemons[2] just to isolate these declarations in win32.py, so just declare them here to prevent any future issues. (win32.py mentions the declarations are required by pypy.) [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-May/097905.html [2] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-May/097907.html
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 06 Jun 2017 20:18:06 -0400
parents 41f99a90675d
children ed1f376090cd
files tests/killdaemons.py
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/killdaemons.py	Sun May 07 14:58:40 2017 -0400
+++ b/tests/killdaemons.py	Tue Jun 06 20:18:06 2017 -0400
@@ -10,6 +10,26 @@
 if os.name =='nt':
     import ctypes
 
+    _BOOL = ctypes.c_long
+    _DWORD = ctypes.c_ulong
+    _UINT = ctypes.c_uint
+    _HANDLE = ctypes.c_void_p
+
+    ctypes.windll.kernel32.CloseHandle.argtypes = [_HANDLE]
+    ctypes.windll.kernel32.CloseHandle.restype = _BOOL
+
+    ctypes.windll.kernel32.GetLastError.argtypes = []
+    ctypes.windll.kernel32.GetLastError.restype = _DWORD
+
+    ctypes.windll.kernel32.OpenProcess.argtypes = [_DWORD, _BOOL, _DWORD]
+    ctypes.windll.kernel32.OpenProcess.restype = _HANDLE
+
+    ctypes.windll.kernel32.TerminateProcess.argtypes = [_HANDLE, _UINT]
+    ctypes.windll.kernel32.TerminateProcess.restype = _BOOL
+
+    ctypes.windll.kernel32.WaitForSingleObject.argtypes = [_HANDLE, _DWORD]
+    ctypes.windll.kernel32.WaitForSingleObject.restype = _DWORD
+
     def _check(ret, expectederr=None):
         if ret == 0:
             winerrno = ctypes.GetLastError()
@@ -27,7 +47,7 @@
         handle = ctypes.windll.kernel32.OpenProcess(
                 PROCESS_TERMINATE|SYNCHRONIZE|PROCESS_QUERY_INFORMATION,
                 False, pid)
-        if handle == 0:
+        if handle is None:
             _check(0, 87) # err 87 when process not found
             return # process not found, already finished
         try: