1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
diff --git a/src/locale.cpp b/src/locale.cpp
index 220caee..fc95dad 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -43,7 +43,7 @@
# include <langinfo.h>
#endif
-#include "include/atomic_support.h"
+#include "atomic"
#include "include/sso_allocator.h"
// On Linux, wint_t and wchar_t have different signed-ness, and this causes
@@ -141,14 +141,7 @@ class _LIBCPP_HIDDEN locale::__imp
: public facet
{
enum {N = 30};
-#if defined(_LIBCPP_COMPILER_MSVC)
-// FIXME: MSVC doesn't support aligned parameters by value.
-// I can't get the __sso_allocator to work here
-// for MSVC I think for this reason.
- vector<facet*> facets_;
-#else
vector<facet*, __sso_allocator<facet*, N> > facets_;
-#endif
string name_;
public:
explicit __imp(size_t refs = 0);
@@ -701,8 +694,6 @@ locale::facet::__on_zero_shared() noexcept
// locale::id
-int32_t locale::id::__next_id = 0;
-
namespace
{
@@ -722,17 +713,22 @@ public:
}
+int32_t locale::id::__next_id;
+
long
locale::id::__get()
{
- call_once(__flag_, __fake_bind(&locale::id::__init, this));
- return __id_ - 1;
-}
-
-void
-locale::id::__init()
-{
- __id_ = __libcpp_atomic_add(&__next_id, 1);
+ int32_t result = __id_.load(std::memory_order_acquire);
+ if (result == 0) {
+ static std::mutex m;
+ std::lock_guard<std::mutex> guard(m);
+ result = __id_.load(std::memory_order_acquire);
+ if (result == 0) {
+ result = ++__next_id;
+ __id_.store(result, std::memory_order_release);
+ }
+ }
+ return result - 1;
}
// template <> class collate_byname<char>
@@ -1106,6 +1102,11 @@ extern "C" const int ** __ctype_tolower_loc();
extern "C" const int ** __ctype_toupper_loc();
#endif
+#if defined(__ANDROID__)
+// See src/support/android/android_locale.cpp
+extern "C" const unsigned short* const _ctype_android;
+#endif
+
#ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
const ctype<char>::mask*
ctype<char>::classic_table() noexcept
@@ -1205,6 +1206,8 @@ ctype<char>::classic_table() noexcept
#elif defined(_NEWLIB_VERSION)
// Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
return _ctype_ + 1;
+#elif defined(__ANDROID__)
+ return _ctype_android;
#elif defined(_AIX)
return (const unsigned int *)__lc_ctype_ptr->obj->mask;
#elif defined(__MVS__)
@@ -4218,14 +4221,25 @@ __codecvt_utf16<char32_t, true>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
+#if defined(_LIBCPP_SHORT_WCHAR)
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+#else
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
+#endif
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
+#if defined(_LIBCPP_SHORT_WCHAR)
+ result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+ _Maxcode_, _Mode_);
+#else
result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
+#endif
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
@@ -4294,7 +4308,7 @@ __codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
-#if defined(_LIBCPP_SHORT_WCHAR)
+#ifdef _WIN32
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
@@ -4321,7 +4335,7 @@ __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
-#if defined(_LIBCPP_SHORT_WCHAR)
+#ifdef _WIN32
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
@@ -4478,9 +4492,15 @@ __codecvt_utf8_utf16<char32_t>::do_in(state_type&,
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
+#if defined(_LIBCPP_SHORT_WCHAR)
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+#else
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
+#endif
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
@@ -5950,7 +5970,7 @@ __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
+ __curr_symbol_.insert((size_t)0, 1, space_char);
}
return;
default:
@@ -5973,7 +5993,7 @@ __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
+ __curr_symbol_.insert((size_t)0, 1, space_char);
}
return;
case 2: // Space between sign and currency or value.
@@ -6003,7 +6023,7 @@ __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
// We insert the space into the symbol instead of
// setting pat.field[1]=space so that when
// showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
+ __curr_symbol_.insert((size_t)0, 1, space_char);
}
pat.field[1] = none;
pat.field[2] = symbol;
@@ -6046,7 +6066,7 @@ __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
+ __curr_symbol_.insert((size_t)0, 1, space_char);
}
return;
default:
@@ -6069,7 +6089,7 @@ __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
// We insert the space into the symbol instead of
// setting pat.field[1]=space so that when
// showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
+ __curr_symbol_.insert((size_t)0, 1, space_char);
}
return;
case 2: // Space between sign and currency or value.
@@ -6110,7 +6130,7 @@ __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
+ __curr_symbol_.insert((size_t)0, 1, space_char);
}
return;
default:
|