Skip to content

Commit 6904b61

Browse files
committed
[libc++] Rename locale_t to __libcpp_locale_t
This is a step towards refactoring our amazingly complicated interface with the system's localization library. Instead of using locale_t and just assuming that the system provides it, use a proper libc++ internal name (and introduce that name properly).
1 parent 8aa69a0 commit 6904b61

File tree

22 files changed

+236
-166
lines changed

22 files changed

+236
-166
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,10 @@ set(files
492492
__locale
493493
__locale_dir/locale_base_api.h
494494
__locale_dir/locale_base_api/android.h
495+
__locale_dir/locale_base_api/apple.h
495496
__locale_dir/locale_base_api/bsd_locale_defaults.h
496497
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
498+
__locale_dir/locale_base_api/freebsd.h
497499
__locale_dir/locale_base_api/fuchsia.h
498500
__locale_dir/locale_base_api/ibm.h
499501
__locale_dir/locale_base_api/locale_guard.h

libcxx/include/__locale

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class _LIBCPP_TEMPLATE_VIS collate_byname;
247247

248248
template <>
249249
class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {
250-
locale_t __l_;
250+
__libcpp_locale_t __l_;
251251

252252
public:
253253
typedef char char_type;
@@ -266,7 +266,7 @@ protected:
266266
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
267267
template <>
268268
class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {
269-
locale_t __l_;
269+
__libcpp_locale_t __l_;
270270

271271
public:
272272
typedef wchar_t char_type;
@@ -616,7 +616,7 @@ class _LIBCPP_TEMPLATE_VIS ctype_byname;
616616

617617
template <>
618618
class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {
619-
locale_t __l_;
619+
__libcpp_locale_t __l_;
620620

621621
public:
622622
explicit ctype_byname(const char*, size_t = 0);
@@ -633,7 +633,7 @@ protected:
633633
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
634634
template <>
635635
class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {
636-
locale_t __l_;
636+
__libcpp_locale_t __l_;
637637

638638
public:
639639
explicit ctype_byname(const char*, size_t = 0);
@@ -824,7 +824,7 @@ protected:
824824
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
825825
template <>
826826
class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {
827-
locale_t __l_;
827+
__libcpp_locale_t __l_;
828828

829829
public:
830830
typedef wchar_t intern_type;

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
1010
#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
1111

12+
#include <__config>
13+
1214
#if defined(_LIBCPP_MSVCRT_LIKE)
1315
# include <__locale_dir/locale_base_api/win32.h>
1416
#elif defined(_AIX) || defined(__MVS__)
1517
# include <__locale_dir/locale_base_api/ibm.h>
1618
#elif defined(__ANDROID__)
1719
# include <__locale_dir/locale_base_api/android.h>
18-
#elif defined(__sun__)
19-
# include <__locale_dir/locale_base_api/solaris.h>
2020
#elif defined(_NEWLIB_VERSION)
2121
# include <__locale_dir/locale_base_api/newlib.h>
2222
#elif defined(__OpenBSD__)
@@ -25,8 +25,10 @@
2525
# include <__locale_dir/locale_base_api/fuchsia.h>
2626
#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
2727
# include <__locale_dir/locale_base_api/musl.h>
28-
#elif defined(__APPLE__) || defined(__FreeBSD__)
29-
# include <xlocale.h>
28+
#elif defined(__APPLE__)
29+
# include <__locale_dir/locale_base_api/apple.h>
30+
#elif defined(__FreeBSD__)
31+
# include <__locale_dir/locale_base_api/freebsd.h>
3032
#endif
3133

3234
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -36,8 +38,7 @@
3638
/*
3739
The platform-specific headers have to provide the following interface:
3840
39-
// TODO: rename this to __libcpp_locale_t
40-
using locale_t = implementation-defined;
41+
using __libcpp_locale_t = implementation-defined;
4142
4243
implementation-defined __libcpp_mb_cur_max_l(locale_t);
4344
wint_t __libcpp_btowc_l(int, locale_t);

libcxx/include/__locale_dir/locale_base_api/android.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ extern "C" {
3434
# include <__support/xlocale/__strtonum_fallback.h>
3535
# elif __ANDROID_API__ < 26
3636

37-
inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) {
37+
inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, __libcpp_locale_t) {
3838
return ::strtof(__nptr, __endptr);
3939
}
4040

41-
inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t) {
41+
inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, __libcpp_locale_t) {
4242
return ::strtod(__nptr, __endptr);
4343
}
4444

@@ -47,4 +47,6 @@ inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr
4747
# endif // __NDK_MAJOR__ <= 16
4848
#endif // __has_include(<android/ndk-version.h>)
4949

50+
using __libcpp_locale_t = ::locale_t;
51+
5052
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// -*- C++ -*-
2+
//===-----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_APPLE_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_APPLE_H
12+
13+
#include <xlocale.h>
14+
15+
using __libcpp_locale_t = locale_t;
16+
17+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_APPLE_H

libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,74 @@
2828

2929
_LIBCPP_BEGIN_NAMESPACE_STD
3030

31-
inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) {
31+
inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(__libcpp_locale_t __l) {
3232
__libcpp_locale_guard __current(__l);
3333
return MB_CUR_MAX;
3434
}
3535

3636
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
37-
inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) {
37+
inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, __libcpp_locale_t __l) {
3838
__libcpp_locale_guard __current(__l);
3939
return btowc(__c);
4040
}
4141

42-
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) {
42+
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, __libcpp_locale_t __l) {
4343
__libcpp_locale_guard __current(__l);
4444
return wctob(__c);
4545
}
4646

47-
inline _LIBCPP_HIDE_FROM_ABI size_t
48-
__libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) {
47+
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcsnrtombs_l(
48+
char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __libcpp_locale_t __l) {
4949
__libcpp_locale_guard __current(__l);
5050
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
5151
}
5252

53-
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) {
53+
inline _LIBCPP_HIDE_FROM_ABI size_t
54+
__libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, __libcpp_locale_t __l) {
5455
__libcpp_locale_guard __current(__l);
5556
return wcrtomb(__s, __wc, __ps);
5657
}
5758

58-
inline _LIBCPP_HIDE_FROM_ABI size_t
59-
__libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) {
59+
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbsnrtowcs_l(
60+
wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __libcpp_locale_t __l) {
6061
__libcpp_locale_guard __current(__l);
6162
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
6263
}
6364

6465
inline _LIBCPP_HIDE_FROM_ABI size_t
65-
__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
66+
__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __libcpp_locale_t __l) {
6667
__libcpp_locale_guard __current(__l);
6768
return mbrtowc(__pwc, __s, __n, __ps);
6869
}
6970

70-
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) {
71+
inline _LIBCPP_HIDE_FROM_ABI int
72+
__libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, __libcpp_locale_t __l) {
7173
__libcpp_locale_guard __current(__l);
7274
return mbtowc(__pwc, __pmb, __max);
7375
}
7476

75-
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
77+
inline _LIBCPP_HIDE_FROM_ABI size_t
78+
__libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, __libcpp_locale_t __l) {
7679
__libcpp_locale_guard __current(__l);
7780
return mbrlen(__s, __n, __ps);
7881
}
7982
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
8083

81-
inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t __l) {
84+
inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(__libcpp_locale_t __l) {
8285
__libcpp_locale_guard __current(__l);
8386
return localeconv();
8487
}
8588

8689
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
8790
inline _LIBCPP_HIDE_FROM_ABI size_t
88-
__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) {
91+
__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __libcpp_locale_t __l) {
8992
__libcpp_locale_guard __current(__l);
9093
return mbsrtowcs(__dest, __src, __len, __ps);
9194
}
9295
#endif
9396

9497
inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
95-
char* __s, size_t __n, locale_t __l, const char* __format, ...) {
98+
char* __s, size_t __n, __libcpp_locale_t __l, const char* __format, ...) {
9699
va_list __va;
97100
va_start(__va, __format);
98101
__libcpp_locale_guard __current(__l);
@@ -102,7 +105,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
102105
}
103106

104107
inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
105-
char** __s, locale_t __l, const char* __format, ...) {
108+
char** __s, __libcpp_locale_t __l, const char* __format, ...) {
106109
va_list __va;
107110
va_start(__va, __format);
108111
__libcpp_locale_guard __current(__l);
@@ -112,7 +115,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
112115
}
113116

114117
inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
115-
const char* __s, locale_t __l, const char* __format, ...) {
118+
const char* __s, __libcpp_locale_t __l, const char* __format, ...) {
116119
va_list __va;
117120
va_start(__va, __format);
118121
__libcpp_locale_guard __current(__l);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// -*- C++ -*-
2+
//===-----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_FREEBSD_H
11+
#define _LIBCPP___LOCALE_LOCALE_BASE_API_FREEBSD_H
12+
13+
#include <xlocale.h>
14+
15+
using __libcpp_locale_t = locale_t;
16+
17+
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FREEBSD_H

libcxx/include/__locale_dir/locale_base_api/fuchsia.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
#include <cstdlib>
1616
#include <cwchar>
1717

18+
using __libcpp_locale_t = locale_t;
19+
1820
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H

libcxx/include/__locale_dir/locale_base_api/ibm.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
# include <__support/xlocale/__posix_l_fallback.h>
2727
#endif // defined(__MVS__)
2828

29+
using __libcpp_locale_t = locale_t;
30+
2931
namespace {
3032

3133
struct __setAndRestore {
32-
explicit __setAndRestore(locale_t locale) {
33-
if (locale == (locale_t)0) {
34-
__cloc = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0);
34+
explicit __setAndRestore(__libcpp_locale_t locale) {
35+
if (locale == (__libcpp_locale_t)0) {
36+
__cloc = newlocale(LC_ALL_MASK, "C", /* base */ (__libcpp_locale_t)0);
3537
__stored = uselocale(__cloc);
3638
} else {
3739
__stored = uselocale(locale);
@@ -45,36 +47,37 @@ struct __setAndRestore {
4547
}
4648

4749
private:
48-
locale_t __stored = (locale_t)0;
49-
locale_t __cloc = (locale_t)0;
50+
__libcpp_locale_t __stored = (__libcpp_locale_t)0;
51+
__libcpp_locale_t __cloc = (__libcpp_locale_t)0;
5052
};
5153

5254
} // namespace
5355

5456
// The following are not POSIX routines. These are quick-and-dirty hacks
5557
// to make things pretend to work
56-
inline _LIBCPP_HIDE_FROM_ABI long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
58+
inline _LIBCPP_HIDE_FROM_ABI long long
59+
strtoll_l(const char* __nptr, char** __endptr, int __base, __libcpp_locale_t locale) {
5760
__setAndRestore __newloc(locale);
5861
return ::strtoll(__nptr, __endptr, __base);
5962
}
6063

61-
inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t locale) {
64+
inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, __libcpp_locale_t locale) {
6265
__setAndRestore __newloc(locale);
6366
return ::strtod(__nptr, __endptr);
6467
}
6568

66-
inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t locale) {
69+
inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, __libcpp_locale_t locale) {
6770
__setAndRestore __newloc(locale);
6871
return ::strtof(__nptr, __endptr);
6972
}
7073

71-
inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, locale_t locale) {
74+
inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, __libcpp_locale_t locale) {
7275
__setAndRestore __newloc(locale);
7376
return ::strtold(__nptr, __endptr);
7477
}
7578

7679
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
77-
strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
80+
strtoull_l(const char* __nptr, char** __endptr, int __base, __libcpp_locale_t locale) {
7881
__setAndRestore __newloc(locale);
7982
return ::strtoull(__nptr, __endptr, __base);
8083
}

libcxx/include/__locale_dir/locale_base_api/locale_guard.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H
1111

1212
#include <__config>
13-
#include <__locale> // for locale_t
13+
#include <__locale> // for __libcpp_locale_t
1414
#include <clocale>
1515

1616
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -21,21 +21,21 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
2323
struct __libcpp_locale_guard {
24-
_LIBCPP_HIDE_FROM_ABI __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
24+
_LIBCPP_HIDE_FROM_ABI __libcpp_locale_guard(__libcpp_locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
2525

2626
_LIBCPP_HIDE_FROM_ABI ~__libcpp_locale_guard() {
2727
if (__old_loc_)
2828
uselocale(__old_loc_);
2929
}
3030

31-
locale_t __old_loc_;
31+
__libcpp_locale_t __old_loc_;
3232

3333
__libcpp_locale_guard(__libcpp_locale_guard const&) = delete;
3434
__libcpp_locale_guard& operator=(__libcpp_locale_guard const&) = delete;
3535
};
3636
#elif defined(_LIBCPP_MSVCRT_LIKE)
3737
struct __libcpp_locale_guard {
38-
__libcpp_locale_guard(locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
38+
__libcpp_locale_guard(__libcpp_locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
3939
// Setting the locale can be expensive even when the locale given is
4040
// already the current locale, so do an explicit check to see if the
4141
// current locale is already the one we want.

0 commit comments

Comments
 (0)