[libcxx-commits] [libcxx] [libc++] Move the locale support headers to __locale_dir/locale_base_api/ (PR #74522)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 5 12:52:33 PST 2023


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/74522

Spies: arichardson, krytarowski, fedor.sergeev, phosek, abrachet

Differential Revision: https://reviews.llvm.org/D147869


>From 49e7cbc460927eab140dd3420f454a9c8d432299 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 5 Dec 2023 17:56:28 +0100
Subject: [PATCH] [libc++] Move the locale support headers to
 __locale_dir/locale_base_api/

Spies: arichardson, krytarowski, fedor.sergeev, phosek, abrachet

Differential Revision: https://reviews.llvm.org/D147869
---
 libcxx/include/CMakeLists.txt                 |  8 +--
 libcxx/include/__locale                       | 26 +-------
 libcxx/include/__locale_dir/locale_base_api.h | 63 +++++++++++++++++++
 .../locale_base_api/android.h}                |  6 +-
 .../locale_base_api/fuchsia.h}                |  6 +-
 .../locale_base_api/ibm.h}                    |  6 +-
 .../locale_base_api/musl.h}                   |  6 +-
 .../locale_base_api/newlib.h}                 |  6 +-
 .../locale_base_api/openbsd.h}                |  6 +-
 .../locale_base_api/win32.h}                  |  6 +-
 libcxx/include/module.modulemap.in            |  1 +
 11 files changed, 88 insertions(+), 52 deletions(-)
 create mode 100644 libcxx/include/__locale_dir/locale_base_api.h
 rename libcxx/include/{__support/android/locale_bionic.h => __locale_dir/locale_base_api/android.h} (92%)
 rename libcxx/include/{__support/fuchsia/xlocale.h => __locale_dir/locale_base_api/fuchsia.h} (79%)
 rename libcxx/include/{__support/ibm/xlocale.h => __locale_dir/locale_base_api/ibm.h} (95%)
 rename libcxx/include/{__support/musl/xlocale.h => __locale_dir/locale_base_api/musl.h} (91%)
 rename libcxx/include/{__support/newlib/xlocale.h => __locale_dir/locale_base_api/newlib.h} (81%)
 rename libcxx/include/{__support/openbsd/xlocale.h => __locale_dir/locale_base_api/openbsd.h} (85%)
 rename libcxx/include/{__support/win32/locale_win32.h => __locale_dir/locale_base_api/win32.h} (98%)

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index d8faf6467b79a..73999a46feda7 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -484,6 +484,7 @@ set(files
   __iterator/unreachable_sentinel.h
   __iterator/wrap_iter.h
   __locale
+  __locale_dir/locale_base_api.h
   __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
@@ -662,16 +663,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 ab36939f9c14c..96adac3265a9f 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -12,10 +12,9 @@
 
 #include <__availability>
 #include <__config>
-#include <__memory/shared_ptr.h> // __shared_count
+#include <__locale_dir/locale_base_api.h>
+#include <__memory/shared_ptr.h>
 #include <__mutex/once_flag.h>
-#include <__type_traits/make_unsigned.h>
-#include <__utility/no_destroy.h>
 #include <cctype>
 #include <clocale>
 #include <cstdint>
@@ -32,27 +31,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 0000000000000..0b79425088976
--- /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 <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, ...);
+
+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
similarity index 92%
rename from libcxx/include/__support/android/locale_bionic.h
rename to libcxx/include/__locale_dir/locale_base_api/android.h
index 30e345cf9ee1c..1f4c621e76f26 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 1e4ece8dd3e57..561d99e8154ac 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 03302b0d4f04d..6d5cd9fab5251 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>
@@ -126,4 +126,4 @@ vasprintf(char **strp, const char *fmt, va_list ap) {
 #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 9b0a50b04f82d..e4121ec1a9f48 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 4e546500fcf02..4639e0b63bc36 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)
 
@@ -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
similarity index 85%
rename from libcxx/include/__support/openbsd/xlocale.h
rename to libcxx/include/__locale_dir/locale_base_api/openbsd.h
index b969ae9d106a7..623abdb4db840 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 d40e80e344e68..f50553634face 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>
@@ -279,4 +279,4 @@ 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 90ee7fbb2157c..c585a2f344905 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1465,6 +1465,7 @@ module std_private_iterator_wrap_iter               [system] { header "__iterato
 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_locale_guard         [system] { header "__locale_dir/locale_base_api/locale_guard.h" }
+module std_private_locale_locale_base_api                      [system] { header "__locale_dir/locale_base_api/locale_base_api.h" }
 
 module std_private_math_abs                             [system] { header "__math/abs.h" }
 module std_private_math_copysign                        [system] { header "__math/copysign.h" }



More information about the libcxx-commits mailing list