Author: compnerd Date: Mon Jan 2 12:41:48 2017 New Revision: 290823 URL: http://llvm.org/viewvc/llvm-project?rev=290823&view=rev Log: locale: update ctype access for MSVC CRT 14+
Visual C++ 14 and newer split msvcrt into msvcrt and ucrt with flavours of the ucrt for different environments. This changed the access to the ctype table by introducing the `__pctype_func` and `__pwctype_func` accessors. Use this rather than directly accessing `_ctype` which allows us to be safer in threaded situations by going through the libc locking. Modified: libcxx/trunk/include/support/win32/locale_win32.h libcxx/trunk/src/locale.cpp Modified: libcxx/trunk/include/support/win32/locale_win32.h URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale_win32.h?rev=290823&r1=290822&r2=290823&view=diff ============================================================================== --- libcxx/trunk/include/support/win32/locale_win32.h (original) +++ libcxx/trunk/include/support/win32/locale_win32.h Mon Jan 2 12:41:48 2017 @@ -11,8 +11,12 @@ #ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H +#include <crtversion.h> + +#if _VC_CRT_MAJOR_VERSION < 14 // ctype mask table defined in msvcrt.dll -extern "C" unsigned short __declspec(dllimport) _ctype[]; +extern "C" unsigned short __declspec(dllimport) _ctype[]; +#endif #include "support/win32/support.h" #include "support/win32/locale_mgmt_win32.h" Modified: libcxx/trunk/src/locale.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=290823&r1=290822&r2=290823&view=diff ============================================================================== --- libcxx/trunk/src/locale.cpp (original) +++ libcxx/trunk/src/locale.cpp Mon Jan 2 12:41:48 2017 @@ -24,6 +24,9 @@ #endif #include "clocale" #include "cstring" +#if defined(_LIBCPP_MSVCRT) +#define _CTYPE_DISABLE_MACROS +#endif #include "cwctype" #include "__sso_allocator" #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) @@ -1108,9 +1111,13 @@ ctype<char>::classic_table() _NOEXCEPT #elif __sun__ return __ctype_mask; #elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) +#if _VC_CRT_MAJOR_VERSION < 14 + // This is assumed to be safe, which is a nonsense assumption because we're + // going to end up dereferencing it later... return _ctype+1; // internal ctype mask table defined in msvcrt.dll -// This is assumed to be safe, which is a nonsense assumption because we're -// going to end up dereferencing it later... +#else + return __pctype_func(); +#endif #elif defined(__EMSCRIPTEN__) return *__ctype_b_loc(); #elif defined(_NEWLIB_VERSION) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits