Mercurial > hg
changeset 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 | 1f3b54f392b0 |
children | e80041832eec |
files | mercurial/win32.py |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/win32.py Wed Jul 12 15:27:56 2017 -0700 +++ b/mercurial/win32.py Thu Mar 30 00:33:00 2017 -0400 @@ -212,7 +212,12 @@ _kernel32.PeekNamedPipe.restype = _BOOL def _raiseoserror(name): - err = ctypes.WinError() + # Force the code to a signed int to avoid an 'int too large' error. + # See https://bugs.python.org/issue28474 + code = _kernel32.GetLastError() + if code > 0x7fffffff: + code -= 2**32 + err = ctypes.WinError(code=code) raise OSError(err.errno, '%s: %s' % (name, err.strerror)) def _getfileinfo(name):