diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -440,6 +440,7 @@ __locale_dir/locale_base_api/bsd_locale_defaults.h __locale_dir/locale_base_api/bsd_locale_fallbacks.h __locale_dir/locale_base_api/locale_guard.h + __locale_dir/locale_base_api.h __mbstate_t.h __memory/addressof.h __memory/align.h @@ -574,19 +575,11 @@ __string/char_traits.h __string/constexpr_c_functions.h __string/extern_template_lists.h - __support/android/locale_bionic.h - __support/fuchsia/xlocale.h __support/ibm/gettod_zos.h __support/ibm/locale_mgmt_zos.h __support/ibm/nanosleep.h - __support/ibm/xlocale.h - __support/musl/xlocale.h - __support/newlib/xlocale.h - __support/openbsd/xlocale.h __support/solaris/floatingpoint.h __support/solaris/wchar.h - __support/solaris/xlocale.h - __support/win32/locale_win32.h __support/xlocale/__nop_locale_mgmt.h __support/xlocale/__posix_l_fallback.h __support/xlocale/__strtonum_fallback.h diff --git a/libcxx/include/__locale b/libcxx/include/__locale --- a/libcxx/include/__locale +++ b/libcxx/include/__locale @@ -12,6 +12,7 @@ #include <__availability> #include <__config> +#include <__locale_dir/locale_base_api.h> #include #include #include @@ -26,30 +27,6 @@ # include #endif -#if defined(_LIBCPP_MSVCRT_LIKE) -# include <__support/win32/locale_win32.h> -#elif defined(_AIX) || defined(__MVS__) -# include <__support/ibm/xlocale.h> -#elif defined(__ANDROID__) -# include <__support/android/locale_bionic.h> -#elif defined(__sun__) -# include <__support/solaris/xlocale.h> -# include -#elif defined(_NEWLIB_VERSION) -# include <__support/newlib/xlocale.h> -#elif defined(__OpenBSD__) -# include <__support/openbsd/xlocale.h> -#elif (defined(__APPLE__) || defined(__FreeBSD__)) -# include -#elif defined(__Fuchsia__) -# include <__support/fuchsia/xlocale.h> -#elif defined(__wasi__) -// WASI libc uses musl's locales support. -# include <__support/musl/xlocale.h> -#elif defined(_LIBCPP_HAS_MUSL_LIBC) -# include <__support/musl/xlocale.h> -#endif - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__locale_dir/locale_base_api.h @@ -0,0 +1,63 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H + +#if defined(_LIBCPP_MSVCRT_LIKE) +# include <__locale_dir/locale_base_api/win32.h> +#elif defined(_AIX) || defined(__MVS__) +# include <__locale_dir/locale_base_api/ibm.h> +#elif defined(__ANDROID__) +# include <__locale_dir/locale_base_api/android.h> +#elif defined(__sun__) +# include <__locale_dir/locale_base_api/solaris.h> +#elif defined(_NEWLIB_VERSION) +# include <__locale_dir/locale_base_api/newlib.h> +#elif defined(__OpenBSD__) +# include <__locale_dir/locale_base_api/openbsd.h> +#elif defined(__Fuchsia__) +# include <__locale_dir/locale_base_api/fuchsia.h> +#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) +# include <__locale_dir/locale_base_api/musl.h> +#elif defined(__APPLE__) || defined(__FreeBSD__) +# include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +/* +The platform-specific headers have to provide the following interface: + +// TODO: rename this to __libcpp_locale_t +using locale_t = //implementation-defined//; + +//implementation-defined// __libcpp_mb_cur_max_l(locale_t); +wint_t __libcpp_btowc_l(int, locale_t); +int __libcpp_wctob_l(wint_t, locale_t); +size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t); +size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t); +size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t); +size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t); +int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t); +size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t); +lconv* __libcpp_localeconv_l(locale_t); +size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t); +int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...); +int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...); +int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...); + +These functions are equivalent to their C counterparts, +except that locale_t is used instead of the current global locale. + +The variadic functions may be implemented as templates with a parameter pacj instead of variadic functions +*/ + +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H diff --git a/libcxx/include/__support/android/locale_bionic.h b/libcxx/include/__locale_dir/locale_base_api/android.h rename from libcxx/include/__support/android/locale_bionic.h rename to libcxx/include/__locale_dir/locale_base_api/android.h --- a/libcxx/include/__support/android/locale_bionic.h +++ b/libcxx/include/__locale_dir/locale_base_api/android.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H -#define _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H #if defined(__BIONIC__) @@ -69,4 +69,4 @@ #endif // defined(__ANDROID__) #endif // defined(__BIONIC__) -#endif // _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H diff --git a/libcxx/include/__support/fuchsia/xlocale.h b/libcxx/include/__locale_dir/locale_base_api/fuchsia.h rename from libcxx/include/__support/fuchsia/xlocale.h rename to libcxx/include/__locale_dir/locale_base_api/fuchsia.h --- a/libcxx/include/__support/fuchsia/xlocale.h +++ b/libcxx/include/__locale_dir/locale_base_api/fuchsia.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H -#define _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H #if defined(__Fuchsia__) @@ -19,4 +19,4 @@ #endif // defined(__Fuchsia__) -#endif // _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H diff --git a/libcxx/include/__support/ibm/xlocale.h b/libcxx/include/__locale_dir/locale_base_api/ibm.h rename from libcxx/include/__support/ibm/xlocale.h rename to libcxx/include/__locale_dir/locale_base_api/ibm.h --- a/libcxx/include/__support/ibm/xlocale.h +++ b/libcxx/include/__locale_dir/locale_base_api/ibm.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_IBM_XLOCALE_H -#define _LIBCPP___SUPPORT_IBM_XLOCALE_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H #if defined(__MVS__) #include <__support/ibm/locale_mgmt_zos.h> @@ -126,4 +126,4 @@ #ifdef __cplusplus } #endif -#endif // _LIBCPP___SUPPORT_IBM_XLOCALE_H +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H diff --git a/libcxx/include/__support/musl/xlocale.h b/libcxx/include/__locale_dir/locale_base_api/musl.h rename from libcxx/include/__support/musl/xlocale.h rename to libcxx/include/__locale_dir/locale_base_api/musl.h --- a/libcxx/include/__support/musl/xlocale.h +++ b/libcxx/include/__locale_dir/locale_base_api/musl.h @@ -14,8 +14,8 @@ // in Musl. //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_MUSL_XLOCALE_H -#define _LIBCPP___SUPPORT_MUSL_XLOCALE_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H #include #include @@ -49,4 +49,4 @@ } #endif -#endif // _LIBCPP___SUPPORT_MUSL_XLOCALE_H +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H diff --git a/libcxx/include/__support/newlib/xlocale.h b/libcxx/include/__locale_dir/locale_base_api/newlib.h rename from libcxx/include/__support/newlib/xlocale.h rename to libcxx/include/__locale_dir/locale_base_api/newlib.h --- a/libcxx/include/__support/newlib/xlocale.h +++ b/libcxx/include/__locale_dir/locale_base_api/newlib.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_NEWLIB_XLOCALE_H -#define _LIBCPP___SUPPORT_NEWLIB_XLOCALE_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H #if defined(_NEWLIB_VERSION) @@ -20,4 +20,4 @@ #endif // _NEWLIB_VERSION -#endif +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H diff --git a/libcxx/include/__support/openbsd/xlocale.h b/libcxx/include/__locale_dir/locale_base_api/openbsd.h rename from libcxx/include/__support/openbsd/xlocale.h rename to libcxx/include/__locale_dir/locale_base_api/openbsd.h --- a/libcxx/include/__support/openbsd/xlocale.h +++ b/libcxx/include/__locale_dir/locale_base_api/openbsd.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_OPENBSD_XLOCALE_H -#define _LIBCPP___SUPPORT_OPENBSD_XLOCALE_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H #include <__support/xlocale/__strtonum_fallback.h> #include @@ -32,4 +32,4 @@ } #endif -#endif +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H diff --git a/libcxx/include/__support/solaris/xlocale.h b/libcxx/include/__locale_dir/locale_base_api/solaris.h rename from libcxx/include/__support/solaris/xlocale.h rename to libcxx/include/__locale_dir/locale_base_api/solaris.h --- a/libcxx/include/__support/solaris/xlocale.h +++ b/libcxx/include/__locale_dir/locale_base_api/solaris.h @@ -10,8 +10,8 @@ // Minimal xlocale implementation for Solaris. This implements the subset of // the xlocale APIs that libc++ depends on. //////////////////////////////////////////////////////////////////////////////// -#ifndef __XLOCALE_H_INCLUDED -#define __XLOCALE_H_INCLUDED +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_SOLARIS_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_SOLARIS_H #include @@ -72,4 +72,4 @@ } #endif -#endif +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_SOLARIS_H diff --git a/libcxx/include/__support/win32/locale_win32.h b/libcxx/include/__locale_dir/locale_base_api/win32.h rename from libcxx/include/__support/win32/locale_win32.h rename to libcxx/include/__locale_dir/locale_base_api/win32.h --- a/libcxx/include/__support/win32/locale_win32.h +++ b/libcxx/include/__locale_dir/locale_base_api/win32.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H -#define _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H +#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H +#define _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H #include <__config> #include @@ -279,4 +279,4 @@ return ( __c == L' ' || __c == L'\t' ); } -#endif // _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H +#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -1112,6 +1112,10 @@ @requires_LIBCXX_ENABLE_LOCALIZATION@ header "locale" export * + + module __locale { + module locale_base_api { private header "__locale_dir/locale_base_api.h" } + } } module map { header "map" diff --git a/libcxx/utils/data/ignore_format.txt b/libcxx/utils/data/ignore_format.txt --- a/libcxx/utils/data/ignore_format.txt +++ b/libcxx/utils/data/ignore_format.txt @@ -455,9 +455,15 @@ libcxx/include/list libcxx/include/__locale libcxx/include/locale +libcxx/include/__locale_dir/locale_base_api/android.h libcxx/include/__locale_dir/locale_base_api/bsd_locale_defaults.h libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h +libcxx/include/__locale_dir/locale_base_api/fuchsia.h +libcxx/include/__locale_dir/locale_base_api/ibm.h libcxx/include/__locale_dir/locale_base_api/locale_guard.h +libcxx/include/__locale_dir/locale_base_api/newlib.h +libcxx/include/__locale_dir/locale_base_api/solaris.h +libcxx/include/__locale_dir/locale_base_api/win32.h libcxx/include/locale.h libcxx/include/map libcxx/include/math.h @@ -602,15 +608,9 @@ libcxx/include/string.h libcxx/include/string_view libcxx/include/strstream -libcxx/include/__support/android/locale_bionic.h -libcxx/include/__support/fuchsia/xlocale.h libcxx/include/__support/ibm/gettod_zos.h libcxx/include/__support/ibm/locale_mgmt_zos.h libcxx/include/__support/ibm/nanosleep.h -libcxx/include/__support/ibm/xlocale.h -libcxx/include/__support/newlib/xlocale.h -libcxx/include/__support/solaris/xlocale.h -libcxx/include/__support/win32/locale_win32.h libcxx/include/__support/xlocale/__nop_locale_mgmt.h libcxx/include/system_error libcxx/include/thread