In commit 797b4a6b5191 ("headers: Expose the wchar ctype _l functions for
msvcrt.dll for Vista") was added following pattern:

    #if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x700 && 
_WIN32_WINNT >= 0x0600)
      /* These are available since msvcr80.dll, and in msvcrt.dll since Vista. 
*/
      _CRTIMP int __cdecl _iswalpha_l(wint_t _C,_locale_t _Locale);
      ...
    #endif

This preprocessor condition is not fully correct as it matches also the
case when compiling for msvcr70.dll library on Windows Vista+ target
systems. msvcr70.dll library does not provide these ctype _l functions on
Windows Vista or new systems. So it should not be enabled.

The problem is that currently __MSVCRT_VERSION__ == 0x700 condition means
compiling for msvcrt.dll OR for msvcr70.dll. And currently it is not
possible to distinguish between these two targets.

Fix this problem by changing the __MSVCRT_VERSION__ value when compiling
for msvcrt.dll and set __MSVCRT_VERSION__ to 0x600.

This is logical step because msvcrt.dll provides ABI / DLL library name of
the Visual C++ 6.0 version and msvcr70.dll provides ABI / DLL library name
of the Visual Studio 2002 (AKA VC++ 7.0).

msvcrt.dll preinstalled as part of the Windows system provides more
functions than the original Visual C++ 6.0, but still it is compatible with
the original version. So setting __MSVCRT_VERSION__ to 0x600 for msvcrt.dll
build is relatively sane option.

I was considering to use 0x6FF value for this case, but this would make it
more complicated for applications if they need to know if they are being
compiled for msvcrt.dll library ABI. They would need to check if the macro
__MSVCRT_VERSION__ is set to 0x600 (targetting the original VC++ msvcrt.dll
library) or to value 0x6FFF (targettting the system msvcrt.dll library).
This looks to be additional complication as it would be needed to track all
possible values for __MSVCRT_VERSION__. So using just one value 0x600 for
both cases should be enough because for system version specific version is
always needed to check also _WIN32_WINNT value.

So __MSVCRT_VERSION__=0x600 would mean compiling for msvcrt.dll ABI
and __MSVCRT_VERSION__=0x700 would mean compiling for msvcr70.dll ABI.

This change fixes guards around wchar ctype _l functions and also the
default value of __MSVCRT_VERSION__ when targeting msvcrt-os filled by the
mingw-w64-headers/configure.ac.
---
 mingw-w64-crt/Makefile.am      | 2 +-
 mingw-w64-headers/configure.ac | 2 +-
 mingw-w64-headers/crt/ctype.h  | 7 ++++---
 mingw-w64-headers/crt/wchar.h  | 7 ++++---
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 241ed9501335..6c08b9388030 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -20,7 +20,7 @@ else
 endif
 
 AM_CPPFLAGS=$(sysincludes)
-AM_CFLAGS=-pipe -std=gnu99 -D_CRTBLD -D_WIN32_WINNT=0x0f00 
-D__MSVCRT_VERSION__=0x700 -D__USE_MINGW_ANSI_STDIO=0 @IMAGEBASE_CFLAGS@ 
@CFGUARD_CFLAGS@ @ADD_C_CXX_WARNING_FLAGS@ @ADD_C_ONLY_WARNING_FLAGS@
+AM_CFLAGS=-pipe -std=gnu99 -D_CRTBLD -D_WIN32_WINNT=0x0f00 
-D__MSVCRT_VERSION__=0x600 -D__USE_MINGW_ANSI_STDIO=0 @IMAGEBASE_CFLAGS@ 
@CFGUARD_CFLAGS@ @ADD_C_CXX_WARNING_FLAGS@ @ADD_C_ONLY_WARNING_FLAGS@
 AM_CXXFLAGS=@ADD_C_CXX_WARNING_FLAGS@ @ADD_CXX_ONLY_WARNING_FLAGS@
 CPPFLAGSARM32=-mfpu=vfpv3
 CPPFLAGS32=-m32 -masm=att
diff --git a/mingw-w64-headers/configure.ac b/mingw-w64-headers/configure.ac
index d6809d14704b..11b4f76dae62 100644
--- a/mingw-w64-headers/configure.ac
+++ b/mingw-w64-headers/configure.ac
@@ -179,7 +179,7 @@ msvcr120*)
   default_msvcrt_version=0xC00
   ;;
 msvcrt*)
-  default_msvcrt_version=0x700
+  default_msvcrt_version=0x600
   ;;
 ucrt*|*)
   default_msvcrt_version=0xE00
diff --git a/mingw-w64-headers/crt/ctype.h b/mingw-w64-headers/crt/ctype.h
index 975d21abfb2e..825947677e58 100644
--- a/mingw-w64-headers/crt/ctype.h
+++ b/mingw-w64-headers/crt/ctype.h
@@ -138,8 +138,9 @@ int __cdecl isblank(int _C);
   wint_t __cdecl towupper(wint_t _C);
   wint_t __cdecl towlower(wint_t _C);
   int __cdecl iswctype(wint_t _C,wctype_t _Type);
-#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x700 && 
_WIN32_WINNT >= 0x0600)
-  /* These are available since msvcr80.dll, and in msvcrt.dll since Vista. */
+#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x600 && 
_WIN32_WINNT >= 0x0600)
+  /* These are available since msvcr80.dll (__MSVCRT_VERSION__ >= 0x800), and 
in
+   * msvcrt.dll (__MSVCRT_VERSION__ == 0x600) since Vista (_WIN32_WINNT >= 
0x0600). */
   _CRTIMP int __cdecl _iswalpha_l(wint_t _C,_locale_t _Locale);
   _CRTIMP int __cdecl _iswupper_l(wint_t _C,_locale_t _Locale);
   _CRTIMP int __cdecl _iswlower_l(wint_t _C,_locale_t _Locale);
@@ -225,7 +226,7 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
 #define iswgraph(_c) (iswctype(_c,_PUNCT|_ALPHA|_DIGIT))
 #define iswcntrl(_c) (iswctype(_c,_CONTROL))
 #define iswascii(_c) ((unsigned)(_c) < 0x80)
-#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x700 && 
_WIN32_WINNT >= 0x0600)
+#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x600 && 
_WIN32_WINNT >= 0x0600)
 # define _iswalpha_l(_c,_p) (_iswctype_l(_c,_ALPHA,_p))
 # define _iswupper_l(_c,_p) (_iswctype_l(_c,_UPPER,_p))
 # define _iswlower_l(_c,_p) (_iswctype_l(_c,_LOWER,_p))
diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h
index 34df93ec2470..ca2c1fc70cb3 100644
--- a/mingw-w64-headers/crt/wchar.h
+++ b/mingw-w64-headers/crt/wchar.h
@@ -213,8 +213,9 @@ _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index);
   wint_t __cdecl towupper(wint_t _C);
   wint_t __cdecl towlower(wint_t _C);
   int __cdecl iswctype(wint_t _C,wctype_t _Type);
-#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x700 && 
_WIN32_WINNT >= 0x0600)
-  /* These are available since msvcr80.dll, and in msvcrt.dll since Vista. */
+#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x600 && 
_WIN32_WINNT >= 0x0600)
+  /* These are available since msvcr80.dll (__MSVCRT_VERSION__ >= 0x800), and 
in
+   * msvcrt.dll (__MSVCRT_VERSION__ == 0x600) since Vista (_WIN32_WINNT >= 
0x0600). */
   _CRTIMP int __cdecl _iswalpha_l(wint_t _C,_locale_t _Locale);
   _CRTIMP int __cdecl _iswupper_l(wint_t _C,_locale_t _Locale);
   _CRTIMP int __cdecl _iswlower_l(wint_t _C,_locale_t _Locale);
@@ -349,7 +350,7 @@ _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index);
 #define iswgraph(_c) (iswctype(_c,_PUNCT|_ALPHA|_DIGIT))
 #define iswcntrl(_c) (iswctype(_c,_CONTROL))
 #define iswascii(_c) ((unsigned)(_c) < 0x80)
-#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x700 && 
_WIN32_WINNT >= 0x0600)
+#if __MSVCRT_VERSION__ >= 0x800 || (__MSVCRT_VERSION__ == 0x600 && 
_WIN32_WINNT >= 0x0600)
 # define _iswalpha_l(_c,_p) (_iswctype_l(_c,_ALPHA,_p))
 # define _iswupper_l(_c,_p) (_iswctype_l(_c,_UPPER,_p))
 # define _iswlower_l(_c,_p) (_iswctype_l(_c,_LOWER,_p))
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to