changeset 16474:ee553e6cd8c4 stable

pure/osutil: use Python's msvcrt module (issue3380) As proposed by Christophe Gouiran <christophe.gouiran@eurocopter.com>
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 19 Apr 2012 17:08:12 +0200
parents 7adc521259d4
children 1f75c1decdeb fc04698fa778
files mercurial/pure/osutil.py
diffstat 1 files changed, 2 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pure/osutil.py	Thu Apr 19 18:11:48 2012 +0300
+++ b/mercurial/pure/osutil.py	Thu Apr 19 17:08:12 2012 +0200
@@ -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)