2003-09-04 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / libstdc++-v3 / src / globals.cc
blobe9e5814f6b55d3b5b4687e86613fd5847645ea0f
1 // Copyright (C) 2001, 2002, 2003 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 2, or (at your option)
7 // any later version.
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.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
28 #include "bits/c++config.h"
29 #include "bits/gthr.h"
30 #include <fstream>
31 #include <istream>
32 #include <ostream>
33 #include <locale>
34 #include <ext/stdio_filebuf.h>
35 #include <ext/stdio_sync_filebuf.h>
37 // On AIX, and perhaps other systems, library initialization order is
38 // not guaranteed. For example, the static initializers for the main
39 // program might run before the static initializers for this library.
40 // That means that we cannot rely on static initialization in the
41 // library; there is no guarantee that things will get initialized in
42 // time. This file contains definitions of all global variables that
43 // require initialization as arrays of characters.
45 // NB: asm directives can rename these non-exported, namespace
46 // __gnu_cxx symbols into exported, namespace std symbols with the
47 // appropriate symbol version name.
48 // The rename syntax is
49 // asm (".symver currentname,oldname@@GLIBCXX_3.2")
50 // In macro form:
51 // _GLIBCXX_ASM_SYMVER(currentname, oldname, GLIBCXX_3.2)
53 namespace std
55 // Standard stream objects.
56 // NB: Iff <iostream> is included, these definitions become wonky.
57 typedef char fake_istream[sizeof(istream)]
58 __attribute__ ((aligned(__alignof__(istream))));
59 typedef char fake_ostream[sizeof(ostream)]
60 __attribute__ ((aligned(__alignof__(ostream))));
61 fake_istream cin;
62 fake_ostream cout;
63 fake_ostream cerr;
64 fake_ostream clog;
66 #ifdef _GLIBCXX_USE_WCHAR_T
67 typedef char fake_wistream[sizeof(wistream)]
68 __attribute__ ((aligned(__alignof__(wistream))));
69 typedef char fake_wostream[sizeof(wostream)]
70 __attribute__ ((aligned(__alignof__(wostream))));
71 fake_wistream wcin;
72 fake_wostream wcout;
73 fake_wostream wcerr;
74 fake_wostream wclog;
75 #endif
76 } // namespace std
78 namespace __gnu_cxx
80 using namespace std;
82 // We use different stream buffer types depending on whether
83 // ios_base::sync_with_stdio(false) has been called.
84 typedef char fake_stdiobuf[sizeof(stdio_sync_filebuf<char>)]
85 __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<char>))));
86 fake_stdiobuf buf_cout_sync;
87 fake_stdiobuf buf_cin_sync;
88 fake_stdiobuf buf_cerr_sync;
90 typedef char fake_filebuf[sizeof(stdio_filebuf<char>)]
91 __attribute__ ((aligned(__alignof__(stdio_filebuf<char>))));
92 fake_filebuf buf_cout;
93 fake_filebuf buf_cin;
94 fake_filebuf buf_cerr;
96 #ifdef _GLIBCXX_USE_WCHAR_T
97 typedef char fake_wstdiobuf[sizeof(stdio_sync_filebuf<wchar_t>)]
98 __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<wchar_t>))));
99 fake_wstdiobuf buf_wcout_sync;
100 fake_wstdiobuf buf_wcin_sync;
101 fake_wstdiobuf buf_wcerr_sync;
103 typedef char fake_wfilebuf[sizeof(stdio_filebuf<wchar_t>)]
104 __attribute__ ((aligned(__alignof__(stdio_filebuf<wchar_t>))));
105 fake_wfilebuf buf_wcout;
106 fake_wfilebuf buf_wcin;
107 fake_wfilebuf buf_wcerr;
108 #endif
110 typedef char fake_locale_Impl[sizeof(locale::_Impl)]
111 __attribute__ ((aligned(__alignof__(locale::_Impl))));
112 fake_locale_Impl c_locale_impl;
114 typedef char fake_locale[sizeof(locale)]
115 __attribute__ ((aligned(__alignof__(locale))));
116 fake_locale c_locale;
118 typedef char fake_name_vec[sizeof(char*)]
119 __attribute__ ((aligned(__alignof__(char*))));
120 fake_name_vec name_vec[6 + _GLIBCXX_NUM_CATEGORIES];
122 typedef char fake_names[sizeof(char[2])]
123 __attribute__ ((aligned(__alignof__(char[2]))));
124 fake_names name_c[6 + _GLIBCXX_NUM_CATEGORIES];
126 typedef char fake_facet_vec[sizeof(locale::facet*)]
127 __attribute__ ((aligned(__alignof__(locale::facet*))));
128 fake_facet_vec facet_vec[_GLIBCXX_NUM_FACETS];
130 typedef char fake_cache_vec[sizeof(locale::facet*)]
131 __attribute__ ((aligned(__alignof__(locale::facet*))));
132 fake_cache_vec cache_vec[_GLIBCXX_NUM_FACETS];
134 typedef char fake_ctype_c[sizeof(std::ctype<char>)]
135 __attribute__ ((aligned(__alignof__(std::ctype<char>))));
136 fake_ctype_c ctype_c;
138 typedef char fake_collate_c[sizeof(std::collate<char>)]
139 __attribute__ ((aligned(__alignof__(std::collate<char>))));
140 fake_collate_c collate_c;
142 typedef char fake_numpunct_c[sizeof(numpunct<char>)]
143 __attribute__ ((aligned(__alignof__(numpunct<char>))));
144 fake_numpunct_c numpunct_c;
146 typedef char fake_num_get_c[sizeof(num_get<char>)]
147 __attribute__ ((aligned(__alignof__(num_get<char>))));
148 fake_num_get_c num_get_c;
150 typedef char fake_num_put_c[sizeof(num_put<char>)]
151 __attribute__ ((aligned(__alignof__(num_put<char>))));
152 fake_num_put_c num_put_c;
154 typedef char fake_codecvt_c[sizeof(codecvt<char, char, mbstate_t>)]
155 __attribute__ ((aligned(__alignof__(codecvt<char, char, mbstate_t>))));
156 fake_codecvt_c codecvt_c;
158 typedef char fake_moneypunct_c[sizeof(moneypunct<char, true>)]
159 __attribute__ ((aligned(__alignof__(moneypunct<char, true>))));
160 fake_moneypunct_c moneypunct_ct;
161 fake_moneypunct_c moneypunct_cf;
163 typedef char fake_money_get_c[sizeof(money_get<char>)]
164 __attribute__ ((aligned(__alignof__(money_get<char>))));
165 fake_money_get_c money_get_c;
167 typedef char fake_money_put_c[sizeof(money_put<char>)]
168 __attribute__ ((aligned(__alignof__(money_put<char>))));
169 fake_money_put_c money_put_c;
171 typedef char fake_timepunct_c[sizeof(__timepunct<char>)]
172 __attribute__ ((aligned(__alignof__(__timepunct<char>))));
173 fake_timepunct_c timepunct_c;
175 typedef char fake_time_get_c[sizeof(time_get<char>)]
176 __attribute__ ((aligned(__alignof__(time_get<char>))));
177 fake_time_get_c time_get_c;
179 typedef char fake_time_put_c[sizeof(time_put<char>)]
180 __attribute__ ((aligned(__alignof__(time_put<char>))));
181 fake_time_put_c time_put_c;
183 typedef char fake_messages_c[sizeof(messages<char>)]
184 __attribute__ ((aligned(__alignof__(messages<char>))));
185 fake_messages_c messages_c;
187 #ifdef _GLIBCXX_USE_WCHAR_T
188 typedef char fake_wtype_w[sizeof(std::ctype<wchar_t>)]
189 __attribute__ ((aligned(__alignof__(std::ctype<wchar_t>))));
190 fake_wtype_w ctype_w;
192 typedef char fake_wollate_w[sizeof(std::collate<wchar_t>)]
193 __attribute__ ((aligned(__alignof__(std::collate<wchar_t>))));
194 fake_wollate_w collate_w;
196 typedef char fake_numpunct_w[sizeof(numpunct<wchar_t>)]
197 __attribute__ ((aligned(__alignof__(numpunct<wchar_t>))));
198 fake_numpunct_w numpunct_w;
200 typedef char fake_num_get_w[sizeof(num_get<wchar_t>)]
201 __attribute__ ((aligned(__alignof__(num_get<wchar_t>))));
202 fake_num_get_w num_get_w;
204 typedef char fake_num_put_w[sizeof(num_put<wchar_t>)]
205 __attribute__ ((aligned(__alignof__(num_put<wchar_t>))));
206 fake_num_put_w num_put_w;
208 typedef char fake_wodecvt_w[sizeof(codecvt<wchar_t, char, mbstate_t>)]
209 __attribute__ ((aligned(__alignof__(codecvt<wchar_t, char, mbstate_t>))));
210 fake_wodecvt_w codecvt_w;
212 typedef char fake_moneypunct_w[sizeof(moneypunct<wchar_t, true>)]
213 __attribute__ ((aligned(__alignof__(moneypunct<wchar_t, true>))));
214 fake_moneypunct_w moneypunct_wt;
215 fake_moneypunct_w moneypunct_wf;
217 typedef char fake_money_get_w[sizeof(money_get<wchar_t>)]
218 __attribute__ ((aligned(__alignof__(money_get<wchar_t>))));
219 fake_money_get_w money_get_w;
221 typedef char fake_money_put_w[sizeof(money_put<wchar_t>)]
222 __attribute__ ((aligned(__alignof__(money_put<wchar_t>))));
223 fake_money_put_w money_put_w;
225 typedef char fake_timepunct_w[sizeof(__timepunct<wchar_t>)]
226 __attribute__ ((aligned(__alignof__(__timepunct<wchar_t>))));
227 fake_timepunct_w timepunct_w;
229 typedef char fake_time_get_w[sizeof(time_get<wchar_t>)]
230 __attribute__ ((aligned(__alignof__(time_get<wchar_t>))));
231 fake_time_get_w time_get_w;
233 typedef char fake_time_put_w[sizeof(time_put<wchar_t>)]
234 __attribute__ ((aligned(__alignof__(time_put<wchar_t>))));
235 fake_time_put_w time_put_w;
237 typedef char fake_messages_w[sizeof(messages<wchar_t>)]
238 __attribute__ ((aligned(__alignof__(messages<wchar_t>))));
239 fake_messages_w messages_w;
240 #endif
242 // Storage for "C" locale caches.
243 typedef char fake_num_cache_c[sizeof(std::__numpunct_cache<char>)]
244 __attribute__ ((aligned(__alignof__(std::__numpunct_cache<char>))));
245 fake_num_cache_c numpunct_cache_c;
247 typedef char fake_money_cache_c[sizeof(std::__moneypunct_cache<char>)]
248 __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<char>))));
249 fake_money_cache_c moneypunct_cache_ct;
250 fake_money_cache_c moneypunct_cache_cf;
252 typedef char fake_time_cache_c[sizeof(std::__timepunct_cache<char>)]
253 __attribute__ ((aligned(__alignof__(std::__timepunct_cache<char>))));
254 fake_time_cache_c timepunct_cache_c;
256 #ifdef _GLIBCXX_USE_WCHAR_T
257 typedef char fake_num_cache_w[sizeof(std::__numpunct_cache<wchar_t>)]
258 __attribute__ ((aligned(__alignof__(std::__numpunct_cache<wchar_t>))));
259 fake_num_cache_w numpunct_cache_w;
261 typedef char fake_money_cache_w[sizeof(std::__moneypunct_cache<wchar_t>)]
262 __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<wchar_t>))));
263 fake_money_cache_w moneypunct_cache_wt;
264 fake_money_cache_w moneypunct_cache_wf;
266 typedef char fake_time_cache_w[sizeof(std::__timepunct_cache<wchar_t>)]
267 __attribute__ ((aligned(__alignof__(std::__timepunct_cache<wchar_t>))));
268 fake_time_cache_w timepunct_cache_w;
269 #endif
271 // Globals for once-only runtime initialization of mutex objects. This
272 // allows static initialization of these objects on systems that need a
273 // function call to initialize a mutex. For example, see stl_threads.h.
274 #ifdef __GTHREAD_MUTEX_INIT
275 #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
276 __gthread_once_t _GLIBCXX_once = __GTHREAD_ONCE_INIT;
277 __gthread_mutex_t _GLIBCXX_mutex;
278 __gthread_mutex_t *_GLIBCXX_mutex_address;
280 // Once-only initializer function for _GLIBCXX_mutex.
281 void
282 _GLIBCXX_mutex_init ()
283 { __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCXX_mutex); }
285 // Once-only initializer function for _GLIBCXX_mutex_address.
286 void
287 _GLIBCXX_mutex_address_init ()
288 { __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCXX_mutex_address); }
289 #endif
290 } // namespace __gnu_cxx