diff --git a/Include/fileobject.h b/Include/fileobject.h index a99c94d..de04253 100644 --- a/Include/fileobject.h +++ b/Include/fileobject.h @@ -45,7 +45,8 @@ int _PyVerify_fd(int fd); #endif /* Py_LIMITED_API */ /* A routine to check if a file descriptor can be select()-ed. */ -#ifdef HAVE_SELECT +/* NOTE check below obsolete Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE */ +#if defined(HAVE_SELECT) && !defined(MS_WIN32) #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE)) #else #define _PyIsSelectable_fd(FD) (1) diff --git a/Include/node.h b/Include/node.h index 99c13f7..2e4e2ba 100644 --- a/Include/node.h +++ b/Include/node.h @@ -21,7 +21,7 @@ PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, char *str, int lineno, int col_offset); PyAPI_FUNC(void) PyNode_Free(node *n); #ifndef Py_LIMITED_API -Py_ssize_t _PyNode_SizeOf(node *n); +PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n); #endif /* Node access functions */ diff --git a/Include/objimpl.h b/Include/objimpl.h index 3d5f509..d762006 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -250,6 +250,12 @@ typedef union _gc_head { Py_ssize_t gc_refs; } gc; long double dummy; /* force worst-case alignment */ +#if defined(__MINGW32__) +/* FIXME: what about 64-bit platforms ? + * see http://mail.python.org/pipermail/python-dev/2009-July/090724.html + */ + double dummy1; +#endif } PyGC_Head; extern PyGC_Head *_PyGC_generation0; diff --git a/Include/osdefs.h b/Include/osdefs.h index 90b430a..377f608 100644 --- a/Include/osdefs.h +++ b/Include/osdefs.h @@ -17,8 +17,10 @@ extern "C" { #else #define SEP L'\\' #define ALTSEP L'/' +#ifndef MAXPATHLEN #define MAXPATHLEN 256 #endif +#endif #define DELIM L';' #endif #endif diff --git a/Include/pymath.h b/Include/pymath.h index 62a6c42..9570c5f 100644 --- a/Include/pymath.h +++ b/Include/pymath.h @@ -107,6 +107,8 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short); * non-infinite value v sitting in an 80-bit x87 register such that * v becomes infinite when spilled from the register to 64-bit memory. * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf + * FIXME: PC/pyconfig.h defines Py_IS_INFINITY as (!_finite(X) && !_isnan(X)) + * so that above note isn't correct !!! */ #ifndef Py_IS_INFINITY # if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1 diff --git a/Include/pyport.h b/Include/pyport.h index eba34f9..c3305f7 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -664,6 +664,152 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ +#ifdef __MINGW32__ +/* FIXME: some of next definitions specific to gcc(mingw build) can be + generalized on definitions of _WIN32 or WIN32 and to be common for + all windows build instead explicitly to define only for non-autotools + based builds (see PC/pyconfig.h for details). */ +#if defined(_WIN64) +# define MS_WIN64 +#endif +#if !defined(MS_WIN32) && defined(_WIN32) +# define MS_WIN32 +#endif +#if !defined(MS_WIN32) && defined(_WIN32) +# define MS_WIN32 +#endif +#if !defined(MS_WINDOWS) && defined(MS_WIN32) +# define MS_WINDOWS +#endif + +#ifndef PYTHONPATH +# define PYTHONPATH L".\\DLLs;.\\lib" +#endif + +/* python 2.6+ requires Windows 2000 or greater. */ +#define Py_WINVER 0x0500 + +#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) +/* FIXME if NTDDI_xxx is in use by mingw (see PC/pyconfig.h) */ +#ifndef WINVER +# define WINVER Py_WINVER +#endif +#ifndef _WIN32_WINNT +# define _WIN32_WINNT Py_WINVER +#endif +#endif + +#ifdef PLATFORM +/*NOTE: if compile getplatform.c PLATFORM is set to MACHDEP that is + "win" for mingw build (see respective comment in configure.in). */ +# undef PLATFORM +#endif +/* always set to "win32" - see PC/pyconfig.h */ +#define PLATFORM "win32" + +#if defined(MS_WIN64) +# define SIZEOF_HKEY 8 +#elif defined(MS_WIN32) +# define SIZEOF_HKEY 4 +#endif + +/*NOTE: mingw has isinf as macro defined in math.h. + Since PC/pyconfig.h define Py_IS_INFINITY(X) that cover HAVE_DECL_ISFINITE + here for Py_IS_INFINITY we define same as for MSVC build. + This makes HAVE_DECL_ISFINITE needless. + Also see commants in configure.in and pymath.h. */ +#define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X)) + +#ifndef HAVE_LARGEFILE_SUPPORT +/* + FIXME: on windows platforms: + - Python use PY_LONG_LONG(!) for Py_off_t (_fileio.c); + - HAVE_LARGEFILE_SUPPORT is defined in PC/pyconfig.h; + - PC/pyconfig.h define 4 for SIZEOF_OFF_T and 8 for SIZEOF_FPOS_T; + - If HAVE_LARGEFILE_SUPPORT isn't defined python will use off_t(!) + for Py_off_t (see fileobjects.c and bz2module.c). + Since for mingw configure detect 4 for size of "off_t" and 8 - for + "fpos_t" we has to define HAVE_LARGEFILE_SUPPORT too. + TODO: to test with AC_SYS_LARGEFILE and appropriate updates in + python code. +*/ +# define HAVE_LARGEFILE_SUPPORT +#endif + +#if defined(Py_ENABLE_SHARED) +# define MS_COREDLL 1 /* deprecated old symbol, but still in use for windows code */ +#else +# define MS_NO_COREDLL 1 +#endif + +#if Py_UNICODE_SIZE == 2 +/* For mingw is 2 but FIXME: What about to raise error in configure if + unicode size isn't two ? Did python windows code support ucs4 ? */ +# define Py_WIN_WIDE_FILENAMES +#endif + +/* NOTE: Don't define HAVE_STDDEF_H. + * It is defined by PC/pyconfig.h and used by Include/Python.h + * (with comment For size_t?) but isn't required for mingw */ + +#if 0 +/* Obsolete: + * Author: Charles-François Natali + * Date: Sun Aug 28 17:51:43 2011 +0200 + * NOTE: still defined in PC/pyconfig.h ;) + */ +#define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE +#endif + +/* All other defines from PC/pyconfig.h are in autoconf generated + pyconfig.h */ +#if 0 +/*FIXME: + MSDN: + "The getaddrinfo function was added to the ws2_32.dll on Windows XP + and later." + mingw: + getaddrinfo and getnameinfo is defined for WINVER >= 0x0501. + PC/pyconfig.h: + "Python 2.6+ requires Windows 2000 or greater" + So far so good but socketmodule.h define HAVE_GETADDRINFO and + HAVE_GETNAMEINFO under very specific condition : + # ifdef SIO_GET_MULTICAST_FILTER + # include + So the question is "Separate SDKs" required for w2k in MSVC build ? + TODO: resolve later, may by configure :-/. For now python code will + use fake implementation and if user define appropriate value for + WINVER - the functionas from C runtime. + For details see socketmodule.c . + */ +#ifndef HAVE_GETADDRINFO +# define HAVE_GETADDRINFO +#endif +#ifndef HAVE_GETNAMEINFO +# define HAVE_GETNAMEINFO +#endif +#endif + +/* Refer to . + For mingw host configure detect functions described as HAVE_XXX + in _math.h but as MSVC don't define them we will undefine HAVE_XXX + too to use _Py_* replacements same as MSVC build . + */ +#undef HAVE_ACOSH +#undef HAVE_ASINH +#undef HAVE_ATANH +#undef HAVE_EXPM1 +#undef HAVE_LOG1P + +/* Refer to . + Side by Side assemblies are not supported by default in MSVC CRT 10 . + */ +#if __MSVCRT_VERSION__ >= 0x0800 && __MSVCRT_VERSION__ < 0x1000 +#define HAVE_SXS 1 +#endif + +#endif /*def __MINGW32__*/ + /* On 4.4BSD-descendants, ctype functions serves the whole range of * wchar_t character set rather than single byte code points only. * This characteristic can break some operations of string object @@ -717,12 +863,12 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); */ /* - All windows ports, except cygwin, are handled in PC/pyconfig.h. + MSVC windows port is handled in PC/pyconfig.h. - Cygwin is the only other autoconf platform requiring special + Cygwin and Mingw are autoconf platforms requiring special linkage handling and it uses __declspec(). */ -#if defined(__CYGWIN__) +#if defined(__CYGWIN__) || defined(__MINGW32__) # define HAVE_DECLSPEC_DLL #endif @@ -745,9 +891,17 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); /* Under Cygwin, auto-import functions to prevent compilation */ /* failures similar to those described at the bottom of 4.1: */ /* http://docs.python.org/extending/windows.html#a-cookbook-approach */ -# if !defined(__CYGWIN__) +# if !defined(__CYGWIN__) && !defined(__MINGW32__) # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE -# endif /* !__CYGWIN__ */ +# else +# define PyAPI_FUNC(RTYPE) RTYPE +# endif /* !__CYGWIN__ !__MINGW32__ */ + /* NOTE: The issue3945 "compile error in _fileio.c (cygwin)" + * was resolved with modification of code. + * This issue was resolved for gcc(mingw) with enabling auto + * import feature. Since _fileio.c problem now disappear there + * is no more reasons to avoid dllimport for gcc(mingw). + */ # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE /* module init functions outside the core must be exported */ # if defined(__cplusplus) diff --git a/Include/pythonrun.h b/Include/pythonrun.h index 4d24b2d..30e1335 100644 --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -175,7 +175,7 @@ PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); PyAPI_FUNC(wchar_t *) Py_GetPath(void); PyAPI_FUNC(void) Py_SetPath(const wchar_t *); #ifdef MS_WINDOWS -int _Py_CheckPython3(); +int _Py_CheckPython3(void); #endif /* In their own files */ diff --git a/Lib/ctypes/test/test_as_parameter.py b/Lib/ctypes/test/test_as_parameter.py index 2657a66..bfec44c 100644 --- a/Lib/ctypes/test/test_as_parameter.py +++ b/Lib/ctypes/test/test_as_parameter.py @@ -1,6 +1,7 @@ import unittest from ctypes import * import _ctypes_test +import sys dll = CDLL(_ctypes_test.__file__) @@ -171,6 +172,10 @@ class BasicWrapTestCase(unittest.TestCase): s2h = dll.ret_2h_func(self.wrap(inp)) self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) + # This is known cdecl incompatibility between GCC + # and MSVC. It is addressed in GCC issue #36834. + # Python libffi detect it and complain. + @unittest.skipIf(sys.platform == "win32" and sys.version.find("GCC") >= 0, 'XFAIL GCC(mingw)') def test_struct_return_8H(self): class S8I(Structure): _fields_ = [("a", c_int), diff --git a/Lib/ctypes/test/test_functions.py b/Lib/ctypes/test/test_functions.py index 45d74ec..3aab4d5 100644 --- a/Lib/ctypes/test/test_functions.py +++ b/Lib/ctypes/test/test_functions.py @@ -359,6 +359,10 @@ class FunctionTestCase(unittest.TestCase): s2h = windll.s_ret_2h_func(S2H(99, 88)) self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) + # This is known cdecl incompatibility between GCC + # and MSVC. It is addressed in GCC issue #36834. + # Python libffi detect it and complain. + @unittest.skipIf(sys.platform == "win32" and sys.version.find("GCC") >= 0, 'XFAIL GCC(mingw)') def test_struct_return_8H(self): class S8I(Structure): _fields_ = [("a", c_int), diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 5555b2e..85c1c77 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -6,6 +6,11 @@ import subprocess if os.name == "nt": def _get_build_version(): + #*********************************************************** + # NOTE: As example for GCC(mingw) build sys.version return: + # '2.7a0 (trunk:M, ,