1*e4b17023SJohn Marino // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2*e4b17023SJohn Marino // 2009, 2010 3*e4b17023SJohn Marino // Free Software Foundation, Inc. 4*e4b17023SJohn Marino // 5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 7*e4b17023SJohn Marino // terms of the GNU General Public License as published by the 8*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 9*e4b17023SJohn Marino // any later version. 10*e4b17023SJohn Marino 11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 12*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*e4b17023SJohn Marino // GNU General Public License for more details. 15*e4b17023SJohn Marino 16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 19*e4b17023SJohn Marino 20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 24*e4b17023SJohn Marino 25*e4b17023SJohn Marino #include <clocale> 26*e4b17023SJohn Marino #include <cstring> 27*e4b17023SJohn Marino #include <cstdlib> // For getenv, free. 28*e4b17023SJohn Marino #include <cctype> 29*e4b17023SJohn Marino #include <cwctype> // For towupper, etc. 30*e4b17023SJohn Marino #include <locale> 31*e4b17023SJohn Marino #include <ext/concurrence.h> 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino namespace 34*e4b17023SJohn Marino { 35*e4b17023SJohn Marino __gnu_cxx::__mutex& get_locale_mutex()36*e4b17023SJohn Marino get_locale_mutex() 37*e4b17023SJohn Marino { 38*e4b17023SJohn Marino static __gnu_cxx::__mutex locale_mutex; 39*e4b17023SJohn Marino return locale_mutex; 40*e4b17023SJohn Marino } 41*e4b17023SJohn Marino 42*e4b17023SJohn Marino using namespace std; 43*e4b17023SJohn Marino 44*e4b17023SJohn Marino typedef char fake_locale_Impl[sizeof(locale::_Impl)] 45*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(locale::_Impl)))); 46*e4b17023SJohn Marino fake_locale_Impl c_locale_impl; 47*e4b17023SJohn Marino 48*e4b17023SJohn Marino typedef char fake_locale[sizeof(locale)] 49*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(locale)))); 50*e4b17023SJohn Marino fake_locale c_locale; 51*e4b17023SJohn Marino 52*e4b17023SJohn Marino typedef char fake_name_vec[sizeof(char*)] 53*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(char*)))); 54*e4b17023SJohn Marino fake_name_vec name_vec[6 + _GLIBCXX_NUM_CATEGORIES]; 55*e4b17023SJohn Marino 56*e4b17023SJohn Marino typedef char fake_names[sizeof(char[2])] 57*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(char[2])))); 58*e4b17023SJohn Marino fake_names name_c[6 + _GLIBCXX_NUM_CATEGORIES]; 59*e4b17023SJohn Marino 60*e4b17023SJohn Marino typedef char fake_facet_vec[sizeof(locale::facet*)] 61*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(locale::facet*)))); 62*e4b17023SJohn Marino fake_facet_vec facet_vec[_GLIBCXX_NUM_FACETS]; 63*e4b17023SJohn Marino 64*e4b17023SJohn Marino typedef char fake_cache_vec[sizeof(locale::facet*)] 65*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(locale::facet*)))); 66*e4b17023SJohn Marino fake_cache_vec cache_vec[_GLIBCXX_NUM_FACETS]; 67*e4b17023SJohn Marino 68*e4b17023SJohn Marino typedef char fake_ctype_c[sizeof(std::ctype<char>)] 69*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::ctype<char>)))); 70*e4b17023SJohn Marino fake_ctype_c ctype_c; 71*e4b17023SJohn Marino 72*e4b17023SJohn Marino typedef char fake_collate_c[sizeof(std::collate<char>)] 73*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::collate<char>)))); 74*e4b17023SJohn Marino fake_collate_c collate_c; 75*e4b17023SJohn Marino 76*e4b17023SJohn Marino typedef char fake_numpunct_c[sizeof(numpunct<char>)] 77*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(numpunct<char>)))); 78*e4b17023SJohn Marino fake_numpunct_c numpunct_c; 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino typedef char fake_num_get_c[sizeof(num_get<char>)] 81*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(num_get<char>)))); 82*e4b17023SJohn Marino fake_num_get_c num_get_c; 83*e4b17023SJohn Marino 84*e4b17023SJohn Marino typedef char fake_num_put_c[sizeof(num_put<char>)] 85*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(num_put<char>)))); 86*e4b17023SJohn Marino fake_num_put_c num_put_c; 87*e4b17023SJohn Marino 88*e4b17023SJohn Marino typedef char fake_codecvt_c[sizeof(codecvt<char, char, mbstate_t>)] 89*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(codecvt<char, char, mbstate_t>)))); 90*e4b17023SJohn Marino fake_codecvt_c codecvt_c; 91*e4b17023SJohn Marino 92*e4b17023SJohn Marino typedef char fake_moneypunct_c[sizeof(moneypunct<char, true>)] 93*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(moneypunct<char, true>)))); 94*e4b17023SJohn Marino fake_moneypunct_c moneypunct_ct; 95*e4b17023SJohn Marino fake_moneypunct_c moneypunct_cf; 96*e4b17023SJohn Marino 97*e4b17023SJohn Marino typedef char fake_money_get_c[sizeof(money_get<char>)] 98*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(money_get<char>)))); 99*e4b17023SJohn Marino fake_money_get_c money_get_c; 100*e4b17023SJohn Marino 101*e4b17023SJohn Marino typedef char fake_money_put_c[sizeof(money_put<char>)] 102*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(money_put<char>)))); 103*e4b17023SJohn Marino fake_money_put_c money_put_c; 104*e4b17023SJohn Marino 105*e4b17023SJohn Marino typedef char fake_timepunct_c[sizeof(__timepunct<char>)] 106*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(__timepunct<char>)))); 107*e4b17023SJohn Marino fake_timepunct_c timepunct_c; 108*e4b17023SJohn Marino 109*e4b17023SJohn Marino typedef char fake_time_get_c[sizeof(time_get<char>)] 110*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(time_get<char>)))); 111*e4b17023SJohn Marino fake_time_get_c time_get_c; 112*e4b17023SJohn Marino 113*e4b17023SJohn Marino typedef char fake_time_put_c[sizeof(time_put<char>)] 114*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(time_put<char>)))); 115*e4b17023SJohn Marino fake_time_put_c time_put_c; 116*e4b17023SJohn Marino 117*e4b17023SJohn Marino typedef char fake_messages_c[sizeof(messages<char>)] 118*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(messages<char>)))); 119*e4b17023SJohn Marino fake_messages_c messages_c; 120*e4b17023SJohn Marino 121*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 122*e4b17023SJohn Marino typedef char fake_wtype_w[sizeof(std::ctype<wchar_t>)] 123*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::ctype<wchar_t>)))); 124*e4b17023SJohn Marino fake_wtype_w ctype_w; 125*e4b17023SJohn Marino 126*e4b17023SJohn Marino typedef char fake_wollate_w[sizeof(std::collate<wchar_t>)] 127*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::collate<wchar_t>)))); 128*e4b17023SJohn Marino fake_wollate_w collate_w; 129*e4b17023SJohn Marino 130*e4b17023SJohn Marino typedef char fake_numpunct_w[sizeof(numpunct<wchar_t>)] 131*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(numpunct<wchar_t>)))); 132*e4b17023SJohn Marino fake_numpunct_w numpunct_w; 133*e4b17023SJohn Marino 134*e4b17023SJohn Marino typedef char fake_num_get_w[sizeof(num_get<wchar_t>)] 135*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(num_get<wchar_t>)))); 136*e4b17023SJohn Marino fake_num_get_w num_get_w; 137*e4b17023SJohn Marino 138*e4b17023SJohn Marino typedef char fake_num_put_w[sizeof(num_put<wchar_t>)] 139*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(num_put<wchar_t>)))); 140*e4b17023SJohn Marino fake_num_put_w num_put_w; 141*e4b17023SJohn Marino 142*e4b17023SJohn Marino typedef char fake_wodecvt_w[sizeof(codecvt<wchar_t, char, mbstate_t>)] 143*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(codecvt<wchar_t, char, mbstate_t>)))); 144*e4b17023SJohn Marino fake_wodecvt_w codecvt_w; 145*e4b17023SJohn Marino 146*e4b17023SJohn Marino typedef char fake_moneypunct_w[sizeof(moneypunct<wchar_t, true>)] 147*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(moneypunct<wchar_t, true>)))); 148*e4b17023SJohn Marino fake_moneypunct_w moneypunct_wt; 149*e4b17023SJohn Marino fake_moneypunct_w moneypunct_wf; 150*e4b17023SJohn Marino 151*e4b17023SJohn Marino typedef char fake_money_get_w[sizeof(money_get<wchar_t>)] 152*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(money_get<wchar_t>)))); 153*e4b17023SJohn Marino fake_money_get_w money_get_w; 154*e4b17023SJohn Marino 155*e4b17023SJohn Marino typedef char fake_money_put_w[sizeof(money_put<wchar_t>)] 156*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(money_put<wchar_t>)))); 157*e4b17023SJohn Marino fake_money_put_w money_put_w; 158*e4b17023SJohn Marino 159*e4b17023SJohn Marino typedef char fake_timepunct_w[sizeof(__timepunct<wchar_t>)] 160*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(__timepunct<wchar_t>)))); 161*e4b17023SJohn Marino fake_timepunct_w timepunct_w; 162*e4b17023SJohn Marino 163*e4b17023SJohn Marino typedef char fake_time_get_w[sizeof(time_get<wchar_t>)] 164*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(time_get<wchar_t>)))); 165*e4b17023SJohn Marino fake_time_get_w time_get_w; 166*e4b17023SJohn Marino 167*e4b17023SJohn Marino typedef char fake_time_put_w[sizeof(time_put<wchar_t>)] 168*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(time_put<wchar_t>)))); 169*e4b17023SJohn Marino fake_time_put_w time_put_w; 170*e4b17023SJohn Marino 171*e4b17023SJohn Marino typedef char fake_messages_w[sizeof(messages<wchar_t>)] 172*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(messages<wchar_t>)))); 173*e4b17023SJohn Marino fake_messages_w messages_w; 174*e4b17023SJohn Marino #endif 175*e4b17023SJohn Marino 176*e4b17023SJohn Marino // Storage for "C" locale caches. 177*e4b17023SJohn Marino typedef char fake_num_cache_c[sizeof(std::__numpunct_cache<char>)] 178*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::__numpunct_cache<char>)))); 179*e4b17023SJohn Marino fake_num_cache_c numpunct_cache_c; 180*e4b17023SJohn Marino 181*e4b17023SJohn Marino typedef char fake_money_cache_c[sizeof(std::__moneypunct_cache<char, true>)] 182*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<char, true>)))); 183*e4b17023SJohn Marino fake_money_cache_c moneypunct_cache_ct; 184*e4b17023SJohn Marino fake_money_cache_c moneypunct_cache_cf; 185*e4b17023SJohn Marino 186*e4b17023SJohn Marino typedef char fake_time_cache_c[sizeof(std::__timepunct_cache<char>)] 187*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::__timepunct_cache<char>)))); 188*e4b17023SJohn Marino fake_time_cache_c timepunct_cache_c; 189*e4b17023SJohn Marino 190*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 191*e4b17023SJohn Marino typedef char fake_num_cache_w[sizeof(std::__numpunct_cache<wchar_t>)] 192*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::__numpunct_cache<wchar_t>)))); 193*e4b17023SJohn Marino fake_num_cache_w numpunct_cache_w; 194*e4b17023SJohn Marino 195*e4b17023SJohn Marino typedef char fake_money_cache_w[sizeof(std::__moneypunct_cache<wchar_t,true>)] 196*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<wchar_t,true>)))); 197*e4b17023SJohn Marino fake_money_cache_w moneypunct_cache_wt; 198*e4b17023SJohn Marino fake_money_cache_w moneypunct_cache_wf; 199*e4b17023SJohn Marino 200*e4b17023SJohn Marino typedef char fake_time_cache_w[sizeof(std::__timepunct_cache<wchar_t>)] 201*e4b17023SJohn Marino __attribute__ ((aligned(__alignof__(std::__timepunct_cache<wchar_t>)))); 202*e4b17023SJohn Marino fake_time_cache_w timepunct_cache_w; 203*e4b17023SJohn Marino #endif 204*e4b17023SJohn Marino } // anonymous namespace 205*e4b17023SJohn Marino 206*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 207*e4b17023SJohn Marino { 208*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 209*e4b17023SJohn Marino locale()210*e4b17023SJohn Marino locale::locale() throw() : _M_impl(0) 211*e4b17023SJohn Marino { 212*e4b17023SJohn Marino _S_initialize(); 213*e4b17023SJohn Marino 214*e4b17023SJohn Marino // Checked locking to optimize the common case where _S_global 215*e4b17023SJohn Marino // still points to _S_classic (locale::_S_initialize_once()): 216*e4b17023SJohn Marino // - If they are the same, just increment the reference count and 217*e4b17023SJohn Marino // we are done. This effectively constructs a C locale object 218*e4b17023SJohn Marino // identical to the static c_locale. 219*e4b17023SJohn Marino // - Otherwise, _S_global can and may be destroyed due to 220*e4b17023SJohn Marino // locale::global() call on another thread, in which case we 221*e4b17023SJohn Marino // fall back to lock protected access to both _S_global and 222*e4b17023SJohn Marino // its reference count. 223*e4b17023SJohn Marino _M_impl = _S_global; 224*e4b17023SJohn Marino if (_M_impl == _S_classic) 225*e4b17023SJohn Marino _M_impl->_M_add_reference(); 226*e4b17023SJohn Marino else 227*e4b17023SJohn Marino { 228*e4b17023SJohn Marino __gnu_cxx::__scoped_lock sentry(get_locale_mutex()); 229*e4b17023SJohn Marino _S_global->_M_add_reference(); 230*e4b17023SJohn Marino _M_impl = _S_global; 231*e4b17023SJohn Marino } 232*e4b17023SJohn Marino } 233*e4b17023SJohn Marino 234*e4b17023SJohn Marino locale global(const locale & __other)235*e4b17023SJohn Marino locale::global(const locale& __other) 236*e4b17023SJohn Marino { 237*e4b17023SJohn Marino _S_initialize(); 238*e4b17023SJohn Marino _Impl* __old; 239*e4b17023SJohn Marino { 240*e4b17023SJohn Marino __gnu_cxx::__scoped_lock sentry(get_locale_mutex()); 241*e4b17023SJohn Marino __old = _S_global; 242*e4b17023SJohn Marino __other._M_impl->_M_add_reference(); 243*e4b17023SJohn Marino _S_global = __other._M_impl; 244*e4b17023SJohn Marino const string __other_name = __other.name(); 245*e4b17023SJohn Marino if (__other_name != "*") 246*e4b17023SJohn Marino setlocale(LC_ALL, __other_name.c_str()); 247*e4b17023SJohn Marino } 248*e4b17023SJohn Marino 249*e4b17023SJohn Marino // Reference count sanity check: one reference removed for the 250*e4b17023SJohn Marino // subsition of __other locale, one added by return-by-value. Net 251*e4b17023SJohn Marino // difference: zero. When the returned locale object's destrutor 252*e4b17023SJohn Marino // is called, then the reference count is decremented and possibly 253*e4b17023SJohn Marino // destroyed. 254*e4b17023SJohn Marino return locale(__old); 255*e4b17023SJohn Marino } 256*e4b17023SJohn Marino 257*e4b17023SJohn Marino const locale& classic()258*e4b17023SJohn Marino locale::classic() 259*e4b17023SJohn Marino { 260*e4b17023SJohn Marino _S_initialize(); 261*e4b17023SJohn Marino return *(new (&c_locale) locale(_S_classic)); 262*e4b17023SJohn Marino } 263*e4b17023SJohn Marino 264*e4b17023SJohn Marino void _S_initialize_once()265*e4b17023SJohn Marino locale::_S_initialize_once() throw() 266*e4b17023SJohn Marino { 267*e4b17023SJohn Marino // 2 references. 268*e4b17023SJohn Marino // One reference for _S_classic, one for _S_global 269*e4b17023SJohn Marino _S_classic = new (&c_locale_impl) _Impl(2); 270*e4b17023SJohn Marino _S_global = _S_classic; 271*e4b17023SJohn Marino } 272*e4b17023SJohn Marino 273*e4b17023SJohn Marino void _S_initialize()274*e4b17023SJohn Marino locale::_S_initialize() 275*e4b17023SJohn Marino { 276*e4b17023SJohn Marino #ifdef __GTHREADS 277*e4b17023SJohn Marino if (__gthread_active_p()) 278*e4b17023SJohn Marino __gthread_once(&_S_once, _S_initialize_once); 279*e4b17023SJohn Marino #endif 280*e4b17023SJohn Marino if (!_S_classic) 281*e4b17023SJohn Marino _S_initialize_once(); 282*e4b17023SJohn Marino } 283*e4b17023SJohn Marino 284*e4b17023SJohn Marino // Definitions for static const data members of locale::_Impl 285*e4b17023SJohn Marino const locale::id* const 286*e4b17023SJohn Marino locale::_Impl::_S_id_ctype[] = 287*e4b17023SJohn Marino { 288*e4b17023SJohn Marino &std::ctype<char>::id, 289*e4b17023SJohn Marino &codecvt<char, char, mbstate_t>::id, 290*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 291*e4b17023SJohn Marino &std::ctype<wchar_t>::id, 292*e4b17023SJohn Marino &codecvt<wchar_t, char, mbstate_t>::id, 293*e4b17023SJohn Marino #endif 294*e4b17023SJohn Marino 0 295*e4b17023SJohn Marino }; 296*e4b17023SJohn Marino 297*e4b17023SJohn Marino const locale::id* const 298*e4b17023SJohn Marino locale::_Impl::_S_id_numeric[] = 299*e4b17023SJohn Marino { 300*e4b17023SJohn Marino &num_get<char>::id, 301*e4b17023SJohn Marino &num_put<char>::id, 302*e4b17023SJohn Marino &numpunct<char>::id, 303*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 304*e4b17023SJohn Marino &num_get<wchar_t>::id, 305*e4b17023SJohn Marino &num_put<wchar_t>::id, 306*e4b17023SJohn Marino &numpunct<wchar_t>::id, 307*e4b17023SJohn Marino #endif 308*e4b17023SJohn Marino 0 309*e4b17023SJohn Marino }; 310*e4b17023SJohn Marino 311*e4b17023SJohn Marino const locale::id* const 312*e4b17023SJohn Marino locale::_Impl::_S_id_collate[] = 313*e4b17023SJohn Marino { 314*e4b17023SJohn Marino &std::collate<char>::id, 315*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 316*e4b17023SJohn Marino &std::collate<wchar_t>::id, 317*e4b17023SJohn Marino #endif 318*e4b17023SJohn Marino 0 319*e4b17023SJohn Marino }; 320*e4b17023SJohn Marino 321*e4b17023SJohn Marino const locale::id* const 322*e4b17023SJohn Marino locale::_Impl::_S_id_time[] = 323*e4b17023SJohn Marino { 324*e4b17023SJohn Marino &__timepunct<char>::id, 325*e4b17023SJohn Marino &time_get<char>::id, 326*e4b17023SJohn Marino &time_put<char>::id, 327*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 328*e4b17023SJohn Marino &__timepunct<wchar_t>::id, 329*e4b17023SJohn Marino &time_get<wchar_t>::id, 330*e4b17023SJohn Marino &time_put<wchar_t>::id, 331*e4b17023SJohn Marino #endif 332*e4b17023SJohn Marino 0 333*e4b17023SJohn Marino }; 334*e4b17023SJohn Marino 335*e4b17023SJohn Marino const locale::id* const 336*e4b17023SJohn Marino locale::_Impl::_S_id_monetary[] = 337*e4b17023SJohn Marino { 338*e4b17023SJohn Marino &money_get<char>::id, 339*e4b17023SJohn Marino &money_put<char>::id, 340*e4b17023SJohn Marino &moneypunct<char, false>::id, 341*e4b17023SJohn Marino &moneypunct<char, true >::id, 342*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 343*e4b17023SJohn Marino &money_get<wchar_t>::id, 344*e4b17023SJohn Marino &money_put<wchar_t>::id, 345*e4b17023SJohn Marino &moneypunct<wchar_t, false>::id, 346*e4b17023SJohn Marino &moneypunct<wchar_t, true >::id, 347*e4b17023SJohn Marino #endif 348*e4b17023SJohn Marino 0 349*e4b17023SJohn Marino }; 350*e4b17023SJohn Marino 351*e4b17023SJohn Marino const locale::id* const 352*e4b17023SJohn Marino locale::_Impl::_S_id_messages[] = 353*e4b17023SJohn Marino { 354*e4b17023SJohn Marino &std::messages<char>::id, 355*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 356*e4b17023SJohn Marino &std::messages<wchar_t>::id, 357*e4b17023SJohn Marino #endif 358*e4b17023SJohn Marino 0 359*e4b17023SJohn Marino }; 360*e4b17023SJohn Marino 361*e4b17023SJohn Marino const locale::id* const* const 362*e4b17023SJohn Marino locale::_Impl::_S_facet_categories[] = 363*e4b17023SJohn Marino { 364*e4b17023SJohn Marino // Order must match the decl order in class locale. 365*e4b17023SJohn Marino locale::_Impl::_S_id_ctype, 366*e4b17023SJohn Marino locale::_Impl::_S_id_numeric, 367*e4b17023SJohn Marino locale::_Impl::_S_id_collate, 368*e4b17023SJohn Marino locale::_Impl::_S_id_time, 369*e4b17023SJohn Marino locale::_Impl::_S_id_monetary, 370*e4b17023SJohn Marino locale::_Impl::_S_id_messages, 371*e4b17023SJohn Marino 0 372*e4b17023SJohn Marino }; 373*e4b17023SJohn Marino 374*e4b17023SJohn Marino // Construct "C" _Impl. 375*e4b17023SJohn Marino locale::_Impl:: _Impl(size_t __refs)376*e4b17023SJohn Marino _Impl(size_t __refs) throw() 377*e4b17023SJohn Marino : _M_refcount(__refs), _M_facets(0), _M_facets_size(_GLIBCXX_NUM_FACETS), 378*e4b17023SJohn Marino _M_caches(0), _M_names(0) 379*e4b17023SJohn Marino { 380*e4b17023SJohn Marino _M_facets = new (&facet_vec) const facet*[_M_facets_size]; 381*e4b17023SJohn Marino _M_caches = new (&cache_vec) const facet*[_M_facets_size]; 382*e4b17023SJohn Marino for (size_t __i = 0; __i < _M_facets_size; ++__i) 383*e4b17023SJohn Marino _M_facets[__i] = _M_caches[__i] = 0; 384*e4b17023SJohn Marino 385*e4b17023SJohn Marino // Name the categories. 386*e4b17023SJohn Marino _M_names = new (&name_vec) char*[_S_categories_size]; 387*e4b17023SJohn Marino _M_names[0] = new (&name_c[0]) char[2]; 388*e4b17023SJohn Marino std::memcpy(_M_names[0], locale::facet::_S_get_c_name(), 2); 389*e4b17023SJohn Marino for (size_t __j = 1; __j < _S_categories_size; ++__j) 390*e4b17023SJohn Marino _M_names[__j] = 0; 391*e4b17023SJohn Marino 392*e4b17023SJohn Marino // This is needed as presently the C++ version of "C" locales 393*e4b17023SJohn Marino // != data in the underlying locale model for __timepunct, 394*e4b17023SJohn Marino // numpunct, and moneypunct. Also, the "C" locales must be 395*e4b17023SJohn Marino // constructed in a way such that they are pre-allocated. 396*e4b17023SJohn Marino // NB: Set locale::facets(ref) count to one so that each individual 397*e4b17023SJohn Marino // facet is not destroyed when the locale (and thus locale::_Impl) is 398*e4b17023SJohn Marino // destroyed. 399*e4b17023SJohn Marino _M_init_facet(new (&ctype_c) std::ctype<char>(0, false, 1)); 400*e4b17023SJohn Marino _M_init_facet(new (&codecvt_c) codecvt<char, char, mbstate_t>(1)); 401*e4b17023SJohn Marino 402*e4b17023SJohn Marino typedef __numpunct_cache<char> num_cache_c; 403*e4b17023SJohn Marino num_cache_c* __npc = new (&numpunct_cache_c) num_cache_c(2); 404*e4b17023SJohn Marino _M_init_facet(new (&numpunct_c) numpunct<char>(__npc, 1)); 405*e4b17023SJohn Marino 406*e4b17023SJohn Marino _M_init_facet(new (&num_get_c) num_get<char>(1)); 407*e4b17023SJohn Marino _M_init_facet(new (&num_put_c) num_put<char>(1)); 408*e4b17023SJohn Marino _M_init_facet(new (&collate_c) std::collate<char>(1)); 409*e4b17023SJohn Marino 410*e4b17023SJohn Marino typedef __moneypunct_cache<char, false> money_cache_cf; 411*e4b17023SJohn Marino typedef __moneypunct_cache<char, true> money_cache_ct; 412*e4b17023SJohn Marino money_cache_cf* __mpcf = new (&moneypunct_cache_cf) money_cache_cf(2); 413*e4b17023SJohn Marino _M_init_facet(new (&moneypunct_cf) moneypunct<char, false>(__mpcf, 1)); 414*e4b17023SJohn Marino money_cache_ct* __mpct = new (&moneypunct_cache_ct) money_cache_ct(2); 415*e4b17023SJohn Marino _M_init_facet(new (&moneypunct_ct) moneypunct<char, true>(__mpct, 1)); 416*e4b17023SJohn Marino 417*e4b17023SJohn Marino _M_init_facet(new (&money_get_c) money_get<char>(1)); 418*e4b17023SJohn Marino _M_init_facet(new (&money_put_c) money_put<char>(1)); 419*e4b17023SJohn Marino 420*e4b17023SJohn Marino typedef __timepunct_cache<char> time_cache_c; 421*e4b17023SJohn Marino time_cache_c* __tpc = new (&timepunct_cache_c) time_cache_c(2); 422*e4b17023SJohn Marino _M_init_facet(new (&timepunct_c) __timepunct<char>(__tpc, 1)); 423*e4b17023SJohn Marino 424*e4b17023SJohn Marino _M_init_facet(new (&time_get_c) time_get<char>(1)); 425*e4b17023SJohn Marino _M_init_facet(new (&time_put_c) time_put<char>(1)); 426*e4b17023SJohn Marino _M_init_facet(new (&messages_c) std::messages<char>(1)); 427*e4b17023SJohn Marino 428*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 429*e4b17023SJohn Marino _M_init_facet(new (&ctype_w) std::ctype<wchar_t>(1)); 430*e4b17023SJohn Marino _M_init_facet(new (&codecvt_w) codecvt<wchar_t, char, mbstate_t>(1)); 431*e4b17023SJohn Marino 432*e4b17023SJohn Marino typedef __numpunct_cache<wchar_t> num_cache_w; 433*e4b17023SJohn Marino num_cache_w* __npw = new (&numpunct_cache_w) num_cache_w(2); 434*e4b17023SJohn Marino _M_init_facet(new (&numpunct_w) numpunct<wchar_t>(__npw, 1)); 435*e4b17023SJohn Marino 436*e4b17023SJohn Marino _M_init_facet(new (&num_get_w) num_get<wchar_t>(1)); 437*e4b17023SJohn Marino _M_init_facet(new (&num_put_w) num_put<wchar_t>(1)); 438*e4b17023SJohn Marino _M_init_facet(new (&collate_w) std::collate<wchar_t>(1)); 439*e4b17023SJohn Marino 440*e4b17023SJohn Marino typedef __moneypunct_cache<wchar_t, false> money_cache_wf; 441*e4b17023SJohn Marino typedef __moneypunct_cache<wchar_t, true> money_cache_wt; 442*e4b17023SJohn Marino money_cache_wf* __mpwf = new (&moneypunct_cache_wf) money_cache_wf(2); 443*e4b17023SJohn Marino _M_init_facet(new (&moneypunct_wf) moneypunct<wchar_t, false>(__mpwf, 1)); 444*e4b17023SJohn Marino money_cache_wt* __mpwt = new (&moneypunct_cache_wt) money_cache_wt(2); 445*e4b17023SJohn Marino _M_init_facet(new (&moneypunct_wt) moneypunct<wchar_t, true>(__mpwt, 1)); 446*e4b17023SJohn Marino 447*e4b17023SJohn Marino _M_init_facet(new (&money_get_w) money_get<wchar_t>(1)); 448*e4b17023SJohn Marino _M_init_facet(new (&money_put_w) money_put<wchar_t>(1)); 449*e4b17023SJohn Marino 450*e4b17023SJohn Marino typedef __timepunct_cache<wchar_t> time_cache_w; 451*e4b17023SJohn Marino time_cache_w* __tpw = new (&timepunct_cache_w) time_cache_w(2); 452*e4b17023SJohn Marino _M_init_facet(new (&timepunct_w) __timepunct<wchar_t>(__tpw, 1)); 453*e4b17023SJohn Marino 454*e4b17023SJohn Marino _M_init_facet(new (&time_get_w) time_get<wchar_t>(1)); 455*e4b17023SJohn Marino _M_init_facet(new (&time_put_w) time_put<wchar_t>(1)); 456*e4b17023SJohn Marino _M_init_facet(new (&messages_w) std::messages<wchar_t>(1)); 457*e4b17023SJohn Marino #endif 458*e4b17023SJohn Marino 459*e4b17023SJohn Marino // This locale is safe to pre-cache, after all the facets have 460*e4b17023SJohn Marino // been created and installed. 461*e4b17023SJohn Marino _M_caches[numpunct<char>::id._M_id()] = __npc; 462*e4b17023SJohn Marino _M_caches[moneypunct<char, false>::id._M_id()] = __mpcf; 463*e4b17023SJohn Marino _M_caches[moneypunct<char, true>::id._M_id()] = __mpct; 464*e4b17023SJohn Marino _M_caches[__timepunct<char>::id._M_id()] = __tpc; 465*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 466*e4b17023SJohn Marino _M_caches[numpunct<wchar_t>::id._M_id()] = __npw; 467*e4b17023SJohn Marino _M_caches[moneypunct<wchar_t, false>::id._M_id()] = __mpwf; 468*e4b17023SJohn Marino _M_caches[moneypunct<wchar_t, true>::id._M_id()] = __mpwt; 469*e4b17023SJohn Marino _M_caches[__timepunct<wchar_t>::id._M_id()] = __tpw; 470*e4b17023SJohn Marino #endif 471*e4b17023SJohn Marino } 472*e4b17023SJohn Marino 473*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 474*e4b17023SJohn Marino } // namespace 475