diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -222,8 +222,6 @@ __bit/popcount.h __bit/rotate.h __bit_reference - __bsd_locale_defaults.h - __bsd_locale_fallbacks.h __charconv/chars_format.h __charconv/from_chars_integral.h __charconv/from_chars_result.h @@ -585,6 +583,8 @@ __support/xlocale/__nop_locale_mgmt.h __support/xlocale/__posix_l_fallback.h __support/xlocale/__strtonum_fallback.h + __support/xlocale/bsd_locale_defaults.h + __support/xlocale/bsd_locale_fallbacks.h __thread/poll_with_backoff.h __thread/timed_backoff_policy.h __threading_support diff --git a/libcxx/include/__locale b/libcxx/include/__locale --- a/libcxx/include/__locale +++ b/libcxx/include/__locale @@ -52,63 +52,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) -struct __libcpp_locale_guard { - _LIBCPP_INLINE_VISIBILITY - __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} - - _LIBCPP_INLINE_VISIBILITY - ~__libcpp_locale_guard() { - if (__old_loc_) - uselocale(__old_loc_); - } - - locale_t __old_loc_; -private: - __libcpp_locale_guard(__libcpp_locale_guard const&); - __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); -}; -#elif defined(_LIBCPP_MSVCRT_LIKE) -struct __libcpp_locale_guard { - __libcpp_locale_guard(locale_t __l) : - __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { - // Setting the locale can be expensive even when the locale given is - // already the current locale, so do an explicit check to see if the - // current locale is already the one we want. - const char* __lc = __setlocale(nullptr); - // If every category is the same, the locale string will simply be the - // locale name, otherwise it will be a semicolon-separated string listing - // each category. In the second case, we know at least one category won't - // be what we want, so we only have to check the first case. - if (_VSTD::strcmp(__l.__get_locale(), __lc) != 0) { - __locale_all = _strdup(__lc); - if (__locale_all == nullptr) - __throw_bad_alloc(); - __setlocale(__l.__get_locale()); - } - } - ~__libcpp_locale_guard() { - // The CRT documentation doesn't explicitly say, but setlocale() does the - // right thing when given a semicolon-separated list of locale settings - // for the different categories in the same format as returned by - // setlocale(LC_ALL, nullptr). - if (__locale_all != nullptr) { - __setlocale(__locale_all); - free(__locale_all); - } - _configthreadlocale(__status); - } - static const char* __setlocale(const char* __locale) { - const char* __new_locale = setlocale(LC_ALL, __locale); - if (__new_locale == nullptr) - __throw_bad_alloc(); - return __new_locale; - } - int __status; - char* __locale_all = nullptr; -}; -#endif - class _LIBCPP_TYPE_VIS locale; template diff --git a/libcxx/include/__bsd_locale_defaults.h b/libcxx/include/__support/xlocale/bsd_locale_defaults.h rename from libcxx/include/__bsd_locale_defaults.h rename to libcxx/include/__support/xlocale/bsd_locale_defaults.h --- a/libcxx/include/__bsd_locale_defaults.h +++ b/libcxx/include/__support/xlocale/bsd_locale_defaults.h @@ -11,8 +11,8 @@ // we will define the mapping from an internal macro to the real BSD symbol. //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___BSD_LOCALE_DEFAULTS_H -#define _LIBCPP___BSD_LOCALE_DEFAULTS_H +#ifndef _LIBCPP___SUPPORT_XLOCALE_BSD_LOCALE_DEFAULTS_H +#define _LIBCPP___SUPPORT_XLOCALE_BSD_LOCALE_DEFAULTS_H #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -33,4 +33,4 @@ #define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__) #define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) -#endif // _LIBCPP___BSD_LOCALE_DEFAULTS_H +#endif // _LIBCPP___SUPPORT_XLOCALE_BSD_LOCALE_DEFAULTS_H diff --git a/libcxx/include/__bsd_locale_fallbacks.h b/libcxx/include/__support/xlocale/bsd_locale_fallbacks.h rename from libcxx/include/__bsd_locale_fallbacks.h rename to libcxx/include/__support/xlocale/bsd_locale_fallbacks.h --- a/libcxx/include/__bsd_locale_fallbacks.h +++ b/libcxx/include/__support/xlocale/bsd_locale_fallbacks.h @@ -10,9 +10,12 @@ // of those functions for non-BSD platforms. //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___BSD_LOCALE_FALLBACKS_H -#define _LIBCPP___BSD_LOCALE_FALLBACKS_H +#ifndef _LIBCPP___SUPPORT_XLOCALE_BSD_LOCALE_FALLBACKS_H +#define _LIBCPP___SUPPORT_XLOCALE_BSD_LOCALE_FALLBACKS_H +#include +#include +#include #include #include @@ -22,6 +25,62 @@ _LIBCPP_BEGIN_NAMESPACE_STD +#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) +struct __libcpp_locale_guard { + _LIBCPP_INLINE_VISIBILITY __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} + + _LIBCPP_INLINE_VISIBILITY ~__libcpp_locale_guard() { + if (__old_loc_) + uselocale(__old_loc_); + } + + locale_t __old_loc_; + +private: + __libcpp_locale_guard(__libcpp_locale_guard const&); + __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); +}; +#elif defined(_LIBCPP_MSVCRT_LIKE) +struct __libcpp_locale_guard { + __libcpp_locale_guard(locale_t __l) : + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { + // Setting the locale can be expensive even when the locale given is + // already the current locale, so do an explicit check to see if the + // current locale is already the one we want. + const char* __lc = __setlocale(nullptr); + // If every category is the same, the locale string will simply be the + // locale name, otherwise it will be a semicolon-separated string listing + // each category. In the second case, we know at least one category won't + // be what we want, so we only have to check the first case. + if (_VSTD::strcmp(__l.__get_locale(), __lc) != 0) { + __locale_all = _strdup(__lc); + if (__locale_all == nullptr) + __throw_bad_alloc(); + __setlocale(__l.__get_locale()); + } + } + ~__libcpp_locale_guard() { + // The CRT documentation doesn't explicitly say, but setlocale() does the + // right thing when given a semicolon-separated list of locale settings + // for the different categories in the same format as returned by + // setlocale(LC_ALL, nullptr). + if (__locale_all != nullptr) { + __setlocale(__locale_all); + free(__locale_all); + } + _configthreadlocale(__status); + } + static const char* __setlocale(const char* __locale) { + const char* __new_locale = setlocale(LC_ALL, __locale); + if (__new_locale == nullptr) + __throw_bad_alloc(); + return __new_locale; + } + int __status; + char* __locale_all = nullptr; +}; +#endif + inline _LIBCPP_INLINE_VISIBILITY decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) { @@ -139,4 +198,4 @@ _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___BSD_LOCALE_FALLBACKS_H +#endif // _LIBCPP___SUPPORT_XLOCALE_BSD_LOCALE_FALLBACKS_H diff --git a/libcxx/include/locale b/libcxx/include/locale --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -224,9 +224,9 @@ #endif #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -#include <__bsd_locale_defaults.h> +# include <__support/xlocale/bsd_locale_defaults.h> #else -#include <__bsd_locale_fallbacks.h> +# include <__support/xlocale/bsd_locale_fallbacks.h> #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv --- a/libcxx/test/libcxx/transitive_includes/cxx03.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv @@ -493,6 +493,7 @@ list version locale atomic locale cctype +locale clocale locale concepts locale cstdarg locale cstddef @@ -501,6 +502,7 @@ locale cstdlib locale cstring locale ctime +locale cwchar locale initializer_list locale ios locale iosfwd diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv --- a/libcxx/test/libcxx/transitive_includes/cxx11.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv @@ -493,6 +493,7 @@ list version locale atomic locale cctype +locale clocale locale concepts locale cstdarg locale cstddef @@ -501,6 +502,7 @@ locale cstdlib locale cstring locale ctime +locale cwchar locale initializer_list locale ios locale iosfwd diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv --- a/libcxx/test/libcxx/transitive_includes/cxx14.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv @@ -495,6 +495,7 @@ list version locale atomic locale cctype +locale clocale locale concepts locale cstdarg locale cstddef @@ -503,6 +504,7 @@ locale cstdlib locale cstring locale ctime +locale cwchar locale initializer_list locale ios locale iosfwd diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv --- a/libcxx/test/libcxx/transitive_includes/cxx17.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv @@ -495,6 +495,7 @@ list version locale atomic locale cctype +locale clocale locale concepts locale cstdarg locale cstddef @@ -503,6 +504,7 @@ locale cstdlib locale cstring locale ctime +locale cwchar locale initializer_list locale ios locale iosfwd diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv --- a/libcxx/test/libcxx/transitive_includes/cxx20.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv @@ -501,6 +501,7 @@ list version locale atomic locale cctype +locale clocale locale concepts locale cstdarg locale cstddef @@ -509,6 +510,7 @@ locale cstdlib locale cstring locale ctime +locale cwchar locale initializer_list locale ios locale iosfwd diff --git a/libcxx/test/libcxx/transitive_includes/cxx2b.csv b/libcxx/test/libcxx/transitive_includes/cxx2b.csv --- a/libcxx/test/libcxx/transitive_includes/cxx2b.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx2b.csv @@ -354,12 +354,14 @@ list tuple list version locale cctype +locale clocale locale cstddef locale cstdint locale cstdio locale cstdlib locale cstring locale ctime +locale cwchar locale initializer_list locale ios locale iosfwd