| 1 | // Copyright (C) 2014-2025 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 | // Instantiate the facets using old std::string ABI. |
| 24 | #define _GLIBCXX_USE_CXX11_ABI 0 |
| 25 | #include <locale> |
| 26 | |
| 27 | #if ! _GLIBCXX_USE_DUAL_ABI |
| 28 | # error This file should not be compiled for this configuration. |
| 29 | #endif |
| 30 | |
| 31 | namespace std _GLIBCXX_VISIBILITY(default) |
| 32 | { |
| 33 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 34 | |
| 35 | namespace |
| 36 | { |
| 37 | typedef char fake_collate_c[sizeof(std::collate<char>)] |
| 38 | __attribute__ ((aligned(__alignof__(std::collate<char>)))); |
| 39 | fake_collate_c collate_c; |
| 40 | |
| 41 | typedef char fake_numpunct_c[sizeof(numpunct<char>)] |
| 42 | __attribute__ ((aligned(__alignof__(numpunct<char>)))); |
| 43 | fake_numpunct_c numpunct_c; |
| 44 | |
| 45 | typedef char fake_moneypunct_c[sizeof(moneypunct<char, true>)] |
| 46 | __attribute__ ((aligned(__alignof__(moneypunct<char, true>)))); |
| 47 | fake_moneypunct_c moneypunct_ct; |
| 48 | fake_moneypunct_c moneypunct_cf; |
| 49 | |
| 50 | typedef char fake_money_get_c[sizeof(money_get<char>)] |
| 51 | __attribute__ ((aligned(__alignof__(money_get<char>)))); |
| 52 | fake_money_get_c money_get_c; |
| 53 | |
| 54 | typedef char fake_money_put_c[sizeof(money_put<char>)] |
| 55 | __attribute__ ((aligned(__alignof__(money_put<char>)))); |
| 56 | fake_money_put_c money_put_c; |
| 57 | |
| 58 | typedef char fake_time_get_c[sizeof(time_get<char>)] |
| 59 | __attribute__ ((aligned(__alignof__(time_get<char>)))); |
| 60 | fake_time_get_c time_get_c; |
| 61 | |
| 62 | typedef char fake_messages_c[sizeof(messages<char>)] |
| 63 | __attribute__ ((aligned(__alignof__(messages<char>)))); |
| 64 | fake_messages_c messages_c; |
| 65 | |
| 66 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 67 | typedef char fake_wollate_w[sizeof(std::collate<wchar_t>)] |
| 68 | __attribute__ ((aligned(__alignof__(std::collate<wchar_t>)))); |
| 69 | fake_wollate_w collate_w; |
| 70 | |
| 71 | typedef char fake_numpunct_w[sizeof(numpunct<wchar_t>)] |
| 72 | __attribute__ ((aligned(__alignof__(numpunct<wchar_t>)))); |
| 73 | fake_numpunct_w numpunct_w; |
| 74 | |
| 75 | typedef char fake_moneypunct_w[sizeof(moneypunct<wchar_t, true>)] |
| 76 | __attribute__ ((aligned(__alignof__(moneypunct<wchar_t, true>)))); |
| 77 | fake_moneypunct_w moneypunct_wt; |
| 78 | fake_moneypunct_w moneypunct_wf; |
| 79 | |
| 80 | typedef char fake_money_get_w[sizeof(money_get<wchar_t>)] |
| 81 | __attribute__ ((aligned(__alignof__(money_get<wchar_t>)))); |
| 82 | fake_money_get_w money_get_w; |
| 83 | |
| 84 | typedef char fake_money_put_w[sizeof(money_put<wchar_t>)] |
| 85 | __attribute__ ((aligned(__alignof__(money_put<wchar_t>)))); |
| 86 | fake_money_put_w money_put_w; |
| 87 | |
| 88 | typedef char fake_time_get_w[sizeof(time_get<wchar_t>)] |
| 89 | __attribute__ ((aligned(__alignof__(time_get<wchar_t>)))); |
| 90 | fake_time_get_w time_get_w; |
| 91 | |
| 92 | typedef char fake_messages_w[sizeof(messages<wchar_t>)] |
| 93 | __attribute__ ((aligned(__alignof__(messages<wchar_t>)))); |
| 94 | fake_messages_w messages_w; |
| 95 | #endif |
| 96 | } // anonymous namespace |
| 97 | |
| 98 | void |
| 99 | locale::_Impl::_M_init_extra(facet** caches) |
| 100 | { |
| 101 | auto __npc = static_cast<__numpunct_cache<char>*>(caches[0]); |
| 102 | auto __mpcf = static_cast<__moneypunct_cache<char, false>*>(caches[1]); |
| 103 | auto __mpct = static_cast<__moneypunct_cache<char, true>*>(caches[2]); |
| 104 | |
| 105 | _M_init_facet_unchecked(new (&numpunct_c) numpunct<char>(__npc, 1)); |
| 106 | _M_init_facet_unchecked(new (&collate_c) std::collate<char>(1)); |
| 107 | _M_init_facet_unchecked(new (&moneypunct_cf) moneypunct<char, false>(__mpcf, 1)); |
| 108 | _M_init_facet_unchecked(new (&moneypunct_ct) moneypunct<char, true>(__mpct, 1)); |
| 109 | _M_init_facet_unchecked(new (&money_get_c) money_get<char>(1)); |
| 110 | _M_init_facet_unchecked(new (&money_put_c) money_put<char>(1)); |
| 111 | _M_init_facet_unchecked(new (&time_get_c) time_get<char>(1)); |
| 112 | _M_init_facet_unchecked(new (&messages_c) std::messages<char>(1)); |
| 113 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 114 | auto __npw = static_cast<__numpunct_cache<wchar_t>*>(caches[3]); |
| 115 | auto __mpwf = static_cast<__moneypunct_cache<wchar_t, false>*>(caches[4]); |
| 116 | auto __mpwt = static_cast<__moneypunct_cache<wchar_t, true>*>(caches[5]); |
| 117 | |
| 118 | _M_init_facet_unchecked(new (&numpunct_w) numpunct<wchar_t>(__npw, 1)); |
| 119 | _M_init_facet_unchecked(new (&collate_w) std::collate<wchar_t>(1)); |
| 120 | _M_init_facet_unchecked(new (&moneypunct_wf) moneypunct<wchar_t, false>(__mpwf, 1)); |
| 121 | _M_init_facet_unchecked(new (&moneypunct_wt) moneypunct<wchar_t, true>(__mpwt, 1)); |
| 122 | _M_init_facet_unchecked(new (&money_get_w) money_get<wchar_t>(1)); |
| 123 | _M_init_facet_unchecked(new (&money_put_w) money_put<wchar_t>(1)); |
| 124 | _M_init_facet_unchecked(new (&time_get_w) time_get<wchar_t>(1)); |
| 125 | _M_init_facet_unchecked(new (&messages_w) std::messages<wchar_t>(1)); |
| 126 | #endif |
| 127 | |
| 128 | // The caches must be populated last, after creating all facets. |
| 129 | _M_caches[numpunct<char>::id._M_id()] = __npc; |
| 130 | _M_caches[moneypunct<char, false>::id._M_id()] = __mpcf; |
| 131 | _M_caches[moneypunct<char, true>::id._M_id()] = __mpct; |
| 132 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 133 | _M_caches[numpunct<wchar_t>::id._M_id()] = __npw; |
| 134 | _M_caches[moneypunct<wchar_t, false>::id._M_id()] = __mpwf; |
| 135 | _M_caches[moneypunct<wchar_t, true>::id._M_id()] = __mpwt; |
| 136 | #endif |
| 137 | } |
| 138 | |
| 139 | void |
| 140 | locale::_Impl::_M_init_extra(void* cloc, [[maybe_unused]] void* clocm, |
| 141 | const char* __s, |
| 142 | [[maybe_unused]] const char* __smon) |
| 143 | { |
| 144 | auto& __cloc = *static_cast<__c_locale*>(cloc); |
| 145 | |
| 146 | _M_init_facet_unchecked(new numpunct<char>(__cloc)); |
| 147 | _M_init_facet_unchecked(new std::collate<char>(__cloc)); |
| 148 | _M_init_facet_unchecked(new moneypunct<char, false>(__cloc, 0)); |
| 149 | _M_init_facet_unchecked(new moneypunct<char, true>(__cloc, 0)); |
| 150 | _M_init_facet_unchecked(new money_get<char>); |
| 151 | _M_init_facet_unchecked(new money_put<char>); |
| 152 | _M_init_facet_unchecked(new time_get<char>); |
| 153 | _M_init_facet_unchecked(new std::messages<char>(__cloc, __s)); |
| 154 | |
| 155 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 156 | auto& __clocm = *static_cast<__c_locale*>(clocm); |
| 157 | |
| 158 | _M_init_facet_unchecked(new numpunct<wchar_t>(__cloc)); |
| 159 | _M_init_facet_unchecked(new std::collate<wchar_t>(__cloc)); |
| 160 | _M_init_facet_unchecked(new moneypunct<wchar_t, false>(__clocm, __smon)); |
| 161 | _M_init_facet_unchecked(new moneypunct<wchar_t, true>(__clocm, __smon)); |
| 162 | _M_init_facet_unchecked(new money_get<wchar_t>); |
| 163 | _M_init_facet_unchecked(new money_put<wchar_t>); |
| 164 | _M_init_facet_unchecked(new time_get<wchar_t>); |
| 165 | _M_init_facet_unchecked(new std::messages<wchar_t>(__cloc, __s)); |
| 166 | #endif |
| 167 | } |
| 168 | |
| 169 | // TODO should be in another file |
| 170 | string |
| 171 | locale::name() const |
| 172 | { |
| 173 | string __ret; |
| 174 | if (!_M_impl->_M_names[0]) |
| 175 | __ret = '*'; |
| 176 | else if (_M_impl->_M_check_same_name()) |
| 177 | __ret = _M_impl->_M_names[0]; |
| 178 | else |
| 179 | { |
| 180 | __ret.reserve(128); |
| 181 | __ret += _S_categories[0]; |
| 182 | __ret += '='; |
| 183 | __ret += _M_impl->_M_names[0]; |
| 184 | for (size_t __i = 1; __i < _S_categories_size; ++__i) |
| 185 | { |
| 186 | __ret += ';'; |
| 187 | __ret += _S_categories[__i]; |
| 188 | __ret += '='; |
| 189 | __ret += _M_impl->_M_names[__i]; |
| 190 | } |
| 191 | } |
| 192 | return __ret; |
| 193 | } |
| 194 | |
| 195 | _GLIBCXX_END_NAMESPACE_VERSION |
| 196 | } |