diff -ur Python-3.1.3/Modules/_ctypes/callproc.c Python-3.1.3.fix_mingw_compile/Modules/_ctypes/callproc.c --- Python-3.1.3/Modules/_ctypes/callproc.c 2010-05-09 18:14:21.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/Modules/_ctypes/callproc.c 2010-12-03 11:47:24.369544339 +0100 @@ -760,7 +760,7 @@ int *space; ffi_cif cif; int cc; -#ifdef MS_WIN32 +#if defined(MS_WIN32) && defined(_MSC_VER) int delta; #ifndef DONT_USE_SEH DWORD dwExceptionCode = 0; @@ -812,8 +812,10 @@ #ifndef DONT_USE_SEH __try { #endif +#ifdef _MSC_VER delta = #endif +#endif ffi_call(&cif, (void *)pProc, resmem, avalues); #ifdef MS_WIN32 #ifndef DONT_USE_SEH @@ -839,7 +841,7 @@ if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS #endif -#ifdef MS_WIN32 +#if defined(MS_WIN32) && defined(_MSC_VER) #ifndef DONT_USE_SEH if (dwExceptionCode) { SetException(dwExceptionCode, &record); diff -ur Python-3.1.3/Modules/_pickle.c Python-3.1.3.fix_mingw_compile/Modules/_pickle.c --- Python-3.1.3/Modules/_pickle.c 2010-09-04 20:46:56.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/Modules/_pickle.c 2010-12-02 11:31:56.525863107 +0100 @@ -19,11 +19,11 @@ POP = '0', POP_MARK = '1', DUP = '2', - FLOAT = 'F', - INT = 'I', + _FLOAT = 'F', + _INT = 'I', BININT = 'J', BININT1 = 'K', - LONG = 'L', + _LONG = 'L', BININT2 = 'M', NONE = 'N', PERSID = 'P', @@ -859,7 +859,7 @@ /* Text-mode pickle, or long too big to fit in the 4-byte * signed BININT format: store as a string. */ - pdata[0] = LONG; /* use LONG for consistency with pickle.py */ + pdata[0] = _LONG; /* use _LONG for consistency with pickle.py */ PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, "%ldL\n", x); if (pickler_write(self, pdata, strlen(pdata)) < 0) return -1; @@ -901,7 +901,7 @@ long val = PyLong_AsLong(obj); int status = 0; - const char long_op = LONG; + const char long_op = _LONG; if (val == -1 && PyErr_Occurred()) { /* out of range for int pickling */ @@ -1033,7 +1033,7 @@ else { int result = -1; char *buf = NULL; - char op = FLOAT; + char op = _FLOAT; if (pickler_write(self, &op, 1) < 0) goto done; @@ -4327,11 +4327,11 @@ OP(BININT, load_binint) OP(BININT1, load_binint1) OP(BININT2, load_binint2) - OP(INT, load_int) - OP(LONG, load_long) + OP(_INT, load_int) + OP(_LONG, load_long) OP_ARG(LONG1, load_counted_long, 1) OP_ARG(LONG4, load_counted_long, 4) - OP(FLOAT, load_float) + OP(_FLOAT, load_float) OP(BINFLOAT, load_binfloat) OP(BINBYTES, load_binbytes) OP(SHORT_BINBYTES, load_short_binbytes) diff -ur Python-3.1.3/Modules/posixmodule.c Python-3.1.3.fix_mingw_compile/Modules/posixmodule.c --- Python-3.1.3/Modules/posixmodule.c 2010-11-26 18:04:40.000000000 +0100 +++ Python-3.1.3.fix_mingw_compile/Modules/posixmodule.c 2010-12-03 10:56:26.477889661 +0100 @@ -119,7 +119,7 @@ #define HAVE_SYSTEM 1 #define HAVE_WAIT 1 #else -#ifdef _MSC_VER /* Microsoft compiler */ +#if defined(_MSC_VER) || defined(__MINGW32__) /* Microsoft or MinGW compiler */ #define HAVE_GETCWD 1 #define HAVE_SPAWNV 1 #define HAVE_EXECV 1 @@ -168,7 +168,7 @@ #if defined(PYCC_VACPP) extern int mkdir(char *); #else -#if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__) +#if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) ) && !defined(__QNX__) extern int mkdir(const char *); #else extern int mkdir(const char *, mode_t); @@ -252,7 +252,7 @@ #endif #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) #ifdef HAVE_DIRECT_H #include #endif @@ -265,6 +265,7 @@ #include "osdefs.h" #include #include +#include /* for HCRYPTPROV etc. */ #include /* for ShellExecute() */ #endif /* _MSC_VER */ @@ -7653,7 +7654,7 @@ } -#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__) +#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__) #define INITFUNC PyInit_nt #define MODNAME "nt" diff -ur Python-3.1.3/Modules/signalmodule.c Python-3.1.3.fix_mingw_compile/Modules/signalmodule.c --- Python-3.1.3/Modules/signalmodule.c 2010-11-05 20:54:58.000000000 +0100 +++ Python-3.1.3.fix_mingw_compile/Modules/signalmodule.c 2010-12-02 11:12:09.705362982 +0100 @@ -7,7 +7,7 @@ #include "intrcheck.h" #ifdef MS_WINDOWS -#include +#include #ifdef HAVE_PROCESS_H #include #endif diff -ur Python-3.1.3/Modules/socketmodule.h Python-3.1.3.fix_mingw_compile/Modules/socketmodule.h --- Python-3.1.3/Modules/socketmodule.h 2010-08-28 22:53:24.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/Modules/socketmodule.h 2010-12-03 13:20:37.541461431 +0100 @@ -13,6 +13,17 @@ # endif #else /* MS_WINDOWS */ + +/* MinGW/win32api headers don't define SIO_KEEPALIVE_VALS */ +#ifndef SIO_KEEPALIVE_VALS +# define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4) +struct tcp_keepalive { + ULONG onoff; + ULONG keepalivetime; + ULONG keepaliveinterval; +}; +#endif + # include # include /* VC6 is shipped with old platform headers, and does not have MSTcpIP.h diff -ur Python-3.1.3/PC/msvcrtmodule.c Python-3.1.3.fix_mingw_compile/PC/msvcrtmodule.c --- Python-3.1.3/PC/msvcrtmodule.c 2010-09-04 23:02:41.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/PC/msvcrtmodule.c 2010-12-03 13:20:49.449889518 +0100 @@ -21,7 +21,9 @@ #include #include #include +#ifndef __MINGW32__ #include +#endif #include #ifdef _MSC_VER diff -ur Python-3.1.3/PC/winreg.c Python-3.1.3.fix_mingw_compile/PC/winreg.c --- Python-3.1.3/PC/winreg.c 2010-06-08 23:00:35.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/PC/winreg.c 2010-12-03 10:40:34.345389898 +0100 @@ -22,6 +22,15 @@ static char errNotAHandle[] = "Object is not a handle"; +/* MinGW/win32api headers don't define REG_LEGAL_CHANGE_FILTER */ +#ifndef REG_LEGAL_CHANGE_FILTER +#define REG_LEGAL_CHANGE_FILTER \ + (REG_NOTIFY_CHANGE_NAME | \ + REG_NOTIFY_CHANGE_ATTRIBUTES | \ + REG_NOTIFY_CHANGE_LAST_SET | \ + REG_NOTIFY_CHANGE_SECURITY) +#endif + /* The win32api module reports the function name that failed, but this concept is not in the Python core. Hopefully it will one day, and in the meantime I dont diff -ur Python-3.1.3/Python/dynload_win.c Python-3.1.3.fix_mingw_compile/Python/dynload_win.c --- Python-3.1.3/Python/dynload_win.c 2010-05-09 18:14:21.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/Python/dynload_win.c 2010-12-02 11:11:55.089863062 +0100 @@ -28,7 +28,7 @@ /* Case insensitive string compare, to avoid any dependencies on particular C RTL implementations */ -static int strcasecmp (char *string1, char *string2) +static int my_strcasecmp (char *string1, char *string2) { int first, second; @@ -261,7 +261,7 @@ import_python = GetPythonImport(hDLL); if (import_python && - strcasecmp(buffer,import_python)) { + my_strcasecmp(buffer,import_python)) { PyOS_snprintf(buffer, sizeof(buffer), "Module use of %.150s conflicts " "with this version of Python.", diff -ur Python-3.1.3/Python/pythonrun.c Python-3.1.3.fix_mingw_compile/Python/pythonrun.c --- Python-3.1.3/Python/pythonrun.c 2010-10-30 17:43:30.000000000 +0200 +++ Python-3.1.3.fix_mingw_compile/Python/pythonrun.c 2010-12-03 10:49:01.725889851 +0100 @@ -28,8 +28,11 @@ #include "malloc.h" /* for alloca */ #endif -#ifdef HAVE_LANGINFO_H +#ifdef HAVE_SETLOCALE #include +#endif + +#ifdef HAVE_LANGINFO_H #include #endif