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.""" # 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 rpython.translator.platform import host_factory static_platform = host_factory() 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> #include <stdio.h> #ifdef __GNUC__ #define _dosmaperr mingw_dosmaperr #endif 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; }''') try: exename = static_platform.compile( [cfile], ExternalCompilationInfo(), outputfilename = "dosmaperr", standalone=True) except (CompilationError, WindowsError): # Fallback for the mingw32 compiler errors = { 2: 2, 3: 2, 4: 24, 5: 13, 6: 9, 7: 12, 8: 12, 9: 12, 10: 7, 11: 8, 15: 2, 16: 13, 17: 18, 18: 2, 19: 13, 20: 13, 21: 13, 22: 13, 23: 13, 24: 13, 25: 13, 26: 13, 27: 13, 28: 13, 29: 13, 30: 13, 31: 13, 32: 13, 33: 13, 34: 13, 35: 13, 36: 13, 53: 2, 65: 13, 67: 2, 80: 17, 82: 13, 83: 13, 89: 11, 108: 13, 109: 32, 112: 28, 114: 9, 128: 10, 129: 10, 130: 9, 132: 13, 145: 41, 158: 13, 161: 2, 164: 11, 167: 13, 183: 17, 188: 8, 189: 8, 190: 8, 191: 8, 192: 8, 193: 8, 194: 8, 195: 8, 196: 8, 197: 8, 198: 8, 199: 8, 200: 8, 201: 8, 202: 8, 206: 2, 215: 11, 1816: 12, } else: output = os.popen(str(exename)) errors = dict(map(int, line.split()) for line in output) return errors, errno.EINVAL
class CConfig: _compilation_info_ = eci if WIN32: DWORD_PTR = rffi_platform.SimpleType("DWORD_PTR", rffi.LONG) WORD = rffi_platform.SimpleType("WORD", rffi.USHORT) DWORD = rffi_platform.SimpleType("DWORD", rffi.UINT) BOOL = rffi_platform.SimpleType("BOOL", rffi.LONG) BYTE = rffi_platform.SimpleType("BYTE", rffi.UCHAR) WCHAR = rffi_platform.SimpleType("WCHAR", rffi.UCHAR) INT = rffi_platform.SimpleType("INT", rffi.INT) LONG = rffi_platform.SimpleType("LONG", rffi.LONG) PLONG = rffi_platform.SimpleType("PLONG", rffi.LONGP) LPVOID = rffi_platform.SimpleType("LPVOID", rffi.INTP) LPCVOID = rffi_platform.SimpleType("LPCVOID", rffi.VOIDP) LPSTR = rffi_platform.SimpleType("LPSTR", rffi.CCHARP) LPCSTR = rffi_platform.SimpleType("LPCSTR", rffi.CCHARP) LPWSTR = rffi_platform.SimpleType("LPWSTR", rffi.CWCHARP) LPCWSTR = rffi_platform.SimpleType("LPCWSTR", rffi.CWCHARP) LPDWORD = rffi_platform.SimpleType("LPDWORD", rffi.UINTP) LPWORD = rffi_platform.SimpleType("LPWORD", rffi.USHORTP) LPBOOL = rffi_platform.SimpleType("LPBOOL", rffi.LONGP) LPBYTE = rffi_platform.SimpleType("LPBYTE", rffi.UCHARP) SIZE_T = rffi_platform.SimpleType("SIZE_T", rffi.SIZE_T) ULONG_PTR = rffi_platform.SimpleType("ULONG_PTR", rffi.ULONG) HRESULT = rffi_platform.SimpleType("HRESULT", rffi.LONG) HLOCAL = rffi_platform.SimpleType("HLOCAL", rffi.VOIDP) FILETIME = rffi_platform.Struct('FILETIME', [('dwLowDateTime', rffi.UINT), ('dwHighDateTime', rffi.UINT)]) SYSTEMTIME = rffi_platform.Struct('SYSTEMTIME', []) Struct = rffi_platform.Struct COORD = Struct("COORD", [("X", rffi.SHORT), ("Y", rffi.SHORT)]) SMALL_RECT = Struct("SMALL_RECT", [("Left", rffi.SHORT), ("Top", rffi.SHORT), ("Right", rffi.SHORT), ("Bottom", rffi.SHORT)]) CONSOLE_SCREEN_BUFFER_INFO = Struct("CONSOLE_SCREEN_BUFFER_INFO", [("dwSize", COORD), ("dwCursorPosition", COORD), ("wAttributes", WORD.ctype_hint), ("srWindow", SMALL_RECT), ("dwMaximumWindowSize", COORD)]) OSVERSIONINFOEX = rffi_platform.Struct('OSVERSIONINFOEX', [ ('dwOSVersionInfoSize', rffi.UINT), ('dwMajorVersion', rffi.UINT), ('dwMinorVersion', rffi.UINT), ('dwBuildNumber', rffi.UINT), ('dwPlatformId', rffi.UINT), ('szCSDVersion', rffi.CFixedArray(lltype.Char, 1)), ('wServicePackMajor', rffi.USHORT), ('wServicePackMinor', rffi.USHORT), ('wSuiteMask', rffi.USHORT), ('wProductType', rffi.UCHAR), ]) LPSECURITY_ATTRIBUTES = rffi_platform.SimpleType( "LPSECURITY_ATTRIBUTES", rffi.CCHARP) DEFAULT_LANGUAGE = rffi_platform.ConstantInteger( "MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)") defines = """FORMAT_MESSAGE_ALLOCATE_BUFFER FORMAT_MESSAGE_FROM_SYSTEM MAX_PATH _MAX_ENV FORMAT_MESSAGE_IGNORE_INSERTS WAIT_OBJECT_0 WAIT_TIMEOUT INFINITE ERROR_INVALID_HANDLE DELETE READ_CONTROL SYNCHRONIZE WRITE_DAC WRITE_OWNER PROCESS_ALL_ACCESS PROCESS_CREATE_PROCESS PROCESS_CREATE_THREAD PROCESS_DUP_HANDLE PROCESS_QUERY_INFORMATION PROCESS_SET_QUOTA PROCESS_SUSPEND_RESUME PROCESS_TERMINATE PROCESS_VM_OPERATION PROCESS_VM_READ PROCESS_VM_WRITE CTRL_C_EVENT CTRL_BREAK_EVENT MB_ERR_INVALID_CHARS ERROR_NO_UNICODE_TRANSLATION WC_NO_BEST_FIT_CHARS STD_INPUT_HANDLE STD_OUTPUT_HANDLE STD_ERROR_HANDLE HANDLE_FLAG_INHERIT FILE_TYPE_CHAR LOAD_WITH_ALTERED_SEARCH_PATH CT_CTYPE3 C3_HIGHSURROGATE CP_ACP CP_UTF8 CP_UTF7 CP_OEMCP MB_ERR_INVALID_CHARS """ from rpython.translator.platform import host_factory static_platform = host_factory() if static_platform.name == 'msvc': defines += ' PROCESS_QUERY_LIMITED_INFORMATION' for name in defines.split(): locals()[name] = rffi_platform.ConstantInteger(name)
class CConfig: _compilation_info_ = eci if WIN32: DWORD_PTR = rffi_platform.SimpleType("DWORD_PTR", rffi.LONG) WORD = rffi_platform.SimpleType("WORD", rffi.UINT) DWORD = rffi_platform.SimpleType("DWORD", rffi.UINT) BOOL = rffi_platform.SimpleType("BOOL", rffi.LONG) BYTE = rffi_platform.SimpleType("BYTE", rffi.UCHAR) WCHAR = rffi_platform.SimpleType("WCHAR", rffi.UCHAR) INT = rffi_platform.SimpleType("INT", rffi.INT) LONG = rffi_platform.SimpleType("LONG", rffi.LONG) PLONG = rffi_platform.SimpleType("PLONG", rffi.LONGP) LPVOID = rffi_platform.SimpleType("LPVOID", rffi.INTP) LPCVOID = rffi_platform.SimpleType("LPCVOID", rffi.VOIDP) LPSTR = rffi_platform.SimpleType("LPSTR", rffi.CCHARP) LPCSTR = rffi_platform.SimpleType("LPCSTR", rffi.CCHARP) LPWSTR = rffi_platform.SimpleType("LPWSTR", rffi.CWCHARP) LPCWSTR = rffi_platform.SimpleType("LPCWSTR", rffi.CWCHARP) LPDWORD = rffi_platform.SimpleType("LPDWORD", rffi.UINTP) SIZE_T = rffi_platform.SimpleType("SIZE_T", rffi.SIZE_T) ULONG_PTR = rffi_platform.SimpleType("ULONG_PTR", rffi.ULONG) HRESULT = rffi_platform.SimpleType("HRESULT", rffi.LONG) HLOCAL = rffi_platform.SimpleType("HLOCAL", rffi.VOIDP) FILETIME = rffi_platform.Struct('FILETIME', [('dwLowDateTime', rffi.UINT), ('dwHighDateTime', rffi.UINT)]) SYSTEMTIME = rffi_platform.Struct('SYSTEMTIME', []) OSVERSIONINFOEX = rffi_platform.Struct( 'OSVERSIONINFOEX', [('dwOSVersionInfoSize', rffi.UINT), ('dwMajorVersion', rffi.UINT), ('dwMinorVersion', rffi.UINT), ('dwBuildNumber', rffi.UINT), ('dwPlatformId', rffi.UINT), ('szCSDVersion', rffi.CFixedArray(lltype.Char, 1)), ('wServicePackMajor', rffi.USHORT), ('wServicePackMinor', rffi.USHORT), ('wSuiteMask', rffi.USHORT), ('wProductType', rffi.UCHAR), ]) LPSECURITY_ATTRIBUTES = rffi_platform.SimpleType( "LPSECURITY_ATTRIBUTES", rffi.CCHARP) DEFAULT_LANGUAGE = rffi_platform.ConstantInteger( "MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)") defines = """FORMAT_MESSAGE_ALLOCATE_BUFFER FORMAT_MESSAGE_FROM_SYSTEM MAX_PATH _MAX_ENV FORMAT_MESSAGE_IGNORE_INSERTS WAIT_OBJECT_0 WAIT_TIMEOUT INFINITE ERROR_INVALID_HANDLE DELETE READ_CONTROL SYNCHRONIZE WRITE_DAC WRITE_OWNER PROCESS_ALL_ACCESS PROCESS_CREATE_PROCESS PROCESS_CREATE_THREAD PROCESS_DUP_HANDLE PROCESS_QUERY_INFORMATION PROCESS_SET_QUOTA PROCESS_SUSPEND_RESUME PROCESS_TERMINATE PROCESS_VM_OPERATION PROCESS_VM_READ PROCESS_VM_WRITE CTRL_C_EVENT CTRL_BREAK_EVENT MB_ERR_INVALID_CHARS ERROR_NO_UNICODE_TRANSLATION WC_NO_BEST_FIT_CHARS """ from rpython.translator.platform import host_factory static_platform = host_factory() if static_platform.name == 'msvc': defines += ' PROCESS_QUERY_LIMITED_INFORMATION' for name in defines.split(): locals()[name] = rffi_platform.ConstantInteger(name)
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.""" # 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 rpython.translator.platform import host_factory static_platform = host_factory() 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> #include <WinError.h> #include <stdio.h> #ifdef __GNUC__ #define _dosmaperr mingw_dosmaperr #endif int main() { int i; for(i=1; i < 65000; i++) { _dosmaperr(i); if (errno == EINVAL) { /* CPython issue #12802 */ if (i == ERROR_DIRECTORY) errno = ENOTDIR; else continue; } printf("%d\t%d\n", i, errno); } return 0; }''') try: exename = static_platform.compile( [cfile], ExternalCompilationInfo(), outputfilename = "dosmaperr", standalone=True) except (CompilationError, WindowsError): # Fallback for the mingw32 compiler assert static_platform.name == 'mingw32' errors = { 2: 2, 3: 2, 4: 24, 5: 13, 6: 9, 7: 12, 8: 12, 9: 12, 10: 7, 11: 8, 15: 2, 16: 13, 17: 18, 18: 2, 19: 13, 20: 13, 21: 13, 22: 13, 23: 13, 24: 13, 25: 13, 26: 13, 27: 13, 28: 13, 29: 13, 30: 13, 31: 13, 32: 13, 33: 13, 34: 13, 35: 13, 36: 13, 53: 2, 65: 13, 67: 2, 80: 17, 82: 13, 83: 13, 89: 11, 108: 13, 109: 32, 112: 28, 114: 9, 128: 10, 129: 10, 130: 9, 132: 13, 145: 41, 158: 13, 161: 2, 164: 11, 167: 13, 183: 17, 188: 8, 189: 8, 190: 8, 191: 8, 192: 8, 193: 8, 194: 8, 195: 8, 196: 8, 197: 8, 198: 8, 199: 8, 200: 8, 201: 8, 202: 8, 206: 2, 215: 11, 267: 20, 1816: 12, } else: output = os.popen(str(exename)) errors = dict(map(int, line.split()) for line in output) return errors, errno.EINVAL