Bug 3381 - In mercurial/pure/osutil.py, avoid use of msvcrt dll
Summary: In mercurial/pure/osutil.py, avoid use of msvcrt dll
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-18 06:06 UTC by Christophe Gouiran
Modified: 2012-05-13 05:00 UTC (History)
8 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Gouiran 2012-04-18 06:06 UTC
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.
Comment 1 Christophe Gouiran 2012-04-18 06:09 UTC
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)
Comment 2 Matt Mackall 2012-04-18 10:40 UTC
Related: issue3337
Comment 3 Adrian Buehlmann 2012-04-18 17:31 UTC
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 
.
Comment 4 HG Bot 2012-04-19 22:00 UTC
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)
Comment 5 Christophe Gouiran 2012-04-20 02:44 UTC
Hello, I just tested your fix and it works perfectly on our system.
Comment 6 Bugzilla 2012-05-12 09:30 UTC

--- 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