Skip to content

Commit 829a258

Browse files
philnik777agozillon
authored andcommitted
[libc++] Move the locale support headers to __locale_dir/locale_base_api/ (llvm#74522)
Differential Revision: https://reviews.llvm.org/D147869
1 parent 4ed6729 commit 829a258

File tree

13 files changed

+168
-53
lines changed

13 files changed

+168
-53
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,17 @@ set(files
487487
__iterator/unreachable_sentinel.h
488488
__iterator/wrap_iter.h
489489
__locale
490+
__locale_dir/locale_base_api.h
491+
__locale_dir/locale_base_api/android.h
490492
__locale_dir/locale_base_api/bsd_locale_defaults.h
491493
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
494+
__locale_dir/locale_base_api/fuchsia.h
495+
__locale_dir/locale_base_api/ibm.h
492496
__locale_dir/locale_base_api/locale_guard.h
497+
__locale_dir/locale_base_api/musl.h
498+
__locale_dir/locale_base_api/newlib.h
499+
__locale_dir/locale_base_api/openbsd.h
500+
__locale_dir/locale_base_api/win32.h
493501
__math/abs.h
494502
__math/copysign.h
495503
__math/error_functions.h
@@ -666,16 +674,9 @@ set(files
666674
__string/char_traits.h
667675
__string/constexpr_c_functions.h
668676
__string/extern_template_lists.h
669-
__support/android/locale_bionic.h
670-
__support/fuchsia/xlocale.h
671677
__support/ibm/gettod_zos.h
672678
__support/ibm/locale_mgmt_zos.h
673679
__support/ibm/nanosleep.h
674-
__support/ibm/xlocale.h
675-
__support/musl/xlocale.h
676-
__support/newlib/xlocale.h
677-
__support/openbsd/xlocale.h
678-
__support/win32/locale_win32.h
679680
__support/xlocale/__nop_locale_mgmt.h
680681
__support/xlocale/__posix_l_fallback.h
681682
__support/xlocale/__strtonum_fallback.h

libcxx/include/__locale

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <__availability>
1414
#include <__config>
15+
#include <__locale_dir/locale_base_api.h>
1516
#include <__memory/shared_ptr.h> // __shared_count
1617
#include <__mutex/once_flag.h>
1718
#include <__type_traits/make_unsigned.h>
@@ -32,27 +33,6 @@
3233
# include <__std_mbstate_t.h>
3334
#endif
3435

35-
#if defined(_LIBCPP_MSVCRT_LIKE)
36-
# include <__support/win32/locale_win32.h>
37-
#elif defined(_AIX) || defined(__MVS__)
38-
# include <__support/ibm/xlocale.h>
39-
#elif defined(__ANDROID__)
40-
# include <__support/android/locale_bionic.h>
41-
#elif defined(_NEWLIB_VERSION)
42-
# include <__support/newlib/xlocale.h>
43-
#elif defined(__OpenBSD__)
44-
# include <__support/openbsd/xlocale.h>
45-
#elif (defined(__APPLE__) || defined(__FreeBSD__))
46-
# include <xlocale.h>
47-
#elif defined(__Fuchsia__)
48-
# include <__support/fuchsia/xlocale.h>
49-
#elif defined(__wasi__)
50-
// WASI libc uses musl's locales support.
51-
# include <__support/musl/xlocale.h>
52-
#elif defined(_LIBCPP_HAS_MUSL_LIBC)
53-
# include <__support/musl/xlocale.h>
54-
#endif
55-
5636
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5737
# pragma GCC system_header
5838
#endif
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//===-----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
10+
#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
11+
12+
#if defined(_LIBCPP_MSVCRT_LIKE)
13+
# include <__locale_dir/locale_base_api/win32.h>
14+
#elif defined(_AIX) || defined(__MVS__)
15+
# include <__locale_dir/locale_base_api/ibm.h>
16+
#elif defined(__ANDROID__)
17+
# include <__locale_dir/locale_base_api/android.h>
18+
#elif defined(__sun__)
19+
# include <__locale_dir/locale_base_api/solaris.h>
20+
#elif defined(_NEWLIB_VERSION)
21+
# include <__locale_dir/locale_base_api/newlib.h>
22+
#elif defined(__OpenBSD__)
23+
# include <__locale_dir/locale_base_api/openbsd.h>
24+
#elif defined(__Fuchsia__)
25+
# include <__locale_dir/locale_base_api/fuchsia.h>
26+
#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
27+
# include <__locale_dir/locale_base_api/musl.h>
28+
#elif defined(__APPLE__) || defined(__FreeBSD__)
29+
# include <xlocale.h>
30+
#endif
31+
32+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33+
# pragma GCC system_header
34+
#endif
35+
36+
/*
37+
The platform-specific headers have to provide the following interface:
38+
39+
// TODO: rename this to __libcpp_locale_t
40+
using locale_t = implementation-defined;
41+
42+
implementation-defined __libcpp_mb_cur_max_l(locale_t);
43+
wint_t __libcpp_btowc_l(int, locale_t);
44+
int __libcpp_wctob_l(wint_t, locale_t);
45+
size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t);
46+
size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t);
47+
size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t);
48+
size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t);
49+
int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t);
50+
size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t);
51+
lconv* __libcpp_localeconv_l(locale_t);
52+
size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t);
53+
int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...);
54+
int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...);
55+
int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...);
56+
57+
// TODO: change these to reserved names
58+
float strtof_l(const char* str, char** str_end, locale_t);
59+
double strtod_l(const char* str, char** str_end, locale_t);
60+
long double strtold_l(const char* str, char** str_end, locale_t);
61+
long long strtoll_l(const char* str, char** str_end, locale_t);
62+
unsigned long long strtoull_l(const char* str, char** str_end, locale_t);
63+
64+
locale_t newlocale(int category_mask, const char* locale, locale_t base);
65+
void freelocale(locale_t);
66+
67+
int islower_l(int ch, locale_t);
68+
int isupper_l(int ch, locale_t);
69+
int isdigit_l(int ch, locale_t);
70+
int isxdigit_l(int ch, locale_t);
71+
int strcoll_l(const char* lhs, const char* rhs, locale_t);
72+
size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t);
73+
int wcscoll_l(const char* lhs, const char* rhs, locale_t);
74+
size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t);
75+
int toupper_l(int ch, locale_t);
76+
int tolower_l(int ch, locale_t);
77+
int iswspace_l(wint_t ch, locale_t);
78+
int iswprint_l(wint_t ch, locale_t);
79+
int iswcntrl_l(wint_t ch, locale_t);
80+
int iswupper_l(wint_t ch, locale_t);
81+
int iswlower_l(wint_t ch, locale_t);
82+
int iswalpha_l(wint_t ch, locale_t);
83+
int iswblank_l(wint_t ch, locale_t);
84+
int iswdigit_l(wint_t ch, locale_t);
85+
int iswpunct_l(wint_t ch, locale_t);
86+
int iswxdigit_l(wint_t ch, locale_t);
87+
wint_t towupper_l(wint_t ch, locale_t);
88+
wint_t towlower_l(wint_t ch, locale_t);
89+
size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t);
90+
91+
92+
These functions are equivalent to their C counterparts,
93+
except that locale_t is used instead of the current global locale.
94+
95+
The variadic functions may be implemented as templates with a parameter pack instead of variadic functions.
96+
*/
97+
98+
/*
99+
// TODO: These symbols are never actually used, but defined by one or more implementations. They should be removed.
100+
long strtol_l(const char* str, char** str_end, locale_t);
101+
unsigned long strtoul_l(const char* str, char** str_end, locale_t);
102+
long long wcstoll_l(const wchar_t* str, wchar_t** str_end, int base, locale_t);
103+
unsigned long long wcstoull_l(const wchar_t* str, wchar_t** str_end, int base, locale_t);
104+
long double wcstold_l(const wchar_t* str, wchar_t** str_end, int base, locale_t);
105+
int sprintf_l(char* str, const char* format, locale_t, ...);
106+
int vsprintf_l(char* str, const char* format, locale_t, va_list);
107+
int vsnprintf_l(char* str, size_t size, const char* format, locale_t, va_list);
108+
int isblank_l(int ch, locale_t);
109+
110+
*/
111+
112+
#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H

libcxx/include/__support/android/locale_bionic.h renamed to libcxx/include/__locale_dir/locale_base_api/android.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H
11-
#define _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
1212

1313
#if defined(__BIONIC__)
1414

@@ -69,4 +69,4 @@ inline _LIBCPP_HIDE_FROM_ABI_C long strtol_l(const char* __nptr, char** __endptr
6969
# endif // defined(__ANDROID__)
7070

7171
#endif // defined(__BIONIC__)
72-
#endif // _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H
72+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H

libcxx/include/__support/fuchsia/xlocale.h renamed to libcxx/include/__locale_dir/locale_base_api/fuchsia.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H
11-
#define _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H
1212

1313
#if defined(__Fuchsia__)
1414

@@ -19,4 +19,4 @@
1919

2020
#endif // defined(__Fuchsia__)
2121

22-
#endif // _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H
22+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H

libcxx/include/__support/ibm/xlocale.h renamed to libcxx/include/__locale_dir/locale_base_api/ibm.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___SUPPORT_IBM_XLOCALE_H
11-
#define _LIBCPP___SUPPORT_IBM_XLOCALE_H
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H
1212

1313
#if defined(__MVS__)
1414
# include <__support/ibm/locale_mgmt_zos.h>
1515
#endif // defined(__MVS__)
1616

17+
#include <locale.h>
1718
#include <stdarg.h>
19+
#include <stdio.h>
1820

1921
#include "cstdlib"
2022

@@ -119,4 +121,4 @@ inline _LIBCPP_HIDE_FROM_ABI int vasprintf(char** strp, const char* fmt, va_list
119121
#ifdef __cplusplus
120122
}
121123
#endif
122-
#endif // _LIBCPP___SUPPORT_IBM_XLOCALE_H
124+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H

libcxx/include/__support/musl/xlocale.h renamed to libcxx/include/__locale_dir/locale_base_api/musl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// in Musl.
1515
//===----------------------------------------------------------------------===//
1616

17-
#ifndef _LIBCPP___SUPPORT_MUSL_XLOCALE_H
18-
#define _LIBCPP___SUPPORT_MUSL_XLOCALE_H
17+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H
18+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H
1919

2020
#include <cstdlib>
2121
#include <cwchar>
@@ -50,4 +50,4 @@ inline _LIBCPP_HIDE_FROM_ABI_C long double wcstold_l(const wchar_t* __nptr, wcha
5050
}
5151
#endif
5252

53-
#endif // _LIBCPP___SUPPORT_MUSL_XLOCALE_H
53+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H

libcxx/include/__support/newlib/xlocale.h renamed to libcxx/include/__locale_dir/locale_base_api/newlib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef _LIBCPP___SUPPORT_NEWLIB_XLOCALE_H
10-
#define _LIBCPP___SUPPORT_NEWLIB_XLOCALE_H
9+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H
10+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H
1111

1212
#if defined(_NEWLIB_VERSION)
1313

@@ -19,4 +19,4 @@
1919

2020
#endif // _NEWLIB_VERSION
2121

22-
#endif
22+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H

libcxx/include/__support/openbsd/xlocale.h renamed to libcxx/include/__locale_dir/locale_base_api/openbsd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___SUPPORT_OPENBSD_XLOCALE_H
11-
#define _LIBCPP___SUPPORT_OPENBSD_XLOCALE_H
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H
1212

1313
#include <__support/xlocale/__strtonum_fallback.h>
1414
#include <clocale>
@@ -32,4 +32,4 @@ inline _LIBCPP_HIDE_FROM_ABI_C unsigned long strtoul_l(const char* __nptr, char*
3232
}
3333
#endif
3434

35-
#endif
35+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H

libcxx/include/__support/win32/locale_win32.h renamed to libcxx/include/__locale_dir/locale_base_api/win32.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#ifndef _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H
11-
#define _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H
1212

1313
#include <__config>
1414
#include <cstddef>
@@ -236,4 +236,4 @@ _LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const ch
236236
inline int isblank_l(int __c, locale_t /*loc*/) { return (__c == ' ' || __c == '\t'); }
237237
inline int iswblank_l(wint_t __c, locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); }
238238

239-
#endif // _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H
239+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H

libcxx/include/libcxx.imp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,17 @@
479479
{ include: [ "<__iterator/sortable.h>", "private", "<iterator>", "public" ] },
480480
{ include: [ "<__iterator/unreachable_sentinel.h>", "private", "<iterator>", "public" ] },
481481
{ include: [ "<__iterator/wrap_iter.h>", "private", "<iterator>", "public" ] },
482+
{ include: [ "<__locale_dir/locale_base_api.h>", "private", "<locale>", "public" ] },
483+
{ include: [ "<__locale_dir/locale_base_api/android.h>", "private", "<locale>", "public" ] },
482484
{ include: [ "<__locale_dir/locale_base_api/bsd_locale_defaults.h>", "private", "<locale>", "public" ] },
483485
{ include: [ "<__locale_dir/locale_base_api/bsd_locale_fallbacks.h>", "private", "<locale>", "public" ] },
486+
{ include: [ "<__locale_dir/locale_base_api/fuchsia.h>", "private", "<locale>", "public" ] },
487+
{ include: [ "<__locale_dir/locale_base_api/ibm.h>", "private", "<locale>", "public" ] },
484488
{ include: [ "<__locale_dir/locale_base_api/locale_guard.h>", "private", "<locale>", "public" ] },
489+
{ include: [ "<__locale_dir/locale_base_api/musl.h>", "private", "<locale>", "public" ] },
490+
{ include: [ "<__locale_dir/locale_base_api/newlib.h>", "private", "<locale>", "public" ] },
491+
{ include: [ "<__locale_dir/locale_base_api/openbsd.h>", "private", "<locale>", "public" ] },
492+
{ include: [ "<__locale_dir/locale_base_api/win32.h>", "private", "<locale>", "public" ] },
485493
{ include: [ "<__math/abs.h>", "private", "<cmath>", "public" ] },
486494
{ include: [ "<__math/copysign.h>", "private", "<cmath>", "public" ] },
487495
{ include: [ "<__math/error_functions.h>", "private", "<cmath>", "public" ] },

libcxx/include/module.modulemap.in

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,9 +1454,20 @@ module std_private_iterator_sortable [system] {
14541454
module std_private_iterator_unreachable_sentinel [system] { header "__iterator/unreachable_sentinel.h" }
14551455
module std_private_iterator_wrap_iter [system] { header "__iterator/wrap_iter.h" }
14561456

1457+
module std_private_locale_locale_base_api_android [system] { textual header "__locale_dir/locale_base_api/android.h" }
14571458
module std_private_locale_locale_base_api_bsd_locale_defaults [system] { textual header "__locale_dir/locale_base_api/bsd_locale_defaults.h" }
14581459
module std_private_locale_locale_base_api_bsd_locale_fallbacks [system] { textual header "__locale_dir/locale_base_api/bsd_locale_fallbacks.h" }
1460+
module std_private_locale_locale_base_api_fuchsia [system] { textual header "__locale_dir/locale_base_api/fuchsia.h" }
1461+
module std_private_locale_locale_base_api_ibm [system] { textual header "__locale_dir/locale_base_api/ibm.h" }
14591462
module std_private_locale_locale_base_api_locale_guard [system] { header "__locale_dir/locale_base_api/locale_guard.h" }
1463+
module std_private_locale_locale_base_api_musl [system] { textual header "__locale_dir/locale_base_api/musl.h" }
1464+
module std_private_locale_locale_base_api_newlib [system] { textual header "__locale_dir/locale_base_api/newlib.h" }
1465+
module std_private_locale_locale_base_api_openbsd [system] { textual header "__locale_dir/locale_base_api/openbsd.h" }
1466+
module std_private_locale_locale_base_api_win32 [system] { textual header "__locale_dir/locale_base_api/win32.h" }
1467+
module std_private_locale_locale_base_api [system] {
1468+
header "__locale_dir/locale_base_api.h"
1469+
export *
1470+
}
14601471

14611472
module std_private_math_abs [system] { header "__math/abs.h" }
14621473
module std_private_math_copysign [system] { header "__math/copysign.h" }
@@ -1914,7 +1925,10 @@ module std_private_type_traits_is_nothrow_constructible [system
19141925
module std_private_type_traits_is_nothrow_convertible [system] { header "__type_traits/is_nothrow_convertible.h" }
19151926
module std_private_type_traits_is_nothrow_copy_assignable [system] { header "__type_traits/is_nothrow_copy_assignable.h" }
19161927
module std_private_type_traits_is_nothrow_copy_constructible [system] { header "__type_traits/is_nothrow_copy_constructible.h" }
1917-
module std_private_type_traits_is_nothrow_default_constructible [system] { header "__type_traits/is_nothrow_default_constructible.h" }
1928+
module std_private_type_traits_is_nothrow_default_constructible [system] {
1929+
header "__type_traits/is_nothrow_default_constructible.h"
1930+
export std_private_type_traits_integral_constant
1931+
}
19181932
module std_private_type_traits_is_nothrow_destructible [system] {
19191933
header "__type_traits/is_nothrow_destructible.h"
19201934
export std_private_type_traits_is_destructible

libcxx/src/locale.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
# define _CTYPE_DISABLE_MACROS
3535
#endif
3636

37-
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
38-
# include "__support/win32/locale_win32.h"
39-
#elif !defined(__BIONIC__) && !defined(__NuttX__)
37+
#if !defined(_LIBCPP_MSVCRT) && !defined(__MINGW32__) && !defined(__BIONIC__) && !defined(__NuttX__)
4038
# include <langinfo.h>
4139
#endif
4240

0 commit comments

Comments
 (0)