diff -urN a/configure.ac b/configure.ac --- a/configure.ac 2012-05-30 07:33:00.806145441 +0100 +++ b/configure.ac 2012-05-30 07:37:26.345967474 +0100 @@ -378,6 +378,10 @@ dnl - but an item in PYTHONPATH is "plat-win" !!! oops MACHDEP=win ;; + *-*-darwin*) + ac_sys_system=ignore + MACHDEP=darwin + ;; esac fi if test -z "$MACHDEP" @@ -423,7 +427,7 @@ '') MACHDEP="unknown";; esac fi - + # Some systems cannot stand _XOPEN_SOURCE being defined at all; they # disable features if it is defined, without any means to access these # features as extensions. For these systems, we skip the definition of @@ -541,6 +545,27 @@ fi AC_MSG_RESULT($MACHDEP) +# Windows uses ; to separate paths, everything else uses : +AC_MSG_CHECKING(DELIM) +DELIM=: +if test "$MACHDEP" = "win" +then + DELIM=\; +fi +AC_MSG_RESULT([$DELIM]) +AC_SUBST(DELIM) + +# MSYS make uses a 'virtual' VPATH, but getpath.c uses +# GetModuleFileNameW (replacing \ with /). This allows the user to +# define the 'actual 'real' value. Note, it should contain / not \, +# which is what is returned by "pwd -W". +AC_ARG_VAR(MSYSVPATH, + For MSYS, allows specifying the real VPATH. Use / not \) +if test -z "$MSYSVPATH"; then + MSYSVPATH=$srcdir +fi +AC_SUBST(MSYSVPATH) + AC_MSG_CHECKING([for init system calls]) AC_SUBST(INITSYS) case $host in @@ -2817,7 +2842,7 @@ AC_MSG_CHECKING(MACHDEP_OBJS) case $host in *-*-mingw*) - extra_machdep_objs="PC/dl_nt.o PC/getpathp.o PC/import_nt.o" + extra_machdep_objs="PC/dl_nt.o Modules/getpath.o PC/import_nt.o" ;; esac if test -z "$MACHDEP_OBJS" @@ -4064,6 +4089,28 @@ # check for endianness AC_C_BIGENDIAN +# REPARSE_DATA_BUFFER is in winnt.h on mingw32 and (unusably) ddk/ntifs.h on mingw64. +case $host in + *-*-mingw*) +AC_CACHE_CHECK([if struct REPARSE_DATA_BUFFER is in winnt.h], +[ac_cv_struct_reparse_data_buffer_in_winnt_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [#include + #include ], + [REPARSE_DATA_BUFFER rdb], + )], + [ac_cv_struct_reparse_data_buffer_in_winnt_h=yes], + [ac_cv_struct_reparse_data_buffer_in_winnt_h=no] + ) +]) +if test "x${ac_cv_struct_reparse_data_buffer_in_winnt_h}" = xyes; then + AC_DEFINE([REPARSE_DATA_BUFFER_IN_WINNT], [], [REPARSE_DATA_BUFFER in winnt.h]) + AC_SUBST(REPARSE_DATA_BUFFER_IN_WINNT) +fi + ;; +esac + # ABI version string for Python extension modules. This appears between the # periods in shared library file names, e.g. foo..so. It is calculated # from the following attributes which affect the ABI of this Python build (in @@ -4793,7 +4840,8 @@ # FIXME: why windows builds don't use PC/frozen_dllmain.o ? PYTHON_OBJS_FROZENMAIN="" # default sys.path calculations for windows platforms - MODULE_GETPATH=PC/getpathp.o + # MODULE_GETPATH=PC/getpathp.o + MODULE_GETPATH=Modules/getpath.o ;; esac diff -urN a/Include/fileutils.h b/Include/fileutils.h --- a/Include/fileutils.h 2012-04-01 12:50:09.000000000 +0100 +++ b/Include/fileutils.h 2012-05-30 07:33:02.933054690 +0100 @@ -15,7 +15,7 @@ const wchar_t *text, size_t *error_pos); -#if defined(HAVE_STAT) && !defined(MS_WINDOWS) +#if defined(HAVE_STAT) && (!defined(MS_WINDOWS) || defined(__MINGW32__)) PyAPI_FUNC(int) _Py_wstat( const wchar_t* path, struct stat *buf); diff -urN a/Include/osdefs.h b/Include/osdefs.h --- a/Include/osdefs.h 2012-04-01 12:50:09.000000000 +0100 +++ b/Include/osdefs.h 2012-05-30 07:33:03.320855811 +0100 @@ -10,7 +10,7 @@ /* Mod by chrish: QNX has WATCOM, but isn't DOS */ #if !defined(__QNX__) #if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2) -#if defined(PYOS_OS2) && defined(PYCC_GCC) +#if (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__MINGW32__) #define MAXPATHLEN 260 #define SEP L'/' #define ALTSEP L'\\' diff -urN a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py --- a/Lib/distutils/cygwinccompiler.py 2012-05-30 07:33:00.234438631 +0100 +++ b/Lib/distutils/cygwinccompiler.py 2012-05-30 07:33:03.320855811 +0100 @@ -392,7 +392,7 @@ return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) -RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)') +RE_VERSION = re.compile(b'[\D\s]*(\d+\.\d+(\.\d+)*)[\D\s]*$') def _find_exe_version(cmd): """Find the version of an executable by running `cmd` in the shell. @@ -420,5 +420,14 @@ If not possible it returns None for it. """ - commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version'] + gcc = os.environ.get('CC') or 'gcc' + ld = 'ld' + out = Popen(gcc+' --print-prog-name ld', shell=True, stdout=PIPE).stdout + try: + ld = test=str(out.read(),encoding='utf-8').strip() + finally: + out.close() + dllwrap = os.environ.get('DLLWRAP') or 'dllwrap' + # MinGW64 doesn't have i686-w64-mingw32-ld, so instead we ask gcc. + commands = [gcc+' -dumpversion', ld+' -v', dllwrap+' --version'] return tuple([_find_exe_version(cmd) for cmd in commands]) diff -urN a/Lib/plat-generic/regen b/Lib/plat-generic/regen --- a/Lib/plat-generic/regen 2012-04-01 12:50:13.000000000 +0100 +++ b/Lib/plat-generic/regen 2012-05-30 07:33:03.320855811 +0100 @@ -1,3 +1,9 @@ #! /bin/sh set -v -python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h +if [ -n $1 ]; then + CCINSTALL=$($1 -print-search-dirs | head -1 | cut -d' ' -f2) + REGENHEADER=$CCINSTALL/include/stddef.h +else + REGENHEADER=/usr/include/netinet/in.h +fi +python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' $REGENHEADER diff -urN a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in 2012-05-30 07:33:00.794151594 +0100 +++ b/Makefile.pre.in 2012-05-30 07:33:03.320855811 +0100 @@ -27,6 +27,7 @@ VERSION= @VERSION@ srcdir= @srcdir@ VPATH= @srcdir@ +MSYSVPATH= @MSYSVPATH@ CC= @CC@ CXX= @CXX@ @@ -88,7 +89,8 @@ # C flags used for building the interpreter object files PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE - +# ; on Windows otherwise : +DELIM= @DELIM@ # Machine-dependent subdirectories MACHDEP= @MACHDEP@ @@ -611,7 +613,7 @@ -DPREFIX='"$(prefix)"' \ -DEXEC_PREFIX='"$(exec_prefix)"' \ -DVERSION='"$(VERSION)"' \ - -DVPATH='"$(VPATH)"' \ + -DVPATH='"$(MSYSVPATH)"' \ -o $@ $(srcdir)/Modules/getpath.c # default sys.path calculations for windows platforms @@ -1134,7 +1136,7 @@ export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \ export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \ export EXE; EXE="$(BUILDEXE)"; \ - cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen + cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen $(CC) python-config: $(srcdir)/Misc/python-config.in # Substitution happens here, as the completely-expanded BINDIR diff -urN a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c 2012-05-30 07:33:00.798149543 +0100 +++ b/Modules/faulthandler.c 2012-05-30 07:33:03.320855811 +0100 @@ -856,7 +856,15 @@ #ifdef MS_WINDOWS /* configure abort() to not display an error message nor open a popup asking to report the fault. */ -#ifdef _WRITE_ABORT_MSG + + /* + On mingw64 _set_abort_behavior is broken: + undefined reference to `__imp___set_abort_behavior' + So re-use detection of REPARSE_DATA_BUFFER as a way of distingishing + between mingw32 and mingw64 and disabling this call on mingw64. + Can get it to link ok if add -lmsvcr90 and distribute msvcrt100.dll + but don't want to go there. */ +#if defined(_WRITE_ABORT_MSG) && (!defined(__MINGW32__) || defined(REPARSE_DATA_BUFFER_IN_WINNT)) /* mingw define for CRT >= 8.0 */ _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); #endif diff -urN a/Modules/getpath.c b/Modules/getpath.c --- a/Modules/getpath.c 2012-04-01 12:50:20.000000000 +0100 +++ b/Modules/getpath.c 2012-05-30 07:33:03.492767650 +0100 @@ -10,6 +10,10 @@ #include #endif +#ifdef MS_WINDOWS +#include +#endif + /* Search in some common locations for the associated Python libraries. * * Two directories must be found, the platform independent directory @@ -133,6 +137,10 @@ static wchar_t prefix[MAXPATHLEN+1]; static wchar_t exec_prefix[MAXPATHLEN+1]; static wchar_t progpath[MAXPATHLEN+1]; +#ifdef MS_WINDOWS +static wchar_t dllpath[MAXPATHLEN+1]; +extern HANDLE PyWin_DLLhModule; +#endif static wchar_t *module_search_path = NULL; static int module_search_path_malloced = 0; static wchar_t *lib_python = L"lib/python" VERSION; @@ -143,7 +151,7 @@ size_t i = wcslen(dir); while (i > 0 && dir[i] != SEP) --i; - dir[i] = '\0'; + dir[i] = 0; } static int @@ -213,7 +221,11 @@ joinpath(wchar_t *buffer, wchar_t *stuff) { size_t n, k; +#ifdef MS_WINDOWS + if (stuff[0] == SEP || (stuff[0] != 0 && stuff[1] == L':')) +#else if (stuff[0] == SEP) +#endif n = 0; else { n = wcslen(buffer); @@ -234,7 +246,11 @@ static void copy_absolute(wchar_t *path, wchar_t *p, size_t pathlen) { +#ifdef MS_WINDOWS + if (p[0] == SEP || (p[0] != 0 && p[1] == L':')) +#else if (p[0] == SEP) +#endif wcscpy(path, p); else { if (!_Py_wgetcwd(path, pathlen)) { @@ -254,7 +270,11 @@ { wchar_t buffer[MAXPATHLEN+1]; +#ifdef MS_WINDOWS + if (path[0] == SEP || (path[0] != 0 && path[1] == L':')) +#else if (path[0] == SEP) +#endif return; copy_absolute(buffer, path, MAXPATHLEN+1); wcscpy(path, buffer); @@ -398,6 +418,35 @@ return 0; } +#ifdef MS_WINDOWS +/* Calculates dllpath and progpath, replacing \\ with / */ +int GetWindowsModulePaths() +{ + int result = 0; + wchar_t* seps; + result = GetModuleFileNameW(NULL, progpath, MAXPATHLEN); + seps = wcschr(progpath, L'\\'); + while(seps) { + *seps = L'/'; + seps = wcschr(seps, L'\\'); + } + dllpath[0] = 0; +#ifdef Py_ENABLE_SHARED + if (PyWin_DLLhModule) { + if((GetModuleFileNameW(PyWin_DLLhModule, dllpath, MAXPATHLEN) > 0)) { + result = 1; + seps = wcschr(dllpath, L'\\'); + while(seps) { + *seps = L'/'; + seps = wcschr(seps, L'\\'); + } + } + } +#endif + return result; +} +#endif /* MS_WINDOWS */ + static void calculate_path(void) { @@ -473,6 +522,10 @@ } } #endif /* __APPLE__ */ +#ifdef MS_WINDOWS + else if(GetWindowsModulePaths()) { + } +#endif /* MS_WINDOWS */ else if (path) { while (1) { wchar_t *delim = wcschr(path, DELIM); @@ -502,7 +555,11 @@ progpath[0] = '\0'; if (path_buffer != NULL) PyMem_Free(path_buffer); +#ifdef MS_WINDOWS + if (progpath[0] != '\0' && progpath[0] != SEP && progpath[1] != L':') +#else if (progpath[0] != SEP && progpath[0] != '\0') +#endif absolutize(progpath); wcsncpy(argv0_path, progpath, MAXPATHLEN); argv0_path[MAXPATHLEN] = '\0'; @@ -779,7 +836,43 @@ } -#ifdef __cplusplus +#ifdef MS_WINDOWS +/* Load python3.dll before loading any extension module that might refer + to it. That way, we can be sure that always the python3.dll corresponding + to this python DLL is loaded, not a python3.dll that might be on the path + by chance. + Return whether the DLL was found. +*/ +static int python3_checked = 0; +static HANDLE hPython3; +int +_Py_CheckPython3() +{ + wchar_t py3path[MAXPATHLEN+1]; + wchar_t *s; + if (python3_checked) + return hPython3 != NULL; + python3_checked = 1; + + /* If there is a python3.dll next to the python3y.dll, + assume this is a build tree; use that DLL */ + wcscpy(py3path, dllpath); + s = wcsrchr(py3path, L'\\'); + if (!s) + s = py3path; + wcscpy(s, L"\\python3.dll"); + hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (hPython3 != NULL) + return 1; + + /* Check sys.prefix\DLLs\python3.dll */ + wcscpy(py3path, Py_GetPrefix()); + wcscat(py3path, L"\\DLLs\\python3.dll"); + hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + return hPython3 != NULL; } #endif +#ifdef __cplusplus +} +#endif diff -urN a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c 2012-05-30 07:33:00.798149543 +0100 +++ b/Modules/posixmodule.c 2012-05-30 07:33:03.668677436 +0100 @@ -415,7 +415,7 @@ #endif /* A helper used by a number of POSIX-only functions */ -#ifndef MS_WINDOWS +#if !defined(MS_WINDOWS) || defined(__MINGW32__) static int _parse_off_t(PyObject* arg, void* addr) { @@ -524,7 +524,7 @@ #endif #ifdef MS_WINDOWS -#if !defined(__MINGW32__) +#if !defined(__MINGW32__) || !defined(REPARSE_DATA_BUFFER_IN_WINNT) /* The following structure was copied from http://msdn.microsoft.com/en-us/library/ms791514.aspx as the required include doesn't seem to be present in the Windows SDK (at least as included @@ -560,6 +560,10 @@ #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER,\ GenericReparseBuffer) #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 ) +#else /*!defined(__MINGW32__)*/ +#if defined(REPARSE_DATA_BUFFER_IN_WINNT) +#include +#endif /*defined(REPARSE_DATA_BUFFER_IN_WINNT)*/ #endif /*!defined(__MINGW32__)*/ static int diff -urN a/Modules/Setup.config.in b/Modules/Setup.config.in --- a/Modules/Setup.config.in 2012-05-30 07:33:00.794151594 +0100 +++ b/Modules/Setup.config.in 2012-05-30 07:33:03.320855811 +0100 @@ -15,6 +15,9 @@ # On win32 host(mingw build in MSYS environment) show that site.py # fail to load if some modules are not build-in: @BUILDIN_WIN32_MODULE@winreg ../PC/winreg.c +@BUILDIN_WIN32_MODULE@time timemodule.c +@BUILDIN_WIN32_MODULE@_subprocess ../PC/_subprocess.c +@BUILDIN_WIN32_MODULE@msvcrt ../PC/msvcrtmodule.c # The rest of the modules previously listed in this file are built diff -urN a/Modules/Setup.dist b/Modules/Setup.dist --- a/Modules/Setup.dist 2012-05-30 07:33:00.794151594 +0100 +++ b/Modules/Setup.dist 2012-05-30 07:33:03.320855811 +0100 @@ -84,14 +84,14 @@ # Empty since this is now just the runtime prefix. DESTPATH= -# Site specific path components -- should begin with : if non-empty +# Site specific path components -- should begin with $(DELIM) if non-empty SITEPATH= # Standard path components for test modules TESTPATH= # Path components for machine- or system-dependent modules and shared libraries -MACHDEPPATH=:plat-$(MACHDEP) +MACHDEPPATH=$(DELIM)plat-$(MACHDEP) EXTRAMACHDEPPATH= COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(EXTRAMACHDEPPATH) diff -urN a/Modules/socketmodule.h b/Modules/socketmodule.h --- a/Modules/socketmodule.h 2012-05-30 07:33:00.802147492 +0100 +++ b/Modules/socketmodule.h 2012-05-30 07:33:05.007990590 +0100 @@ -28,7 +28,7 @@ * I use SIO_GET_MULTICAST_FILTER to detect a decent SDK. */ # ifdef SIO_GET_MULTICAST_FILTER -# include /* for SIO_RCVALL */ +# include /* for SIO_RCVALL */ # define HAVE_ADDRINFO # define HAVE_SOCKADDR_STORAGE # define HAVE_GETADDRINFO diff -urN a/Parser/metagrammar.c b/Parser/metagrammar.c --- a/Parser/metagrammar.c 2012-04-01 12:50:23.000000000 +0100 +++ b/Parser/metagrammar.c 2012-05-30 07:33:05.007990590 +0100 @@ -139,7 +139,7 @@ {7, 0}, {8, 0}, }; -static grammar _PyParser_Grammar = { +static grammar _PyParser_MetaGrammar = { 6, dfas, {19, labels}, @@ -149,7 +149,7 @@ grammar * meta_grammar(void) { - return &_PyParser_Grammar; + return &_PyParser_MetaGrammar; } grammar * diff -urN a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c --- a/PC/msvcrtmodule.c 2012-05-30 07:33:00.802147492 +0100 +++ b/PC/msvcrtmodule.c 2012-05-30 07:33:05.007990590 +0100 @@ -21,9 +21,7 @@ #include #include #include -#if !defined(__MINGW32__) #include -#endif #include #if defined(__MINGW32__) diff -urN a/Python/fileutils.c b/Python/fileutils.c --- a/Python/fileutils.c 2012-04-01 12:50:23.000000000 +0100 +++ b/Python/fileutils.c 2012-05-30 07:33:05.007990590 +0100 @@ -251,7 +251,7 @@ Not sure whether the MS_WINDOWS guards are necessary: perhaps for cygwin/mingw builds? */ -#if defined(HAVE_STAT) && !defined(MS_WINDOWS) +#if defined(HAVE_STAT) && (!defined(MS_WINDOWS) || defined(__MINGW32__)) /* Get file status. Encode the path to the locale encoding. */ diff -urN a/Python/pythonrun.c b/Python/pythonrun.c --- a/Python/pythonrun.c 2012-04-01 12:50:24.000000000 +0100 +++ b/Python/pythonrun.c 2012-05-30 07:33:05.007990590 +0100 @@ -722,6 +722,13 @@ void Py_SetProgramName(wchar_t *pn) { +#ifdef __MINGW32__ + wchar_t* seps = wcschr(pn, ALTSEP); + while(seps) { + *seps = SEP; + seps = wcschr(seps, ALTSEP); + } +#endif if (pn && *pn) progname = pn; } diff -urN a/setup.py b/setup.py --- a/setup.py 2012-05-30 07:33:00.806145441 +0100 +++ b/setup.py 2012-05-30 07:33:05.011988540 +0100 @@ -899,7 +899,8 @@ for p in ['msvcrtmodule.c']]) ) exts.append( Extension('_msi', [os.path.join(pc_srcdir, p) - for p in ['_msi.c']]) ) + for p in ['_msi.c']], + libraries=['msi','cabinet','rpcrt4']) ) # To link with lib(msi|cabinet|rpcrt4).a exts.append( Extension('_subprocess', [os.path.join(pc_srcdir, p) for p in ['_subprocess.c']]) ) @@ -2053,7 +2054,7 @@ 'universal': [('UNIVERSAL','1')] } - platform = self.get_platform() + platform = host_platform cc = sysconfig.get_config_var('CC') sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T') machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')