[libcxx-commits] [libcxx] [libc++] Move the locale support headers to __locale_dir/locale_base_api/ (PR #74522)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 1 09:21:26 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
Differential Revision: https://reviews.llvm.org/D147869
---
Full diff: https://github.com/llvm/llvm-project/pull/74522.diff
11 Files Affected:
- (modified) libcxx/include/CMakeLists.txt (+8-7)
- (modified) libcxx/include/__locale (+1-21)
- (added) libcxx/include/__locale_dir/locale_base_api.h (+112)
- (renamed) libcxx/include/__locale_dir/locale_base_api/android.h (+3-3)
- (renamed) libcxx/include/__locale_dir/locale_base_api/fuchsia.h (+3-3)
- (renamed) libcxx/include/__locale_dir/locale_base_api/ibm.h (+3-3)
- (renamed) libcxx/include/__locale_dir/locale_base_api/musl.h (+3-3)
- (renamed) libcxx/include/__locale_dir/locale_base_api/newlib.h (+3-3)
- (renamed) libcxx/include/__locale_dir/locale_base_api/openbsd.h (+3-3)
- (renamed) libcxx/include/__locale_dir/locale_base_api/win32.h (+3-3)
- (modified) libcxx/include/module.modulemap.in (+8)
``````````diff
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0fe3ab44d2466e..2e95a3125ed436 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -487,9 +487,17 @@ set(files
__iterator/unreachable_sentinel.h
__iterator/wrap_iter.h
__locale
+ __locale_dir/locale_base_api.h
+ __locale_dir/locale_base_api/android.h
__locale_dir/locale_base_api/bsd_locale_defaults.h
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
+ __locale_dir/locale_base_api/fuchsia.h
+ __locale_dir/locale_base_api/ibm.h
__locale_dir/locale_base_api/locale_guard.h
+ __locale_dir/locale_base_api/musl.h
+ __locale_dir/locale_base_api/newlib.h
+ __locale_dir/locale_base_api/openbsd.h
+ __locale_dir/locale_base_api/win32.h
__math/abs.h
__math/copysign.h
__math/error_functions.h
@@ -665,16 +673,9 @@ set(files
__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/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
index 3ba7ac18b0b36d..2186db84933103 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -12,6 +12,7 @@
#include <__availability>
#include <__config>
+#include <__locale_dir/locale_base_api.h>
#include <__memory/shared_ptr.h> // __shared_count
#include <__mutex/once_flag.h>
#include <__type_traits/make_unsigned.h>
@@ -32,27 +33,6 @@
# include <__std_mbstate_t.h>
#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(_NEWLIB_VERSION)
-# include <__support/newlib/xlocale.h>
-#elif defined(__OpenBSD__)
-# include <__support/openbsd/xlocale.h>
-#elif (defined(__APPLE__) || defined(__FreeBSD__))
-# include <xlocale.h>
-#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
index 00000000000000..2355b4a840d734
--- /dev/null
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -0,0 +1,112 @@
+//===-----------------------------------------------------------------------===//
+//
+// 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 <xlocale.h>
+#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, ...);
+
+// TODO: change these to reserved names
+float strtof_l(const char* str, char** str_end, locale_t);
+double strtod_l(const char* str, char** str_end, locale_t);
+long double strtold_l(const char* str, char** str_end, locale_t);
+long long strtoll_l(const char* str, char** str_end, locale_t);
+unsigned long long strtoull_l(const char* str, char** str_end, locale_t);
+
+locale_t newlocale(int category_mask, const char* locale, locale_t base);
+void freelocale(locale_t);
+
+int islower_l(int ch, locale_t);
+int isupper_l(int ch, locale_t);
+int isdigit_l(int ch, locale_t);
+int isxdigit_l(int ch, locale_t);
+int strcoll_l(const char* lhs, const char* rhs, locale_t);
+size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t);
+int wcscoll_l(const char* lhs, const char* rhs, locale_t);
+size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t);
+int toupper_l(int ch, locale_t);
+int tolower_l(int ch, locale_t);
+int iswspace_l(wint_t ch, locale_t);
+int iswprint_l(wint_t ch, locale_t);
+int iswcntrl_l(wint_t ch, locale_t);
+int iswupper_l(wint_t ch, locale_t);
+int iswlower_l(wint_t ch, locale_t);
+int iswalpha_l(wint_t ch, locale_t);
+int iswblank_l(wint_t ch, locale_t);
+int iswdigit_l(wint_t ch, locale_t);
+int iswpunct_l(wint_t ch, locale_t);
+int iswxdigit_l(wint_t ch, locale_t);
+wint_t towupper_l(wint_t ch, locale_t);
+wint_t towlower_l(wint_t ch, locale_t);
+size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t);
+
+
+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 pack instead of variadic functions.
+*/
+
+/*
+// TODO: These symbols are never actually used, but defined by one or more implementations. They should be removed.
+long strtol_l(const char* str, char** str_end, locale_t);
+unsigned long strtoul_l(const char* str, char** str_end, locale_t);
+long long wcstoll_l(const wchar_t* str, wchar_t** str_end, int base, locale_t);
+unsigned long long wcstoull_l(const wchar_t* str, wchar_t** str_end, int base, locale_t);
+long double wcstold_l(const wchar_t* str, wchar_t** str_end, int base, locale_t);
+int sprintf_l(char* str, const char* format, locale_t, ...);
+int vsprintf_l(char* str, const char* format, locale_t, va_list);
+int vsnprintf_l(char* str, size_t size, const char* format, locale_t, va_list);
+int isblank_l(int ch, locale_t);
+
+*/
+
+#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
similarity index 92%
rename from libcxx/include/__support/android/locale_bionic.h
rename to libcxx/include/__locale_dir/locale_base_api/android.h
index fee2ba5df34f25..c2dea1e731cf2c 100644
--- 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 @@ inline _LIBCPP_HIDE_FROM_ABI_C long strtol_l(const char* __nptr, char** __endptr
# 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
similarity index 79%
rename from libcxx/include/__support/fuchsia/xlocale.h
rename to libcxx/include/__locale_dir/locale_base_api/fuchsia.h
index 957d5cb47dd749..f999bead234e5c 100644
--- 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
similarity index 95%
rename from libcxx/include/__support/ibm/xlocale.h
rename to libcxx/include/__locale_dir/locale_base_api/ibm.h
index 52538e264c03e5..f2211b5c8f0e67 100644
--- 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>
@@ -119,4 +119,4 @@ inline _LIBCPP_HIDE_FROM_ABI int vasprintf(char** strp, const char* fmt, va_list
#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
similarity index 91%
rename from libcxx/include/__support/musl/xlocale.h
rename to libcxx/include/__locale_dir/locale_base_api/musl.h
index 9b0a50b04f82df..e4121ec1a9f486 100644
--- 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 <cstdlib>
#include <cwchar>
@@ -50,4 +50,4 @@ inline _LIBCPP_HIDE_FROM_ABI_C long double wcstold_l(const wchar_t* __nptr, wcha
}
#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
similarity index 81%
rename from libcxx/include/__support/newlib/xlocale.h
rename to libcxx/include/__locale_dir/locale_base_api/newlib.h
index 9c57bf42ab09b4..8d030cb73209f8 100644
--- 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)
@@ -19,4 +19,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
similarity index 85%
rename from libcxx/include/__support/openbsd/xlocale.h
rename to libcxx/include/__locale_dir/locale_base_api/openbsd.h
index b969ae9d106a79..623abdb4db8406 100644
--- 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 <clocale>
@@ -32,4 +32,4 @@ inline _LIBCPP_HIDE_FROM_ABI_C unsigned long strtoul_l(const char* __nptr, char*
}
#endif
-#endif
+#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H
diff --git a/libcxx/include/__support/win32/locale_win32.h b/libcxx/include/__locale_dir/locale_base_api/win32.h
similarity index 98%
rename from libcxx/include/__support/win32/locale_win32.h
rename to libcxx/include/__locale_dir/locale_base_api/win32.h
index 55e818e63a8412..5dfacfb9c1ee9d 100644
--- 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 <cstddef>
@@ -236,4 +236,4 @@ _LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const ch
inline int isblank_l(int __c, locale_t /*loc*/) { return (__c == ' ' || __c == '\t'); }
inline int iswblank_l(wint_t __c, locale_t /*loc*/) { 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
index d10670d4faaffc..1dbbd3a0ba008f 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1463,9 +1463,17 @@ module std_private_iterator_sortable [system] {
module std_private_iterator_unreachable_sentinel [system] { header "__iterator/unreachable_sentinel.h" }
module std_private_iterator_wrap_iter [system] { header "__iterator/wrap_iter.h" }
+module std_private_locale_locale_base_api_android [system] { textual header "__locale_dir/locale_base_api/android.h" }
module std_private_locale_locale_base_api_bsd_locale_defaults [system] { textual header "__locale_dir/locale_base_api/bsd_locale_defaults.h" }
module std_private_locale_locale_base_api_bsd_locale_fallbacks [system] { textual header "__locale_dir/locale_base_api/bsd_locale_fallbacks.h" }
+module std_private_locale_locale_base_api_fuchsia [system] { textual header "__locale_dir/locale_base_api/fuchsia.h" }
+module std_private_locale_locale_base_api_ibm [system] { textual header "__locale_dir/locale_base_api/ibm.h" }
module std_private_locale_locale_base_api_locale_guard [system] { header "__locale_dir/locale_base_api/locale_guard.h" }
+module std_private_locale_locale_base_api_musl [system] { textual header "__locale_dir/locale_base_api/musl.h" }
+module std_private_locale_locale_base_api_newlib [system] { textual header "__locale_dir/locale_base_api/newlib.h" }
+module std_private_locale_locale_base_api_openbsd [system] { textual header "__locale_dir/locale_base_api/openbsd.h" }
+module std_private_locale_locale_base_api_win32 [system] { textual header "__locale_dir/locale_base_api/win32.h" }
+module std_private_locale_locale_base_api [system] { header "__locale_dir/locale_base_api.h" }
module std_private_math_abs [system] { header "__math/abs.h" }
module std_private_math_copysign [system] { header "__math/copysign.h" }
``````````
</details>
https://github.com/llvm/llvm-project/pull/74522
More information about the libcxx-commits
mailing list