--- ./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 2008-12-02 23:01:44.000000000 +0200 +++ ./PC/msvcrtmodule.c 2009-01-18 22:00:44.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 @@ -258,6 +283,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 2009-07-22 00:17:34.000000000 +0300 +++ ./Lib/distutils/command/build_ext.py 2009-07-22 00:17:39.000000000 +0300 @@ -25,7 +25,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()) @@ -223,7 +224,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. @@ -265,7 +267,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", @@ -750,6 +753,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': + from distutils 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/tests/test_cygwinccompiler.py.MINGW 2009-07-20 22:48:21.000000000 +0300 +++ ./Lib/distutils/tests/test_cygwinccompiler.py 2009-07-20 22:21:58.000000000 +0300 @@ -63,7 +63,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_build_ext.py.MINGW 2009-07-20 22:57:45.000000000 +0300 +++ ./Lib/distutils/tests/test_build_ext.py 2009-07-20 22:21:58.000000000 +0300 @@ -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/cygwinccompiler.py.MINGW 2009-07-21 02:23:58.000000000 +0300 +++ ./Lib/distutils/cygwinccompiler.py 2009-07-22 00:40:50.000000000 +0300 @@ -64,6 +64,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] @@ -81,6 +93,8 @@ return ['msvcr90'] else: raise ValueError("Unknown MS Compiler version %s " % msc_ver) + else: + return [] class CygwinCCompiler(UnixCCompiler): @@ -90,6 +104,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" @@ -108,6 +125,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" % @@ -132,6 +153,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', @@ -252,11 +276,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/sysconfig.py.MINGW 2009-06-12 22:15:37.000000000 +0300 +++ ./Lib/distutils/sysconfig.py 2009-07-09 23:56:19.000000000 +0300 @@ -70,7 +70,8 @@ """ if prefix is None: prefix = plat_specific and EXEC_PREFIX or PREFIX - if os.name == "posix": + # GCC(mingw): os.name is "nt" but build system is posix + if os.name == "posix" or sys.version.find('GCC') >= 0: if python_build: # Assume the executable is in the build directory. The # pyconfig.h file should be in the same directory. Since @@ -210,7 +211,8 @@ def get_config_h_filename(): """Return full pathname of installed pyconfig.h file.""" 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 @@ -453,6 +455,11 @@ def _init_nt(): """Initialize the module as appropriate for NT""" + if sys.version.find('GCC') >= 0: + # GCC(mingw) use posix build system + # FIXME: may be modification has to be in get_config_vars ? + _init_posix() + return g = {} # set basic install directories g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) --- ./Lib/distutils/ccompiler.py.MINGW 2009-06-16 23:34:05.000000000 +0300 +++ ./Lib/distutils/ccompiler.py 2009-07-09 23:55:13.000000000 +0300 @@ -1079,6 +1079,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/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-05-10 19:40:46.000000000 +0300 +++ ./Lib/ctypes/util.py 2009-07-22 00:45:33.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, ,