Hello, I had the problem with Mercurial 2.1.2 on Windows platform. We are currently a Mercurial backend in an application compiled with mingw gcc 4.4.0. We therefore embeds a Python 2.7.2 interpreter (we are linked with official Python27.dll) The problem arises when Mercurial tries to use osutil.posixfile() function: as we use gcc, the following line leads to an application exit: fp = _fdopen(fd, fpmode); (I suppose because FILE struct doesn't have the same alignment in msvc and libgcc) So, we felt back to use the Python implementation of osutil in mercurial/pure/osutil.py But we got about the same problem. Indeed, at following line there is an attemp to load msvc90.dll: _crt = ctypes.PyDLL(_crtname()) The call to ctypes.PyDLL("msvcr90.dll") currently fails because of the usage of gcc.
We found the following solution : use official msvcrt Python package Therefore, in mercurial/pure/osutil.py, we made following modifications: a)Changed: --------- 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()) Into: ---- import msvcrt as _crt b)Changed: --------- _crt._open_osfhandle.argtypes = [_HANDLE, ctypes.c_int] _crt._open_osfhandle.restype = ctypes.c_int Into: ---- #_crt._open_osfhandle.argtypes = [_HANDLE, ctypes.c_int] #_crt._open_osfhandle.restype = ctypes.c_int c)Changed: --------- fd = _crt._open_osfhandle(fh, flags) Into: ---- fd = _crt.open_osfhandle(fh, flags)
Related: issue3337
BeChris' proposal looks reasonable. Using msvcrt from the Python standard library seems to make a lot more sense than doing it via ctypes.util.find_msvcrt .
Fixed by http://selenic.com/repo/hg/rev/ee553e6cd8c4 Adrian Buehlmann <adrian@cadifra.com> pure/osutil: use Python's msvcrt module (issue3380) (please test the fix)
Hello, I just tested your fix and it works perfectly on our system.
--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:30 EDT --- This bug was previously known as _bug_ 3380 at http://mercurial.selenic.com/bts/issue3380