Merge branch 'mingw32-5.3-fixes'

Work around several problems in the latest MinGW (not w64) 5.3 release.
This commit is contained in:
Vadim Zeitlin
2017-01-15 17:00:14 +01:00
8 changed files with 99 additions and 33 deletions

View File

@@ -33,6 +33,14 @@
#endif
#endif
/*
MinGW 5.3.0 (and presumably later) predefines _WIN32_WINNT and WINVER
in sdkddkver.h included from _mingw.h to very low (Windows 2000!)
values. We really want to predefine them ourselves instead, so do it
before including _mingw.h.
*/
#include "wx/msw/winver.h"
#include <_mingw.h>
/*
@@ -141,26 +149,44 @@
the new C++11 features and not disable the use of POSIX functions, we just
manually declare the functions we need in this case if necessary.
*/
#if defined(__MINGW32_TOOLCHAIN__) && defined(__STRICT_ANSI__)
#define wxNEEDS_STRICT_ANSI_WORKAROUNDS
#ifdef __MINGW32_TOOLCHAIN__
/*
The macro below is used in wx/wxcrtbase.h included from C regex library
code, so make sure it compiles in non-C++ code too.
*/
#ifdef __cplusplus
#define wxEXTERNC extern "C"
#else
#define wxEXTERNC
#endif
/*
This macro is somewhat unusual as it takes the list of parameters
inside parentheses and includes semicolon inside it as putting the
semicolon outside wouldn't do the right thing when this macro is empty.
*/
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) \
extern "C" _CRTIMP rettype __cdecl __MINGW_NOTHROW func params ;
#define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) \
wxEXTERNC _CRTIMP rettype __cdecl __MINGW_NOTHROW func params ;
/*
There is a bug resulting in a compilation error in MinGW standard
math.h header, see https://sourceforge.net/p/mingw/bugs/2250/, work
around it here because math.h is also included from several other
standard headers (e.g. <algorithm>) and we don't want to duplicate this
hack everywhere this happens.
*/
wxDECL_FOR_STRICT_MINGW32(double, _hypot, (double, double))
#ifdef __STRICT_ANSI__
#define wxNEEDS_STRICT_ANSI_WORKAROUNDS
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) \
wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params)
/*
There is a bug resulting in a compilation error in MinGW standard
math.h header, see https://sourceforge.net/p/mingw/bugs/2250/, work
around it here because math.h is also included from several other
standard headers (e.g. <algorithm>) and we don't want to duplicate this
hack everywhere this happens.
*/
wxDECL_FOR_STRICT_MINGW32(double, _hypot, (double, double))
#else
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params)
#endif
#else
#define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params)
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params)
#endif

36
include/wx/msw/winver.h Normal file
View File

@@ -0,0 +1,36 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/winver.h
// Purpose: Define Windows version macros if they're not predefined.
// Author: Vadim Zeitlin
// Created: 2017-01-13 (extracted from wx/msw/wrapwin.h)
// Copyright: (c) 2017 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_WINVER_H_
#define _WX_MSW_WINVER_H_
// Notice that this header must not include any other wx headers as it's
// indirectly included from wx/defs.h itself when using gcc (via wx/platform.h,
// then wx/compiler.h and wx/msw/gccpriv.h).
// Define WINVER, _WIN32_WINNT and _WIN32_IE to the highest possible values
// because we always check for the version of installed DLLs at runtime anyway
// (see wxGetWinVersion() and wxApp::GetComCtl32Version()) unless the user
// really doesn't want to use APIs only available on later OS versions and had
// defined them to (presumably lower) values -- or, alternatively, wants to use
// even higher version of the API which will become available later.
#ifndef WINVER
#define WINVER 0x0603
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0603
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0700
#endif
#endif // _WX_MSW_WINVER_H_

View File

@@ -12,6 +12,10 @@
#include "wx/platform.h"
// before including windows.h, define version macros at (currently) maximal
// values because we do all our checks at run-time anyhow
#include "wx/msw/winver.h"
// strict type checking to detect conversion from HFOO to HBAR at compile-time
#ifndef STRICT
#define STRICT 1
@@ -24,25 +28,6 @@
#endif // NOMINMAX
// before including windows.h, define version macros at (currently) maximal
// values because we do all our checks at run-time anyhow
#ifndef WINVER
#define WINVER 0x0603
#endif
// define _WIN32_WINNT and _WIN32_IE to the highest possible values because we
// always check for the version of installed DLLs at runtime anyway (see
// wxGetWinVersion() and wxApp::GetComCtl32Version()) unless the user really
// doesn't want to use APIs only available on later OS versions and had defined
// them to (presumably lower) values
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0603
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0700
#endif
// For IPv6 support, we must include winsock2.h before winsock.h, and
// windows.h include winsock.h so do it before including it
#if wxUSE_IPV6

View File

@@ -358,6 +358,7 @@
# define wxCHECK_W32API_VERSION(maj, min) (0)
# undef wxCHECK_MINGW32_VERSION
# define wxCHECK_MINGW32_VERSION( major, minor ) (0)
# define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params)
# define wxDECL_FOR_STRICT_MINGW32(rettype, func, params)
#endif

View File

@@ -221,6 +221,13 @@ extern unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int
#endif
#ifdef HAVE_WCSNLEN
/*
When using MinGW, wcsnlen() is not declared, but is still found by
configure -- just declare it in this case as it seems better to use it
if it's available (see https://sourceforge.net/p/mingw/bugs/2332/)
*/
wxDECL_FOR_MINGW32_ALWAYS(size_t, wcsnlen, (const wchar_t*, size_t))
#define wxCRT_StrnlenW wcsnlen
#endif
@@ -230,8 +237,15 @@ extern unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int
#define wxCRT_StricmpA stricmp
#define wxCRT_StrnicmpA strnicmp
#elif defined(__VISUALC__) || defined(__MINGW32__)
wxDECL_FOR_STRICT_MINGW32(int, _stricmp, (const char*, const char*))
wxDECL_FOR_STRICT_MINGW32(int, _strnicmp, (const char*, const char*, size_t))
/*
Due to MinGW 5.3 bug (https://sourceforge.net/p/mingw/bugs/2322/),
_stricmp() and _strnicmp() are not declared in its standard headers
when compiling without optimizations. Work around this by always
declaring them ourselves (notice that if/when this bug were fixed, we'd
still need to use wxDECL_FOR_STRICT_MINGW32() for them here.
*/
wxDECL_FOR_MINGW32_ALWAYS(int, _stricmp, (const char*, const char*))
wxDECL_FOR_MINGW32_ALWAYS(int, _strnicmp, (const char*, const char*, size_t))
#define wxCRT_StricmpA _stricmp
#define wxCRT_StrnicmpA _strnicmp