--- ./PC/_winreg.c.MINGW 2009-06-11 00:08:17.000000000 +0300 +++ ./PC/_winreg.c 2009-06-10 22:03:53.000000000 +0300 @@ -17,6 +17,18 @@ #include "malloc.h" /* for alloca */ #include "windows.h" +#if defined(__MINGW32__) +_CRTIMP size_t __cdecl __MINGW_NOTHROW _mbstrlen(const char *s); +#endif + +#if !defined(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 + static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); static PyObject *PyHKEY_FromHKEY(HKEY h); static BOOL PyHKEY_Close(PyObject *obHandle); --- ./PC/msvcrtmodule.c.MINGW 2009-12-31 15:33:27.000000000 +0200 +++ ./PC/msvcrtmodule.c 2009-12-31 15:33:32.000000000 +0200 @@ -22,6 +22,31 @@ #include #include +#if defined(__MINGW32__) +#if __MSVCRT_VERSION__ >= 0x0700 +# define _WCONIO_DEFINED +/* NOTE: Up to version ?.?? mingw don't define functions + * listed below. Also it require module to be linked with + * ms-vcrt at least verion 7. + * To build with different runtimes see: + * http://www.mingw.org/wiki/HOWTO_Use_the_GCC_specs_file + * + * Also note that NT5.1(XP), shiped with msvcrt version 7.0, + * contain all those functions, but library name is msvcrt.dll. + * So if you like module to run on w2k as is you must define + * appropriate __MSVCRT_VERSION__ . + * If you like those functions even on w2k you must link + * with appropriate runtime and to pack it in distributions. + * This is what MSVC build do - it is build and packed + * with version 9.0 of Microsoft C-runtime. + */ +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _getwch (void); +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _getwche (void); +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _putwch (wchar_t); +_CRTIMP wint_t __cdecl __MINGW_NOTHROW _ungetwch(wint_t); +#endif /* __MSVCRT_VERSION__ >= 0x0700 */ +#endif + #ifdef _MSC_VER #if _MSC_VER >= 1500 #include @@ -343,6 +368,7 @@ if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) return NULL; + /* FIXME: why _ungetch is called instead _ungetwch */ if (_ungetch(ch) == EOF) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); --- ./Lib/distutils/command/build_ext.py.MINGW 2010-01-23 13:39:59.000000000 +0200 +++ ./Lib/distutils/command/build_ext.py 2010-01-23 15:06:08.000000000 +0200 @@ -27,7 +27,8 @@ from site import USER_BASE HAS_USER_SITE = True -if os.name == 'nt': +# GCC(mingw): os.name is "nt" but build system is posix +if os.name == 'nt' and sys.version.find('GCC') < 0: from distutils.msvccompiler import get_build_version MSVC_VERSION = int(get_build_version()) @@ -224,7 +225,8 @@ # for extensions under windows use different directories # for Release and Debug builds. # also Python's library directory must be appended to library_dirs - if os.name == 'nt': + # GCC(mingw): os.name is "nt" but build system is posix + if os.name == 'nt' and sys.version.find('GCC') < 0: # the 'libs' directory is for binary installs - we assume that # must be the *native* platform. But we don't really support # cross-compiling via a binary install anyway, so we let it go. @@ -266,7 +268,8 @@ # for extensions under Cygwin and AtheOS Python's library directory must be # appended to library_dirs - if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': + if (sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos' + or (sys.platform == 'win32' and sys.version.find('GCC') >= 0)): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions self.library_dirs.append(os.path.join(sys.prefix, "lib", @@ -751,6 +754,34 @@ # pyconfig.h that MSVC groks. The other Windows compilers all seem # to need it mentioned explicitly, though, so that's what we do. # Append '_d' to the python import library on debug builds. + + # FIXME: What is purpose of code below ? + # The posix build system khow requred libraries to build a module. + # The libraries are stored in config(Makefile) variables BLDLIBRARY, + # MODLIBS and SHLIBS. Note that some variables may contain linker + # flags. + # NOTE: For now we will check only GCC(mingw) compiler as is clear + # that we build for windows platfrom. + # The code for GCC(mingw) is not correct but this is distutils + # limitation - we has to pass variables to the linker as is + # instead only library names. + if self.compiler_obj.compiler_type == 'mingw32': + _sysconfig = __import__('sysconfig') + template = "python%s" + if self.debug: + template = template + '_d' + extra = [(template % (_sysconfig.get_config_var('VERSION')))] + for lib in _sysconfig.get_config_var('BLDLIBRARY').split(): + if lib.startswith('-l'): + extra.append(lib[2:]) + for lib in _sysconfig.get_config_var('MODLIBS').split(): + if lib.startswith('-l'): + extra.append(lib[2:]) + for lib in _sysconfig.get_config_var('SHLIBS').split(): + if lib.startswith('-l'): + extra.append(lib[2:]) + return ext.libraries + extra + if sys.platform == "win32": from distutils.msvccompiler import MSVCCompiler if not isinstance(self.compiler_obj, MSVCCompiler): --- ./Lib/distutils/command/install.py.MINGW 2010-01-23 11:51:28.000000000 +0200 +++ ./Lib/distutils/command/install.py 2010-01-24 12:51:26.000000000 +0200 @@ -262,6 +262,7 @@ # everything else. self.config_vars['base'] = self.install_base self.config_vars['platbase'] = self.install_platbase + self.config_vars['projectbase'] = get_config_var('projectbase') if DEBUG: from pprint import pprint @@ -407,7 +408,7 @@ for key, value in scheme.items(): if key == 'platinclude': key = 'headers' - value = os.path.join(value, self.distribution.get_name()) + #value = os.path.join(value, self.distribution.get_name()) attrname = 'install_' + key if hasattr(self, attrname): if getattr(self, attrname) is None: --- ./Lib/distutils/tests/test_cygwinccompiler.py.MINGW 2010-01-23 13:07:24.000000000 +0200 +++ ./Lib/distutils/tests/test_cygwinccompiler.py 2010-01-23 13:07:42.000000000 +0200 @@ -62,7 +62,7 @@ # none sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) ' '\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]') - self.assertEquals(get_msvcr(), None) + self.assertEquals(get_msvcr(), []) # MSVC 7.0 sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' --- ./Lib/distutils/tests/test_msvc9compiler.py.MINGW 2009-12-23 11:38:45.000000000 +0200 +++ ./Lib/distutils/tests/test_msvc9compiler.py 2009-12-27 12:36:38.000000000 +0200 @@ -109,7 +109,11 @@ self.assertTrue('Desktop' in keys) def test_remove_visual_c_ref(self): - from distutils.msvc9compiler import MSVCCompiler + try: + from distutils.msvc9compiler import MSVCCompiler + except DistutilsPlatformError: + # FIXME: this test is only for MSVC X.Y(?) or above + raise unittest.SkipTest, "manifest not supported" tempdir = self.mkdtemp() manifest = os.path.join(tempdir, 'manifest') f = open(manifest, 'w') --- ./Lib/distutils/tests/test_install.py.MINGW 2010-01-23 11:51:27.000000000 +0200 +++ ./Lib/distutils/tests/test_install.py 2010-01-24 13:18:26.000000000 +0200 @@ -69,7 +69,7 @@ check_path(cmd.install_platlib, libdir) check_path(cmd.install_purelib, libdir) check_path(cmd.install_headers, - os.path.join(destination, "include", "python", "foopkg")) + os.path.join(destination, "include", "python")) check_path(cmd.install_scripts, os.path.join(destination, "bin")) check_path(cmd.install_data, destination) --- ./Lib/distutils/tests/test_build_ext.py.MINGW 2010-01-23 13:10:00.000000000 +0200 +++ ./Lib/distutils/tests/test_build_ext.py 2010-01-23 19:56:49.000000000 +0200 @@ -317,6 +317,7 @@ # returns wrong result with --inplace other_tmp_dir = os.path.realpath(self.mkdtemp()) old_wd = os.getcwd() + cmd.library_dirs.insert(0, old_wd) os.chdir(other_tmp_dir) try: cmd.inplace = 1 --- ./Lib/distutils/tests/test_config_cmd.py.MINGW 2009-07-05 18:00:54.000000000 +0300 +++ ./Lib/distutils/tests/test_config_cmd.py 2009-07-05 17:42:40.000000000 +0300 @@ -37,6 +37,7 @@ self.assertEquals(len(self._logs), numlines+1) def test_search_cpp(self): + # TODO: mingw host ? if sys.platform == 'win32': return pkg_dir, dist = self.create_dist() --- ./Lib/distutils/unixccompiler.py.MINGW 2010-01-23 13:34:20.000000000 +0200 +++ ./Lib/distutils/unixccompiler.py 2010-01-23 16:58:11.000000000 +0200 @@ -300,7 +300,14 @@ # use it anyway. Since distutils has always passed in # -Wl whenever gcc was used in the past it is probably # safest to keep doing so. - if _sysconfig.get_config_var("GNULD") == "yes": + # Notes: + # Above comment for -Wl is funny; + # Also linker is not loader so the check for GNU linker + # is not correct; + # --enable-new-dtags is only for ELF systems. + # => Ugly hack to drop at least for one platform + if _sysconfig.get_config_var("GNULD") == "yes" and \ + not self.compiler_type in ('cygwin', 'mingw32'): # GNU ld needs an extra option to get a RUNPATH # instead of just an RPATH. return "-Wl,--enable-new-dtags,-R" + dir --- ./Lib/distutils/cygwinccompiler.py.MINGW 2010-01-23 12:59:14.000000000 +0200 +++ ./Lib/distutils/cygwinccompiler.py 2010-01-23 12:59:18.000000000 +0200 @@ -62,6 +62,18 @@ """Include the appropriate MSVC runtime library if Python was built with MSVC 7.0 or later. """ + # FIXME: next code is from issue870382 + # MS C-runtime libraries never support backward compatibility. + # Linking to a different library without to specify correct runtime + # version for the headers will link renamed functions to msvcrt. + # See issue3308: this piece of code is python problem even + # with correct w32api headers. + # Issue: for MSVC compiler we can get the version and from version + # to determine mcvcrt as code below. But what about if python is + # build with GCC compiler? + # Output of sys.version is information for python build on first + # line, on the next line is information for the compiler and the + # output lack information for the C-runtime. msc_pos = sys.version.find('MSC v.') if msc_pos != -1: msc_ver = sys.version[msc_pos+6:msc_pos+10] @@ -79,6 +91,8 @@ return ['msvcr90'] else: raise ValueError("Unknown MS Compiler version %s " % msc_ver) + else: + return [] class CygwinCCompiler(UnixCCompiler): @@ -88,6 +102,9 @@ obj_extension = ".o" static_lib_extension = ".a" shared_lib_extension = ".dll" + # FIXME: dylib_... = ".dll.a" is not enought for binutils + # loader on win32 platform !!! + dylib_lib_extension = ".dll.a" static_lib_format = "lib%s%s" shared_lib_format = "%s%s" exe_extension = ".exe" @@ -106,6 +123,10 @@ "Compiling may fail because of undefined preprocessor macros." % details) + # Next line of code is problem for cross-compiled enviroment: + # NOTE: GCC cross-compiler is prefixed by the -- + # and by default binaries are installed in same directory + # as native compiler. self.gcc_version, self.ld_version, self.dllwrap_version = \ get_compiler_versions() self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % @@ -130,6 +151,9 @@ else: shared_option = "-mdll -static" + # FIXME: + # Hard-code may override unix-compiler settings and isn't + # possible to use Makefile variables to pass correct flags ! # Hard-code GCC because that's what this is all about. # XXX optimization, warnings etc. should be customizable. self.set_executables(compiler='gcc -mcygwin -O -Wall', @@ -250,11 +274,19 @@ output_dir = '' obj_names = [] for src_name in source_filenames: - # use normcase to make sure '.rc' is really '.rc' and not '.RC' - base, ext = os.path.splitext(os.path.normcase(src_name)) + # FIXME: "bogus checks for suffix" - as example the commented + # by #BOGUS# code break valid assembler suffix ".S" ! + #BOGUS## use normcase to make sure '.rc' is really '.rc' and not '.RC' + #BOGUS#base, ext = os.path.splitext(os.path.normcase(src_name)) + base, ext = os.path.splitext (src_name) + ext_normcase = os.path.normcase(ext) + if ext_normcase in ['.rc','.res']: + ext = ext_normcase if ext not in (self.src_extensions + ['.rc','.res']): raise UnknownFileError, \ "unknown file type '%s' (from '%s')" % (ext, src_name) + base = os.path.splitdrive(base)[1] # Chop off the drive + base = base[os.path.isabs(base):] # If abs, chop off leading / if strip_dir: base = os.path.basename (base) if ext in ('.res', '.rc'): --- ./Lib/distutils/ccompiler.py.MINGW 2010-01-23 13:04:39.000000000 +0200 +++ ./Lib/distutils/ccompiler.py 2010-01-24 09:57:50.000000000 +0200 @@ -25,8 +25,18 @@ Mainly needed on Unix, so we can plug in the information that varies across Unices and is stored in Python's Makefile. + + Note that this impact cross-build environment where make macros + as CC and LDSHARED contain name of cross compiler/linger instead + of host compiler/linker. """ + posix_build = None if compiler.compiler_type == "unix": + posix_build = True + elif compiler.compiler_type == "mingw32": + if sys.version.find('GCC') >= 0: + posix_build = True + if posix_build == True: (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ _sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'SO', 'AR', @@ -966,6 +976,8 @@ osname = os.name if platform is None: platform = sys.platform + if osname == "nt" and sys.version.find('GCC') >= 0: + return 'mingw32' for pattern, compiler in _default_compilers: if re.match(pattern, platform) is not None or \ re.match(pattern, osname) is not None: --- ./Lib/sysconfig.py.MINGW 2010-01-23 11:51:30.000000000 +0200 +++ ./Lib/sysconfig.py 2010-01-23 20:24:18.000000000 +0200 @@ -105,8 +105,13 @@ if _PYTHON_BUILD: for scheme in ('posix_prefix', 'posix_home'): - _INSTALL_SCHEMES[scheme]['include'] = '{projectbase}/Include' - _INSTALL_SCHEMES[scheme]['platinclude'] = '{srcdir}' + _INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include' + _INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}' + + # GCC(mingw) use posix build system + if os.name == "nt" and sys.version.find('GCC') >= 0: + _INSTALL_SCHEMES['nt']['include'] = '{srcdir}/Include' + _INSTALL_SCHEMES['nt']['platinclude'] = '{projectbase}' def _subst_vars(s, local_vars): try: @@ -271,7 +276,8 @@ def get_config_h_filename(): if _PYTHON_BUILD: - if os.name == "nt": + # GCC(mingw): os.name is "nt" but build system is posix + if os.name == "nt" and sys.version.find('GCC') < 0: inc_dir = os.path.join(_PROJECT_BASE, "PC") else: inc_dir = _PROJECT_BASE @@ -388,9 +394,19 @@ _CONFIG_VARS['userbase'] = _getuserbase() _CONFIG_VARS['projectbase'] = _PROJECT_BASE - if os.name in ('nt', 'os2'): - _init_non_posix(_CONFIG_VARS) + # GCC(mingw) use posix build system + posix_build = None if os.name == 'posix': + posix_build = True + else: + if os.name in ('nt', 'os2'): + if sys.version.find('GCC') >= 0: + posix_build = True + else: + posix_build = False + if posix_build == False: + _init_non_posix(_CONFIG_VARS) + if posix_build == True: _init_posix(_CONFIG_VARS) if 'srcdir' not in _CONFIG_VARS: @@ -400,7 +416,7 @@ # Normally it is relative to the build directory. However, during # testing, for example, we might be running a non-installed python # from a different directory. - if _PYTHON_BUILD and os.name == "posix": + if _PYTHON_BUILD and posix_build == True: base = _PROJECT_BASE if (not os.path.isabs(_CONFIG_VARS['srcdir']) and base != os.getcwd()): --- ./Lib/ctypes/test/test_functions.py.MINGW 2009-07-05 18:13:39.000000000 +0300 +++ ./Lib/ctypes/test/test_functions.py 2009-07-22 00:22:31.000000000 +0300 @@ -359,6 +359,11 @@ self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) def test_struct_return_8H(self): + if sys.platform == "win32" and sys.version.find("GCC") >= 0: + # This is known cdecl incompatibility between GCC + # and MSVC. It is addressed in GCC issue #36834. + # Python libffi detect it and complain. + return class S8I(Structure): _fields_ = [("a", c_int), ("b", c_int), --- ./Lib/ctypes/test/test_as_parameter.py.MINGW 2009-07-05 18:12:23.000000000 +0300 +++ ./Lib/ctypes/test/test_as_parameter.py 2009-07-22 00:19:35.000000000 +0300 @@ -1,6 +1,7 @@ import unittest from ctypes import * import _ctypes_test +import sys dll = CDLL(_ctypes_test.__file__) @@ -171,6 +172,11 @@ self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) def test_struct_return_8H(self): + if sys.platform == "win32" and sys.version.find("GCC") >= 0: + # This is known cdecl incompatibility between GCC + # and MSVC. It is addressed in GCC issue #36834. + # Python libffi detect it and complain. + return class S8I(Structure): _fields_ = [("a", c_int), ("b", c_int), --- ./Lib/ctypes/util.py.MINGW 2009-10-23 21:41:00.000000000 +0300 +++ ./Lib/ctypes/util.py 2009-10-23 21:29:17.000000000 +0300 @@ -7,6 +7,11 @@ if os.name == "nt": def _get_build_version(): + #*********************************************************** + # NOTE: As example for GCC(mingw) build sys.version return: + # '2.7a0 (trunk:M, ,