[pypy-svn] r69711 - pypy/trunk/pypy/rlib
afa at codespeak.net
afa at codespeak.net
Fri Nov 27 19:35:43 CET 2009
Author: afa
Date: Fri Nov 27 19:35:42 2009
New Revision: 69711
Modified:
pypy/trunk/pypy/rlib/rwin32.py
Log:
Attempt to fix the windows buildbot, which uses Visual Studio 7:
To generate the map between Windows error codes and errno,
we compile and run an external program, statically linked with the CRT.
(Visual Studio 7 provides the function _dosmaperr only in the static C library)
As a bonus, loading the module is now faster: it saves 65000 calls through ll2ctypes...
Modified: pypy/trunk/pypy/rlib/rwin32.py
==============================================================================
--- pypy/trunk/pypy/rlib/rwin32.py (original)
+++ pypy/trunk/pypy/rlib/rwin32.py Fri Nov 27 19:35:42 2009
@@ -3,6 +3,7 @@
"""
from pypy.rpython.tool import rffi_platform
+from pypy.tool.udir import udir
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.rarithmetic import intmask
@@ -14,13 +15,8 @@
if WIN32:
eci = ExternalCompilationInfo(
- includes = ['windows.h', 'errno.h'],
+ includes = ['windows.h'],
libraries = ['kernel32'],
- separate_module_sources = ["""
- long WINAPI pypy_dosmaperr(long winerror)
- { _dosmaperr(winerror); return errno; }
- """],
- export_symbols = ["pypy_dosmaperr"],
)
else:
eci = ExternalCompilationInfo()
@@ -97,20 +93,40 @@
_get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], HANDLE)
- dosmaperr = winexternal('pypy_dosmaperr', [rffi.LONG], rffi.LONG)
-
-
def build_winerror_to_errno():
"""Build a dictionary mapping windows error numbers to POSIX errno.
The function returns the dict, and the default value for codes not
in the dict."""
- default = errno.EINVAL
- errors = {}
- for i in range(1, 65000):
- error = dosmaperr(i)
- if error != default:
- errors[i] = error
- return errors, default
+ # Prior to Visual Studio 8, the MSVCRT dll doesn't export the
+ # _dosmaperr() function, which is available only when compiled
+ # against the static CRT library.
+ from pypy.translator.platform import platform, Windows
+ static_platform = Windows()
+ if static_platform.name == 'msvc':
+ static_platform.cflags = ['/MT'] # static CRT
+ static_platform.version = 0 # no manifest
+ cfile = udir.join('dosmaperr.c')
+ cfile.write(r'''
+ #include <errno.h>
+ int main()
+ {
+ int i;
+ for(i=1; i < 65000; i++) {
+ _dosmaperr(i);
+ if (errno == EINVAL)
+ continue;
+ printf("%d\t%d\n", i, errno);
+ }
+ return 0;
+ }''')
+ exename = static_platform.compile(
+ [cfile], ExternalCompilationInfo(),
+ outputfilename = "dosmaperr",
+ standalone=True)
+ output = os.popen(str(exename))
+ errors = dict(map(int, line.split())
+ for line in output)
+ return errors, errno.EINVAL
# A bit like strerror...
def FormatError(code):
More information about the Pypy-commit
mailing list