]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/src/c++98/locale_init.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++98 / locale_init.cc
1 // Copyright (C) 1997-2021 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
17
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 // <http://www.gnu.org/licenses/>.
22
23 #define _GLIBCXX_USE_CXX11_ABI 1
24 #include <clocale>
25 #include <cstring>
26 #include <cstdlib> // For free.
27 #include <cctype>
28 #include <cwctype> // For towupper, etc.
29 #include <locale>
30 #include <ext/concurrence.h>
31
32 #if _GLIBCXX_USE_DUAL_ABI
33 // This file is compiled with the new std::string ABI so std::numpunct<char>
34 // refers to std::__cxx11::numpunct<char>. These declarations let us refer
35 // to the other facets instantiated with the old ABI.
36 # define _GLIBCXX_LOC_ID(mangled) extern std::locale::id mangled
37 _GLIBCXX_LOC_ID(_ZNSt8numpunctIcE2idE);
38 _GLIBCXX_LOC_ID(_ZNSt7collateIcE2idE);
39 _GLIBCXX_LOC_ID(_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
40 _GLIBCXX_LOC_ID(_ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
41 _GLIBCXX_LOC_ID(_ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
42 _GLIBCXX_LOC_ID(_ZNSt10moneypunctIcLb0EE2idE);
43 _GLIBCXX_LOC_ID(_ZNSt10moneypunctIcLb1EE2idE);
44 _GLIBCXX_LOC_ID(_ZNSt8messagesIcE2idE);
45 # ifdef _GLIBCXX_USE_WCHAR_T
46 _GLIBCXX_LOC_ID(_ZNSt8numpunctIwE2idE);
47 _GLIBCXX_LOC_ID(_ZNSt7collateIwE2idE);
48 _GLIBCXX_LOC_ID(_ZNSt8time_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
49 _GLIBCXX_LOC_ID(_ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
50 _GLIBCXX_LOC_ID(_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
51 _GLIBCXX_LOC_ID(_ZNSt10moneypunctIwLb0EE2idE);
52 _GLIBCXX_LOC_ID(_ZNSt10moneypunctIwLb1EE2idE);
53 _GLIBCXX_LOC_ID(_ZNSt8messagesIwE2idE);
54 # endif
55 #endif
56
57
58 namespace
59 {
60 const int num_facets = (
61 _GLIBCXX_NUM_FACETS + _GLIBCXX_NUM_CXX11_FACETS
62 #ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
63 + _GLIBCXX_NUM_LBDL_ALT128_FACETS
64 #endif
65 )
66 #ifdef _GLIBCXX_USE_WCHAR_T
67 * 2
68 #endif
69 + _GLIBCXX_NUM_UNICODE_FACETS;
70
71 __gnu_cxx::__mutex&
72 get_locale_mutex()
73 {
74 static __gnu_cxx::__mutex locale_mutex;
75 return locale_mutex;
76 }
77
78 using namespace std;
79
80 typedef char fake_locale_Impl[sizeof(locale::_Impl)]
81 __attribute__ ((aligned(__alignof__(locale::_Impl))));
82 fake_locale_Impl c_locale_impl;
83
84 typedef char fake_locale[sizeof(locale)]
85 __attribute__ ((aligned(__alignof__(locale))));
86 fake_locale c_locale;
87
88 typedef char fake_name_vec[sizeof(char*)]
89 __attribute__ ((aligned(__alignof__(char*))));
90 fake_name_vec name_vec[6 + _GLIBCXX_NUM_CATEGORIES];
91
92 typedef char fake_names[sizeof(char[2])]
93 __attribute__ ((aligned(__alignof__(char[2]))));
94 fake_names name_c[6 + _GLIBCXX_NUM_CATEGORIES];
95
96 typedef char fake_facet_vec[sizeof(locale::facet*)]
97 __attribute__ ((aligned(__alignof__(locale::facet*))));
98 fake_facet_vec facet_vec[num_facets];
99
100 typedef char fake_cache_vec[sizeof(locale::facet*)]
101 __attribute__ ((aligned(__alignof__(locale::facet*))));
102 fake_cache_vec cache_vec[num_facets];
103
104 typedef char fake_ctype_c[sizeof(std::ctype<char>)]
105 __attribute__ ((aligned(__alignof__(std::ctype<char>))));
106 fake_ctype_c ctype_c;
107
108 typedef char fake_collate_c[sizeof(std::collate<char>)]
109 __attribute__ ((aligned(__alignof__(std::collate<char>))));
110 fake_collate_c collate_c;
111
112 typedef char fake_numpunct_c[sizeof(numpunct<char>)]
113 __attribute__ ((aligned(__alignof__(numpunct<char>))));
114 fake_numpunct_c numpunct_c;
115
116 typedef char fake_num_get_c[sizeof(num_get<char>)]
117 __attribute__ ((aligned(__alignof__(num_get<char>))));
118 fake_num_get_c num_get_c;
119
120 typedef char fake_num_put_c[sizeof(num_put<char>)]
121 __attribute__ ((aligned(__alignof__(num_put<char>))));
122 fake_num_put_c num_put_c;
123
124 typedef char fake_codecvt_c[sizeof(codecvt<char, char, mbstate_t>)]
125 __attribute__ ((aligned(__alignof__(codecvt<char, char, mbstate_t>))));
126 fake_codecvt_c codecvt_c;
127
128 typedef char fake_moneypunct_c[sizeof(moneypunct<char, true>)]
129 __attribute__ ((aligned(__alignof__(moneypunct<char, true>))));
130 fake_moneypunct_c moneypunct_ct;
131 fake_moneypunct_c moneypunct_cf;
132
133 typedef char fake_money_get_c[sizeof(money_get<char>)]
134 __attribute__ ((aligned(__alignof__(money_get<char>))));
135 fake_money_get_c money_get_c;
136
137 typedef char fake_money_put_c[sizeof(money_put<char>)]
138 __attribute__ ((aligned(__alignof__(money_put<char>))));
139 fake_money_put_c money_put_c;
140
141 typedef char fake_timepunct_c[sizeof(__timepunct<char>)]
142 __attribute__ ((aligned(__alignof__(__timepunct<char>))));
143 fake_timepunct_c timepunct_c;
144
145 typedef char fake_time_get_c[sizeof(time_get<char>)]
146 __attribute__ ((aligned(__alignof__(time_get<char>))));
147 fake_time_get_c time_get_c;
148
149 typedef char fake_time_put_c[sizeof(time_put<char>)]
150 __attribute__ ((aligned(__alignof__(time_put<char>))));
151 fake_time_put_c time_put_c;
152
153 typedef char fake_messages_c[sizeof(messages<char>)]
154 __attribute__ ((aligned(__alignof__(messages<char>))));
155 fake_messages_c messages_c;
156
157 #ifdef _GLIBCXX_USE_WCHAR_T
158 typedef char fake_wtype_w[sizeof(std::ctype<wchar_t>)]
159 __attribute__ ((aligned(__alignof__(std::ctype<wchar_t>))));
160 fake_wtype_w ctype_w;
161
162 typedef char fake_wollate_w[sizeof(std::collate<wchar_t>)]
163 __attribute__ ((aligned(__alignof__(std::collate<wchar_t>))));
164 fake_wollate_w collate_w;
165
166 typedef char fake_numpunct_w[sizeof(numpunct<wchar_t>)]
167 __attribute__ ((aligned(__alignof__(numpunct<wchar_t>))));
168 fake_numpunct_w numpunct_w;
169
170 typedef char fake_num_get_w[sizeof(num_get<wchar_t>)]
171 __attribute__ ((aligned(__alignof__(num_get<wchar_t>))));
172 fake_num_get_w num_get_w;
173
174 typedef char fake_num_put_w[sizeof(num_put<wchar_t>)]
175 __attribute__ ((aligned(__alignof__(num_put<wchar_t>))));
176 fake_num_put_w num_put_w;
177
178 typedef char fake_wodecvt_w[sizeof(codecvt<wchar_t, char, mbstate_t>)]
179 __attribute__ ((aligned(__alignof__(codecvt<wchar_t, char, mbstate_t>))));
180 fake_wodecvt_w codecvt_w;
181
182 typedef char fake_moneypunct_w[sizeof(moneypunct<wchar_t, true>)]
183 __attribute__ ((aligned(__alignof__(moneypunct<wchar_t, true>))));
184 fake_moneypunct_w moneypunct_wt;
185 fake_moneypunct_w moneypunct_wf;
186
187 typedef char fake_money_get_w[sizeof(money_get<wchar_t>)]
188 __attribute__ ((aligned(__alignof__(money_get<wchar_t>))));
189 fake_money_get_w money_get_w;
190
191 typedef char fake_money_put_w[sizeof(money_put<wchar_t>)]
192 __attribute__ ((aligned(__alignof__(money_put<wchar_t>))));
193 fake_money_put_w money_put_w;
194
195 typedef char fake_timepunct_w[sizeof(__timepunct<wchar_t>)]
196 __attribute__ ((aligned(__alignof__(__timepunct<wchar_t>))));
197 fake_timepunct_w timepunct_w;
198
199 typedef char fake_time_get_w[sizeof(time_get<wchar_t>)]
200 __attribute__ ((aligned(__alignof__(time_get<wchar_t>))));
201 fake_time_get_w time_get_w;
202
203 typedef char fake_time_put_w[sizeof(time_put<wchar_t>)]
204 __attribute__ ((aligned(__alignof__(time_put<wchar_t>))));
205 fake_time_put_w time_put_w;
206
207 typedef char fake_messages_w[sizeof(messages<wchar_t>)]
208 __attribute__ ((aligned(__alignof__(messages<wchar_t>))));
209 fake_messages_w messages_w;
210 #endif
211
212 typedef char fake_codecvt_c16[sizeof(codecvt<char16_t, char, mbstate_t>)]
213 __attribute__ ((aligned(__alignof__(codecvt<char16_t, char, mbstate_t>))));
214 fake_codecvt_c16 codecvt_c16;
215
216 typedef char fake_codecvt_c32[sizeof(codecvt<char32_t, char, mbstate_t>)]
217 __attribute__ ((aligned(__alignof__(codecvt<char32_t, char, mbstate_t>))));
218 fake_codecvt_c32 codecvt_c32;
219
220 #ifdef _GLIBCXX_USE_CHAR8_T
221 typedef char fake_codecvt_c16_c8[sizeof(codecvt<char16_t, char8_t, mbstate_t>)]
222 __attribute__ ((aligned(__alignof__(codecvt<char16_t, char8_t, mbstate_t>))));
223 fake_codecvt_c16_c8 codecvt_c16_c8;
224
225 typedef char fake_codecvt_c32_c8[sizeof(codecvt<char32_t, char8_t, mbstate_t>)]
226 __attribute__ ((aligned(__alignof__(codecvt<char32_t, char8_t, mbstate_t>))));
227 fake_codecvt_c32_c8 codecvt_c32_c8;
228 #endif
229
230 // Storage for "C" locale caches.
231 typedef char fake_num_cache_c[sizeof(std::__numpunct_cache<char>)]
232 __attribute__ ((aligned(__alignof__(std::__numpunct_cache<char>))));
233 fake_num_cache_c numpunct_cache_c;
234
235 typedef char fake_money_cache_c[sizeof(std::__moneypunct_cache<char, true>)]
236 __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<char, true>))));
237 fake_money_cache_c moneypunct_cache_ct;
238 fake_money_cache_c moneypunct_cache_cf;
239
240 typedef char fake_time_cache_c[sizeof(std::__timepunct_cache<char>)]
241 __attribute__ ((aligned(__alignof__(std::__timepunct_cache<char>))));
242 fake_time_cache_c timepunct_cache_c;
243
244 #ifdef _GLIBCXX_USE_WCHAR_T
245 typedef char fake_num_cache_w[sizeof(std::__numpunct_cache<wchar_t>)]
246 __attribute__ ((aligned(__alignof__(std::__numpunct_cache<wchar_t>))));
247 fake_num_cache_w numpunct_cache_w;
248
249 typedef char fake_money_cache_w[sizeof(std::__moneypunct_cache<wchar_t,true>)]
250 __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<wchar_t,true>))));
251 fake_money_cache_w moneypunct_cache_wt;
252 fake_money_cache_w moneypunct_cache_wf;
253
254 typedef char fake_time_cache_w[sizeof(std::__timepunct_cache<wchar_t>)]
255 __attribute__ ((aligned(__alignof__(std::__timepunct_cache<wchar_t>))));
256 fake_time_cache_w timepunct_cache_w;
257 #endif
258 } // anonymous namespace
259
260 namespace std _GLIBCXX_VISIBILITY(default)
261 {
262 _GLIBCXX_BEGIN_NAMESPACE_VERSION
263
264 locale::locale() throw() : _M_impl(0)
265 {
266 _S_initialize();
267
268 // Checked locking to optimize the common case where _S_global
269 // still points to _S_classic (locale::_S_initialize_once()):
270 // - If they are the same, just increment the reference count and
271 // we are done. This effectively constructs a C locale object
272 // identical to the static c_locale.
273 // - Otherwise, _S_global can and may be destroyed due to
274 // locale::global() call on another thread, in which case we
275 // fall back to lock protected access to both _S_global and
276 // its reference count.
277 _M_impl = _S_global;
278 if (_M_impl != _S_classic)
279 {
280 __gnu_cxx::__scoped_lock sentry(get_locale_mutex());
281 _S_global->_M_add_reference();
282 _M_impl = _S_global;
283 }
284 }
285
286 locale
287 locale::global(const locale& __other)
288 {
289 _S_initialize();
290 _Impl* __old;
291 {
292 __gnu_cxx::__scoped_lock sentry(get_locale_mutex());
293 __old = _S_global;
294 if (__other._M_impl != _S_classic)
295 __other._M_impl->_M_add_reference();
296 _S_global = __other._M_impl;
297 const string __other_name = __other.name();
298 if (__other_name != "*")
299 setlocale(LC_ALL, __other_name.c_str());
300 }
301
302 // Reference count sanity check: one reference removed for the
303 // subsition of __other locale, one added by return-by-value. Net
304 // difference: zero. When the returned locale object's destructor
305 // is called, then the reference count is decremented and possibly
306 // destroyed.
307 return locale(__old);
308 }
309
310 const locale&
311 locale::classic()
312 {
313 _S_initialize();
314 return *(const locale*)c_locale;
315 }
316
317 void
318 locale::_S_initialize_once() throw()
319 {
320 // 2 references.
321 // One reference for _S_classic, one for _S_global
322 _S_classic = new (&c_locale_impl) _Impl(2);
323 _S_global = _S_classic;
324 new (&c_locale) locale(_S_classic);
325 }
326
327 void
328 locale::_S_initialize()
329 {
330 #ifdef __GTHREADS
331 if (__gthread_active_p())
332 __gthread_once(&_S_once, _S_initialize_once);
333 #endif
334 if (!_S_classic)
335 _S_initialize_once();
336 }
337
338 // Definitions for static const data members of locale::_Impl
339 const locale::id* const
340 locale::_Impl::_S_id_ctype[] =
341 {
342 &std::ctype<char>::id,
343 &codecvt<char, char, mbstate_t>::id,
344 #ifdef _GLIBCXX_USE_WCHAR_T
345 &std::ctype<wchar_t>::id,
346 &codecvt<wchar_t, char, mbstate_t>::id,
347 #endif
348 #if _GLIBCXX_NUM_UNICODE_FACETS != 0
349 &codecvt<char16_t, char, mbstate_t>::id,
350 &codecvt<char32_t, char, mbstate_t>::id,
351 #ifdef _GLIBCXX_USE_CHAR8_T
352 &codecvt<char16_t, char8_t, mbstate_t>::id,
353 &codecvt<char32_t, char8_t, mbstate_t>::id,
354 #endif
355 #endif
356 0
357 };
358
359 const locale::id* const
360 locale::_Impl::_S_id_numeric[] =
361 {
362 &num_get<char>::id,
363 &num_put<char>::id,
364 &numpunct<char>::id,
365 #ifdef _GLIBCXX_USE_WCHAR_T
366 &num_get<wchar_t>::id,
367 &num_put<wchar_t>::id,
368 &numpunct<wchar_t>::id,
369 #endif
370 0
371 };
372
373 const locale::id* const
374 locale::_Impl::_S_id_collate[] =
375 {
376 &std::collate<char>::id,
377 #ifdef _GLIBCXX_USE_WCHAR_T
378 &std::collate<wchar_t>::id,
379 #endif
380 0
381 };
382
383 const locale::id* const
384 locale::_Impl::_S_id_time[] =
385 {
386 &__timepunct<char>::id,
387 &time_get<char>::id,
388 &time_put<char>::id,
389 #ifdef _GLIBCXX_USE_WCHAR_T
390 &__timepunct<wchar_t>::id,
391 &time_get<wchar_t>::id,
392 &time_put<wchar_t>::id,
393 #endif
394 0
395 };
396
397 const locale::id* const
398 locale::_Impl::_S_id_monetary[] =
399 {
400 &money_get<char>::id,
401 &money_put<char>::id,
402 &moneypunct<char, false>::id,
403 &moneypunct<char, true >::id,
404 #ifdef _GLIBCXX_USE_WCHAR_T
405 &money_get<wchar_t>::id,
406 &money_put<wchar_t>::id,
407 &moneypunct<wchar_t, false>::id,
408 &moneypunct<wchar_t, true >::id,
409 #endif
410 0
411 };
412
413 const locale::id* const
414 locale::_Impl::_S_id_messages[] =
415 {
416 &std::messages<char>::id,
417 #ifdef _GLIBCXX_USE_WCHAR_T
418 &std::messages<wchar_t>::id,
419 #endif
420 0
421 };
422
423 const locale::id* const* const
424 locale::_Impl::_S_facet_categories[] =
425 {
426 // Order must match the decl order in class locale.
427 locale::_Impl::_S_id_ctype,
428 locale::_Impl::_S_id_numeric,
429 locale::_Impl::_S_id_collate,
430 locale::_Impl::_S_id_time,
431 locale::_Impl::_S_id_monetary,
432 locale::_Impl::_S_id_messages,
433 0
434 };
435
436 #if _GLIBCXX_USE_DUAL_ABI
437 // Facets that are instantiated for both the COW and SSO std::string ABIs.
438 // The COW ABI version must come first, followed by its SSO twin.
439 const locale::id* const locale::_S_twinned_facets[] = {
440 &::_ZNSt8numpunctIcE2idE,
441 &numpunct<char>::id,
442 &::_ZNSt7collateIcE2idE,
443 &std::collate<char>::id,
444 &::_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE,
445 &time_get<char>::id,
446 &::_ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE,
447 &money_get<char>::id,
448 &::_ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE,
449 &money_put<char>::id,
450 &::_ZNSt10moneypunctIcLb0EE2idE,
451 &moneypunct<char, false>::id,
452 &::_ZNSt10moneypunctIcLb1EE2idE,
453 &moneypunct<char, true >::id,
454 &::_ZNSt8messagesIcE2idE,
455 &std::messages<char>::id,
456 # ifdef _GLIBCXX_USE_WCHAR_T
457 &::_ZNSt8numpunctIwE2idE,
458 &numpunct<wchar_t>::id,
459 &::_ZNSt7collateIwE2idE,
460 &std::collate<wchar_t>::id,
461 &::_ZNSt8time_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE,
462 &time_get<wchar_t>::id,
463 &::_ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE,
464 &money_get<wchar_t>::id,
465 &::_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE,
466 &money_put<wchar_t>::id,
467 &::_ZNSt10moneypunctIwLb0EE2idE,
468 &moneypunct<wchar_t, false>::id,
469 &::_ZNSt10moneypunctIwLb1EE2idE,
470 &moneypunct<wchar_t, true >::id,
471 &::_ZNSt8messagesIwE2idE,
472 &std::messages<wchar_t>::id,
473 # endif
474 0, 0
475 };
476 #endif
477
478 // Construct "C" _Impl.
479 locale::_Impl::
480 _Impl(size_t __refs) throw()
481 : _M_refcount(__refs), _M_facets(0), _M_facets_size(num_facets),
482 _M_caches(0), _M_names(0)
483 {
484 _M_facets = new (&facet_vec) const facet*[_M_facets_size]();
485 _M_caches = new (&cache_vec) const facet*[_M_facets_size]();
486
487 // Name the categories.
488 _M_names = new (&name_vec) char*[_S_categories_size]();
489 _M_names[0] = new (&name_c[0]) char[2];
490 std::memcpy(_M_names[0], locale::facet::_S_get_c_name(), 2);
491
492 // This is needed as presently the C++ version of "C" locales
493 // != data in the underlying locale model for __timepunct,
494 // numpunct, and moneypunct. Also, the "C" locales must be
495 // constructed in a way such that they are pre-allocated.
496 // NB: Set locale::facets(ref) count to one so that each individual
497 // facet is not destroyed when the locale (and thus locale::_Impl) is
498 // destroyed.
499 _M_init_facet(new (&ctype_c) std::ctype<char>(0, false, 1));
500 _M_init_facet(new (&codecvt_c) codecvt<char, char, mbstate_t>(1));
501
502 typedef __numpunct_cache<char> num_cache_c;
503 num_cache_c* __npc = new (&numpunct_cache_c) num_cache_c(2);
504 _M_init_facet(new (&numpunct_c) numpunct<char>(__npc, 1));
505
506 _M_init_facet(new (&num_get_c) num_get<char>(1));
507 _M_init_facet(new (&num_put_c) num_put<char>(1));
508 _M_init_facet(new (&collate_c) std::collate<char>(1));
509
510 typedef __moneypunct_cache<char, false> money_cache_cf;
511 typedef __moneypunct_cache<char, true> money_cache_ct;
512 money_cache_cf* __mpcf = new (&moneypunct_cache_cf) money_cache_cf(2);
513 _M_init_facet(new (&moneypunct_cf) moneypunct<char, false>(__mpcf, 1));
514 money_cache_ct* __mpct = new (&moneypunct_cache_ct) money_cache_ct(2);
515 _M_init_facet(new (&moneypunct_ct) moneypunct<char, true>(__mpct, 1));
516
517 _M_init_facet(new (&money_get_c) money_get<char>(1));
518 _M_init_facet(new (&money_put_c) money_put<char>(1));
519
520 typedef __timepunct_cache<char> time_cache_c;
521 time_cache_c* __tpc = new (&timepunct_cache_c) time_cache_c(2);
522 _M_init_facet(new (&timepunct_c) __timepunct<char>(__tpc, 1));
523
524 _M_init_facet(new (&time_get_c) time_get<char>(1));
525 _M_init_facet(new (&time_put_c) time_put<char>(1));
526 _M_init_facet(new (&messages_c) std::messages<char>(1));
527
528 #ifdef _GLIBCXX_USE_WCHAR_T
529 _M_init_facet(new (&ctype_w) std::ctype<wchar_t>(1));
530 _M_init_facet(new (&codecvt_w) codecvt<wchar_t, char, mbstate_t>(1));
531
532 typedef __numpunct_cache<wchar_t> num_cache_w;
533 num_cache_w* __npw = new (&numpunct_cache_w) num_cache_w(2);
534 _M_init_facet(new (&numpunct_w) numpunct<wchar_t>(__npw, 1));
535
536 _M_init_facet(new (&num_get_w) num_get<wchar_t>(1));
537 _M_init_facet(new (&num_put_w) num_put<wchar_t>(1));
538 _M_init_facet(new (&collate_w) std::collate<wchar_t>(1));
539
540 typedef __moneypunct_cache<wchar_t, false> money_cache_wf;
541 typedef __moneypunct_cache<wchar_t, true> money_cache_wt;
542 money_cache_wf* __mpwf = new (&moneypunct_cache_wf) money_cache_wf(2);
543 _M_init_facet(new (&moneypunct_wf) moneypunct<wchar_t, false>(__mpwf, 1));
544 money_cache_wt* __mpwt = new (&moneypunct_cache_wt) money_cache_wt(2);
545 _M_init_facet(new (&moneypunct_wt) moneypunct<wchar_t, true>(__mpwt, 1));
546
547 _M_init_facet(new (&money_get_w) money_get<wchar_t>(1));
548 _M_init_facet(new (&money_put_w) money_put<wchar_t>(1));
549
550 typedef __timepunct_cache<wchar_t> time_cache_w;
551 time_cache_w* __tpw = new (&timepunct_cache_w) time_cache_w(2);
552 _M_init_facet(new (&timepunct_w) __timepunct<wchar_t>(__tpw, 1));
553
554 _M_init_facet(new (&time_get_w) time_get<wchar_t>(1));
555 _M_init_facet(new (&time_put_w) time_put<wchar_t>(1));
556 _M_init_facet(new (&messages_w) std::messages<wchar_t>(1));
557 #endif
558
559 #if _GLIBCXX_NUM_UNICODE_FACETS != 0
560 _M_init_facet(new (&codecvt_c16) codecvt<char16_t, char, mbstate_t>(1));
561 _M_init_facet(new (&codecvt_c32) codecvt<char32_t, char, mbstate_t>(1));
562
563 #ifdef _GLIBCXX_USE_CHAR8_T
564 _M_init_facet(new (&codecvt_c16_c8) codecvt<char16_t, char8_t, mbstate_t>(1));
565 _M_init_facet(new (&codecvt_c32_c8) codecvt<char32_t, char8_t, mbstate_t>(1));
566 #endif
567
568 #endif
569
570 #ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
571 _M_init_extra_ldbl128(true);
572 #endif
573
574 #if _GLIBCXX_USE_DUAL_ABI
575 facet* extra[] = { __npc, __mpcf, __mpct
576 # ifdef _GLIBCXX_USE_WCHAR_T
577 , __npw, __mpwf, __mpwt
578 # endif
579 };
580
581 // This call must be after creating all facets, as it sets caches.
582 _M_init_extra(extra);
583 #endif
584
585 // This locale is safe to pre-cache, after all the facets have
586 // been created and installed.
587 _M_caches[numpunct<char>::id._M_id()] = __npc;
588 _M_caches[moneypunct<char, false>::id._M_id()] = __mpcf;
589 _M_caches[moneypunct<char, true>::id._M_id()] = __mpct;
590 _M_caches[__timepunct<char>::id._M_id()] = __tpc;
591 #ifdef _GLIBCXX_USE_WCHAR_T
592 _M_caches[numpunct<wchar_t>::id._M_id()] = __npw;
593 _M_caches[moneypunct<wchar_t, false>::id._M_id()] = __mpwf;
594 _M_caches[moneypunct<wchar_t, true>::id._M_id()] = __mpwt;
595 _M_caches[__timepunct<wchar_t>::id._M_id()] = __tpw;
596 #endif
597 }
598
599 _GLIBCXX_END_NAMESPACE_VERSION
600 } // namespace