comparison mercurial/win32.py @ 33419:7c33adc823e0

win32: work around a WinError problem handling HRESULT types I ran into this ctypes bug while working with the Crypto API. While this could be an issue with any Win32 API in theory, the handful of things that we call are older functions that are unlikely to return COM errors, so I didn't retrofit this everywhere.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 30 Mar 2017 00:33:00 -0400
parents 4c3d9ee87382
children 14af04391fb9
comparison
equal deleted inserted replaced
33418:1f3b54f392b0 33419:7c33adc823e0
210 _kernel32.PeekNamedPipe.argtypes = [_HANDLE, ctypes.c_void_p, _DWORD, 210 _kernel32.PeekNamedPipe.argtypes = [_HANDLE, ctypes.c_void_p, _DWORD,
211 ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p] 211 ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
212 _kernel32.PeekNamedPipe.restype = _BOOL 212 _kernel32.PeekNamedPipe.restype = _BOOL
213 213
214 def _raiseoserror(name): 214 def _raiseoserror(name):
215 err = ctypes.WinError() 215 # Force the code to a signed int to avoid an 'int too large' error.
216 # See https://bugs.python.org/issue28474
217 code = _kernel32.GetLastError()
218 if code > 0x7fffffff:
219 code -= 2**32
220 err = ctypes.WinError(code=code)
216 raise OSError(err.errno, '%s: %s' % (name, err.strerror)) 221 raise OSError(err.errno, '%s: %s' % (name, err.strerror))
217 222
218 def _getfileinfo(name): 223 def _getfileinfo(name):
219 fh = _kernel32.CreateFileA(name, 0, 224 fh = _kernel32.CreateFileA(name, 0,
220 _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE, 225 _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,