--- ./PC/_winreg.c.MINGW 2008-08-06 23:36:36.000000000 +0300 +++ ./PC/_winreg.c 2008-09-27 01:00:04.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-11-30 23:07:47.000000000 +0200 +++ ./PC/msvcrtmodule.c 2008-12-07 20:36:39.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 native 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 2008-08-18 22:39:22.000000000 +0300 +++ ./Lib/distutils/command/build_ext.py 2008-09-28 19:14:21.000000000 +0300 @@ -19,7 +19,8 @@ from distutils.util import get_platform from distutils import log -if os.name == 'nt': +# GCC(mingw): os.name is "nt" but build system is posix +if os.name == 'nt' and sys.version.find('mingw') < 0: from distutils.msvccompiler import get_build_version MSVC_VERSION = int(get_build_version()) @@ -181,7 +182,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('mingw') < 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. @@ -223,7 +225,7 @@ # 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.version.find('mingw') >= 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", --- ./Lib/distutils/command/build_scripts.py.MINGW 2008-08-06 23:37:01.000000000 +0300 +++ ./Lib/distutils/command/build_scripts.py 2008-10-05 16:25:37.000000000 +0300 @@ -104,7 +104,9 @@ outf.write("#!%s%s\n" % (os.path.join( sysconfig.get_config_var("BINDIR"), - "python" + sysconfig.get_config_var("VERSION") + # GCC(mingw) define VERSION without dot as MSVC build, + # so we has to cast number to string + "python" + str(sysconfig.get_config_var("VERSION")) + sysconfig.get_config_var("EXE")), post_interp)) outf.writelines(f.readlines()) --- ./Lib/distutils/tests/test_build_ext.py.MINGW 2008-09-28 01:43:35.000000000 +0300 +++ ./Lib/distutils/tests/test_build_ext.py 2008-09-29 00:33:52.000000000 +0300 @@ -19,7 +19,8 @@ self.sys_path = sys.path[:] sys.path.append(self.tmp_dir) - if os.name == "posix": + # GCC(mingw): os.name is "nt" but build system is posix + if os.name == "posix" or sys.version.find('mingw') >= 0: srcdir = sysconfig.get_config_var('srcdir') else: srcdir = sysconfig.project_base --- ./Lib/distutils/cygwinccompiler.py.MINGW 2008-08-18 22:39:22.000000000 +0300 +++ ./Lib/distutils/cygwinccompiler.py 2008-11-29 22:36:29.000000000 +0200 @@ -60,6 +60,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] @@ -77,6 +89,8 @@ return ['msvcr90'] else: raise ValueError("Unknown MS Compiler version %i " % msc_Ver) + else: + return [] class CygwinCCompiler (UnixCCompiler): @@ -85,6 +99,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" @@ -103,6 +120,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_versions() self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % @@ -127,6 +148,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', @@ -271,8 +295,14 @@ if output_dir is None: 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')" % \ --- ./Lib/distutils/sysconfig.py.MINGW 2008-09-29 00:47:45.000000000 +0300 +++ ./Lib/distutils/sysconfig.py 2008-09-29 00:47:54.000000000 +0300 @@ -73,7 +73,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('mingw') >= 0: if python_build: if plat_specific: inc_dir = project_base @@ -200,7 +201,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('mingw') < 0: inc_dir = os.path.join(project_base, "PC") else: inc_dir = project_base @@ -436,6 +438,11 @@ def _init_nt(): """Initialize the module as appropriate for NT""" + if sys.version.find('mingw') >= 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 2008-08-06 23:37:01.000000000 +0300 +++ ./Lib/distutils/ccompiler.py 2008-09-28 19:14:10.000000000 +0300 @@ -1083,6 +1083,8 @@ osname = os.name if platform is None: platform = sys.platform + if osname == "nt" and sys.version.find('mingw') >= 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 2008-08-06 23:37:08.000000000 +0300 +++ ./Lib/ctypes/test/test_functions.py 2008-12-07 03:28:44.000000000 +0200 @@ -359,6 +359,11 @@ self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3)) def test_struct_return_8H(self): + if sys.version.find("mingw") >= 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 2008-08-06 23:37:08.000000000 +0300 +++ ./Lib/ctypes/test/test_as_parameter.py 2008-12-07 03:28:41.000000000 +0200 @@ -1,6 +1,7 @@ import unittest from ctypes import * import _ctypes_test +import sys dll = CDLL(_ctypes_test.__file__) @@ -171,6 +172,11 @@ self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3)) def test_struct_return_8H(self): + if sys.version.find("mingw") >= 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 2008-08-06 23:37:08.000000000 +0300 +++ ./Lib/ctypes/util.py 2008-11-23 22:45:00.000000000 +0200 @@ -7,6 +7,11 @@ if os.name == "nt": def _get_build_version(): + #*********************************************************** + # NOTE: As example for GCC(mingw) build sys.version return: + # 2.6rc2+ (trunk:M, ,