[PATCH STABLE V2] pure/osutil: use Python's msvcrt module (issue3380)
Adrian Buehlmann
adrian at cadifra.com
Thu Apr 19 10:44:37 CDT 2012
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1334848092 -7200
# Branch stable
# Node ID af57ab11e0a806c740df8c4bfbe0dba451c09fb0
# Parent 09dd707b522a766b7d5e5fd221c4e68ac735f4d9
pure/osutil: use Python's msvcrt module (issue3380)
As proposed by Christophe Gouiran <christophe.gouiran at eurocopter.com>
diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -58,7 +58,7 @@
if os.name != 'nt':
posixfile = open
else:
- import ctypes, ctypes.util
+ import ctypes, msvcrt
_kernel32 = ctypes.windll.kernel32
@@ -68,15 +68,6 @@
_INVALID_HANDLE_VALUE = _HANDLE(-1).value
- def _crtname():
- try:
- # find_msvcrt was introduced in Python 2.6
- return ctypes.util.find_msvcrt()
- except AttributeError:
- return 'msvcr71.dll' # CPython 2.5 and 2.4
-
- _crt = ctypes.PyDLL(_crtname())
-
# CreateFile
_FILE_SHARE_READ = 0x00000001
_FILE_SHARE_WRITE = 0x00000002
@@ -105,9 +96,6 @@
_DWORD, _DWORD, _HANDLE]
_kernel32.CreateFileA.restype = _HANDLE
- _crt._open_osfhandle.argtypes = [_HANDLE, ctypes.c_int]
- _crt._open_osfhandle.restype = ctypes.c_int
-
def _raiseioerror(name):
err = ctypes.WinError()
raise IOError(err.errno, '%s: %s' % (name, err.strerror))
@@ -156,10 +144,7 @@
if fh == _INVALID_HANDLE_VALUE:
_raiseioerror(name)
- # for CPython we must use the same CRT as Python uses,
- # or the os.fdopen call below will abort with
- # "OSError: [Errno 9] Bad file descriptor"
- fd = _crt._open_osfhandle(fh, flags)
+ fd = msvcrt.open_osfhandle(fh, flags)
if fd == -1:
_kernel32.CloseHandle(fh)
_raiseioerror(name)
More information about the Mercurial-devel
mailing list