OSDN Git Service

2009-01-07 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / compatibility.cc
1 // Compatibility symbols for previous versions -*- C++ -*-
2
3 // Copyright (C) 2005, 2006, 2009
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 #include <bits/c++config.h>
32
33 #if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
34     && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE)
35 #define istreambuf_iterator istreambuf_iteratorXX
36 #define basic_fstream basic_fstreamXX
37 #define basic_ifstream basic_ifstreamXX
38 #define basic_ofstream basic_ofstreamXX
39 #define _M_copy(a, b, c) _M_copyXX(a, b, c)
40 #define _M_move(a, b, c) _M_moveXX(a, b, c)
41 #define _M_assign(a, b, c) _M_assignXX(a, b, c)
42 #define _M_disjunct(a) _M_disjunctXX(a)
43 #define _M_check_length(a, b, c) _M_check_lengthXX(a, b, c)
44 #define _M_set_length_and_sharable(a) _M_set_length_and_sharableXX(a)
45 #define ignore ignoreXX
46 #define eq eqXX
47 #define _List_node_base _List_node_baseXX
48 #endif
49
50 #include <string>
51 #include <istream>
52 #include <fstream>
53 #include <sstream>
54 #include <cmath>
55 #include <ext/numeric_traits.h>
56
57 _GLIBCXX_BEGIN_NAMESPACE(std)
58
59   // std::istream ignore explicit specializations.
60   template<>
61     basic_istream<char>&
62     basic_istream<char>::
63     ignore(streamsize __n)
64     {
65       if (__n == 1)
66         return ignore();
67       
68       _M_gcount = 0;
69       sentry __cerb(*this, true);
70       if (__cerb && __n > 0)
71         {
72           ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
73           try
74             {
75               const int_type __eof = traits_type::eof();
76               __streambuf_type* __sb = this->rdbuf();
77               int_type __c = __sb->sgetc();
78
79               // See comment in istream.tcc.
80               bool __large_ignore = false;
81               while (true)
82                 {
83                   while (_M_gcount < __n
84                          && !traits_type::eq_int_type(__c, __eof))
85                     {
86                       streamsize __size = std::min(streamsize(__sb->egptr()
87                                                               - __sb->gptr()),
88                                                   streamsize(__n - _M_gcount));
89                       if (__size > 1)
90                         {
91                           __sb->gbump(__size);
92                           _M_gcount += __size;
93                           __c = __sb->sgetc();
94                         }
95                       else
96                         {
97                           ++_M_gcount;
98                           __c = __sb->snextc();
99                         } 
100                     }
101                   if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
102                       && !traits_type::eq_int_type(__c, __eof))
103                     {
104                       _M_gcount =
105                         __gnu_cxx::__numeric_traits<streamsize>::__min;
106                       __large_ignore = true;
107                     }
108                   else
109                     break;
110                 }
111
112               if (__large_ignore)
113                 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
114
115               if (traits_type::eq_int_type(__c, __eof))
116                 __err |= ios_base::eofbit;
117             }
118           catch(__cxxabiv1::__forced_unwind&)
119             {
120               this->_M_setstate(ios_base::badbit);
121               __throw_exception_again;
122             }
123           catch(...)
124             { this->_M_setstate(ios_base::badbit); }
125           if (__err)
126             this->setstate(__err);
127         }
128       return *this;
129     } 
130
131 #ifdef _GLIBCXX_USE_WCHAR_T
132   template<>
133     basic_istream<wchar_t>&
134     basic_istream<wchar_t>::
135     ignore(streamsize __n)
136     {
137       if (__n == 1)
138         return ignore();
139       
140       _M_gcount = 0;
141       sentry __cerb(*this, true);
142       if (__cerb && __n > 0)
143         {
144           ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
145           try
146             {
147               const int_type __eof = traits_type::eof();
148               __streambuf_type* __sb = this->rdbuf();
149               int_type __c = __sb->sgetc();
150
151               bool __large_ignore = false;
152               while (true)
153                 {
154                   while (_M_gcount < __n
155                          && !traits_type::eq_int_type(__c, __eof))
156                     {
157                       streamsize __size = std::min(streamsize(__sb->egptr()
158                                                               - __sb->gptr()),
159                                                   streamsize(__n - _M_gcount));
160                       if (__size > 1)
161                         {
162                           __sb->gbump(__size);
163                           _M_gcount += __size;
164                           __c = __sb->sgetc();
165                         }
166                       else
167                         {
168                           ++_M_gcount;
169                           __c = __sb->snextc();
170                         }
171                     }
172                   if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
173                       && !traits_type::eq_int_type(__c, __eof))
174                     {
175                       _M_gcount =
176                         __gnu_cxx::__numeric_traits<streamsize>::__min;
177                       __large_ignore = true;
178                     }
179                   else
180                     break;
181                 }
182
183               if (__large_ignore)
184                 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
185
186               if (traits_type::eq_int_type(__c, __eof))
187                 __err |= ios_base::eofbit;
188             }
189           catch(__cxxabiv1::__forced_unwind&)
190             {
191               this->_M_setstate(ios_base::badbit);
192               __throw_exception_again;
193             }
194           catch(...)
195             { this->_M_setstate(ios_base::badbit); }
196           if (__err)
197             this->setstate(__err);
198         }
199       return *this;
200     }
201 #endif
202
203 _GLIBCXX_END_NAMESPACE
204
205
206 // NB: These symbols renames should go into the shared library only,
207 // and only those shared libraries that support versioning.
208 #if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
209     && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE)
210
211 /* gcc-3.4.4
212 _ZNSt19istreambuf_iteratorIcSt11char_traitsIcEEppEv
213 _ZNSt19istreambuf_iteratorIwSt11char_traitsIwEEppEv
214  */
215
216 _GLIBCXX_BEGIN_NAMESPACE(std)
217
218   template
219     istreambuf_iterator<char>&
220     istreambuf_iterator<char>::operator++();
221
222 #ifdef _GLIBCXX_USE_WCHAR_T
223   template
224     istreambuf_iterator<wchar_t>&
225     istreambuf_iterator<wchar_t>::operator++();
226 #endif
227
228 _GLIBCXX_END_NAMESPACE
229
230
231 /* gcc-4.0.0
232 _ZNSs4_Rep26_M_set_length_and_sharableEj
233 _ZNSs7_M_copyEPcPKcj
234 _ZNSs7_M_moveEPcPKcj
235 _ZNSs9_M_assignEPcjc
236 _ZNKSs11_M_disjunctEPKc
237 _ZNKSs15_M_check_lengthEjjPKc
238 _ZNSbIwSt11char_traitsIwESaIwEE4_Rep26_M_set_length_and_sharableEj
239 _ZNSbIwSt11char_traitsIwESaIwEE7_M_copyEPwPKwj
240 _ZNSbIwSt11char_traitsIwESaIwEE7_M_moveEPwPKwj
241 _ZNSbIwSt11char_traitsIwESaIwEE9_M_assignEPwjw
242 _ZNKSbIwSt11char_traitsIwESaIwEE11_M_disjunctEPKw
243 _ZNKSbIwSt11char_traitsIwESaIwEE15_M_check_lengthEjjPKc
244
245 _ZNKSt13basic_fstreamIcSt11char_traitsIcEE7is_openEv
246 _ZNKSt13basic_fstreamIwSt11char_traitsIwEE7is_openEv
247 _ZNKSt14basic_ifstreamIcSt11char_traitsIcEE7is_openEv
248 _ZNKSt14basic_ifstreamIwSt11char_traitsIwEE7is_openEv
249 _ZNKSt14basic_ofstreamIcSt11char_traitsIcEE7is_openEv
250 _ZNKSt14basic_ofstreamIwSt11char_traitsIwEE7is_openEv
251
252 _ZNSi6ignoreEi
253 _ZNSi6ignoreEv
254 _ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEi
255 _ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEv
256
257 _ZNSt11char_traitsIcE2eqERKcS2_
258 _ZNSt11char_traitsIwE2eqERKwS2_
259  */
260 _GLIBCXX_BEGIN_NAMESPACE(std)
261
262   // std::char_traits is explicitly specialized
263   bool (* __p1)(const char&, const char&) = &char_traits<char>::eq;
264
265   // std::string
266   template
267     void
268     basic_string<char>::_M_copy(char*, const char*, size_t);
269
270   template
271     void
272     basic_string<char>::_M_move(char*, const char*, size_t);
273
274   template
275     void
276     basic_string<char>::_M_assign(char*, size_t, char);
277
278   template
279     bool
280     basic_string<char>::_M_disjunct(const char*) const;
281
282   template
283     void
284     basic_string<char>::_M_check_length(size_t, size_t, const char*) const;
285
286   template
287     void
288     basic_string<char>::_Rep::_M_set_length_and_sharable(size_t);
289
290
291   // std::istream
292   template
293     basic_istream<char>&
294     basic_istream<char>::ignore(); 
295
296   template
297     bool
298     basic_fstream<char>::is_open() const;
299
300   template
301     bool
302     basic_ifstream<char>::is_open() const;
303
304   template
305     bool
306     basic_ofstream<char>::is_open() const;
307
308 #ifdef _GLIBCXX_USE_WCHAR_T
309   bool (* __p2)(const wchar_t&, const wchar_t&) = &char_traits<wchar_t>::eq;
310
311   // std::wstring
312   template
313     void
314     basic_string<wchar_t>::_M_copy(wchar_t*, const wchar_t*, size_t);
315
316   template
317     void
318     basic_string<wchar_t>::_M_move(wchar_t*, const wchar_t*, size_t);
319
320   template
321     void
322     basic_string<wchar_t>::_M_assign(wchar_t*, size_t, wchar_t);
323
324   template
325     bool
326     basic_string<wchar_t>::_M_disjunct(const wchar_t*) const;
327
328   template
329     void
330     basic_string<wchar_t>::_M_check_length(size_t, size_t, 
331                                            const char*) const;
332
333   template
334     void
335     basic_string<wchar_t>::_Rep::_M_set_length_and_sharable(size_t);
336
337   template
338     basic_istream<wchar_t>&
339     basic_istream<wchar_t>::ignore(); 
340
341   template
342     bool
343     basic_fstream<wchar_t>::is_open() const;
344
345   template
346     bool
347     basic_ifstream<wchar_t>::is_open() const;
348
349   template
350     bool
351     basic_ofstream<wchar_t>::is_open() const;
352 #endif
353
354 _GLIBCXX_END_NAMESPACE
355
356 // The rename syntax for default exported names is
357 //   asm (".symver name1,exportedname@GLIBCXX_3.4")
358 //   asm (".symver name2,exportedname@@GLIBCXX_3.4.5")
359 // In the future, GLIBCXX_ABI > 6 should remove all uses of
360 // _GLIBCXX_*_SYMVER macros in this file.
361
362 #define _GLIBCXX_3_4_SYMVER(XXname, name) \
363    extern "C" void \
364    _X##name() \
365    __attribute__ ((alias(#XXname))); \
366    asm (".symver " "_X" #name "," #name "@GLIBCXX_3.4");
367
368 #define _GLIBCXX_3_4_5_SYMVER(XXname, name) \
369    extern "C" void \
370    _Y##name() \
371    __attribute__ ((alias(#XXname))); \
372    asm (".symver " "_Y" #name  "," #name "@@GLIBCXX_3.4.5");
373
374 #define _GLIBCXX_ASM_SYMVER(cur, old, version) \
375    asm (".symver " #cur "," #old "@@" #version);
376
377 #define _GLIBCXX_APPLY_SYMVER _GLIBCXX_3_4_SYMVER
378 #include <bits/compatibility.h>
379 #undef _GLIBCXX_APPLY_SYMVER
380
381 #define _GLIBCXX_APPLY_SYMVER _GLIBCXX_3_4_5_SYMVER
382 #include <bits/compatibility.h>
383 #undef _GLIBCXX_APPLY_SYMVER
384
385
386 /* gcc-3.4.0
387 _ZN10__gnu_norm15_List_node_base4hookEPS0_;
388 _ZN10__gnu_norm15_List_node_base4swapERS0_S1_;
389 _ZN10__gnu_norm15_List_node_base6unhookEv;
390 _ZN10__gnu_norm15_List_node_base7reverseEv;
391 _ZN10__gnu_norm15_List_node_base8transferEPS0_S1_;
392 */
393 #include "list.cc"
394 _GLIBCXX_ASM_SYMVER(_ZNSt17_List_node_baseXX4hookEPS_, \
395 _ZN10__gnu_norm15_List_node_base4hookEPS0_, \
396 GLIBCXX_3.4)
397
398 _GLIBCXX_ASM_SYMVER(_ZNSt17_List_node_baseXX4swapERS_S0_, \
399 _ZN10__gnu_norm15_List_node_base4swapERS0_S1_, \
400 GLIBCXX_3.4)
401
402 _GLIBCXX_ASM_SYMVER(_ZNSt17_List_node_baseXX6unhookEv, \
403 _ZN10__gnu_norm15_List_node_base6unhookEv, \
404 GLIBCXX_3.4)
405
406 _GLIBCXX_ASM_SYMVER(_ZNSt17_List_node_baseXX7reverseEv, \
407 _ZN10__gnu_norm15_List_node_base7reverseEv, \
408 GLIBCXX_3.4)
409
410 _GLIBCXX_ASM_SYMVER(_ZNSt17_List_node_baseXX8transferEPS_S0_, \
411 _ZN10__gnu_norm15_List_node_base8transferEPS0_S1_, \
412 GLIBCXX_3.4)
413 #undef _List_node_base
414
415 // gcc-4.1.0
416 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
417 #define _GLIBCXX_MATHL_WRAPPER(name, argdecl, args, ver) \
418 extern "C" double                                               \
419 __ ## name ## l_wrapper argdecl                                 \
420 {                                                               \
421   return name args;                                             \
422 }                                                               \
423 asm (".symver __" #name "l_wrapper, " #name "l@" #ver)
424
425 #define _GLIBCXX_MATHL_WRAPPER1(name, ver) \
426   _GLIBCXX_MATHL_WRAPPER (name, (double x), (x), ver)
427
428 #define _GLIBCXX_MATHL_WRAPPER2(name, ver) \
429   _GLIBCXX_MATHL_WRAPPER (name, (double x, double y), (x, y), ver)
430
431 #ifdef _GLIBCXX_HAVE_ACOSL
432 _GLIBCXX_MATHL_WRAPPER1 (acos, GLIBCXX_3.4.3);
433 #endif
434 #ifdef _GLIBCXX_HAVE_ASINL
435 _GLIBCXX_MATHL_WRAPPER1 (asin, GLIBCXX_3.4.3);
436 #endif
437 #ifdef _GLIBCXX_HAVE_ATAN2L
438 _GLIBCXX_MATHL_WRAPPER2 (atan2, GLIBCXX_3.4);
439 #endif
440 #ifdef _GLIBCXX_HAVE_ATANL
441 _GLIBCXX_MATHL_WRAPPER1 (atan, GLIBCXX_3.4.3);
442 #endif
443 #ifdef _GLIBCXX_HAVE_CEILL
444 _GLIBCXX_MATHL_WRAPPER1 (ceil, GLIBCXX_3.4.3);
445 #endif
446 #ifdef _GLIBCXX_HAVE_COSHL
447 _GLIBCXX_MATHL_WRAPPER1 (cosh, GLIBCXX_3.4);
448 #endif
449 #ifdef _GLIBCXX_HAVE_COSL
450 _GLIBCXX_MATHL_WRAPPER1 (cos, GLIBCXX_3.4);
451 #endif
452 #ifdef _GLIBCXX_HAVE_EXPL
453 _GLIBCXX_MATHL_WRAPPER1 (exp, GLIBCXX_3.4);
454 #endif
455 #ifdef _GLIBCXX_HAVE_FLOORL
456 _GLIBCXX_MATHL_WRAPPER1 (floor, GLIBCXX_3.4.3);
457 #endif
458 #ifdef _GLIBCXX_HAVE_FMODL
459 _GLIBCXX_MATHL_WRAPPER2 (fmod, GLIBCXX_3.4.3);
460 #endif
461 #ifdef _GLIBCXX_HAVE_FREXPL
462 _GLIBCXX_MATHL_WRAPPER (frexp, (double x, int *y), (x, y), GLIBCXX_3.4.3);
463 #endif
464 #ifdef _GLIBCXX_HAVE_HYPOTL
465 _GLIBCXX_MATHL_WRAPPER2 (hypot, GLIBCXX_3.4);
466 #endif
467 #ifdef _GLIBCXX_HAVE_LDEXPL
468 _GLIBCXX_MATHL_WRAPPER (ldexp, (double x, int y), (x, y), GLIBCXX_3.4.3);
469 #endif
470 #ifdef _GLIBCXX_HAVE_LOG10L
471 _GLIBCXX_MATHL_WRAPPER1 (log10, GLIBCXX_3.4);
472 #endif
473 #ifdef _GLIBCXX_HAVE_LOGL
474 _GLIBCXX_MATHL_WRAPPER1 (log, GLIBCXX_3.4);
475 #endif
476 #ifdef _GLIBCXX_HAVE_MODFL
477 _GLIBCXX_MATHL_WRAPPER (modf, (double x, double *y), (x, y), GLIBCXX_3.4.3);
478 #endif
479 #ifdef _GLIBCXX_HAVE_POWL
480 _GLIBCXX_MATHL_WRAPPER2 (pow, GLIBCXX_3.4);
481 #endif
482 #ifdef _GLIBCXX_HAVE_SINHL
483 _GLIBCXX_MATHL_WRAPPER1 (sinh, GLIBCXX_3.4);
484 #endif
485 #ifdef _GLIBCXX_HAVE_SINL
486 _GLIBCXX_MATHL_WRAPPER1 (sin, GLIBCXX_3.4);
487 #endif
488 #ifdef _GLIBCXX_HAVE_SQRTL
489 _GLIBCXX_MATHL_WRAPPER1 (sqrt, GLIBCXX_3.4);
490 #endif
491 #ifdef _GLIBCXX_HAVE_TANHL
492 _GLIBCXX_MATHL_WRAPPER1 (tanh, GLIBCXX_3.4);
493 #endif
494 #ifdef _GLIBCXX_HAVE_TANL
495 _GLIBCXX_MATHL_WRAPPER1 (tan, GLIBCXX_3.4);
496 #endif
497 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT
498
499 #endif
500
501 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
502 extern void *_ZTVN10__cxxabiv123__fundamental_type_infoE[];
503 extern void *_ZTVN10__cxxabiv119__pointer_type_infoE[];
504 extern __attribute__((used, weak)) const char _ZTSe[2] = "e";
505 extern __attribute__((used, weak)) const char _ZTSPe[3] = "Pe";
506 extern __attribute__((used, weak)) const char _ZTSPKe[4] = "PKe";
507 extern __attribute__((used, weak)) const void *_ZTIe[2]
508   = { (void *) &_ZTVN10__cxxabiv123__fundamental_type_infoE[2],
509       (void *) _ZTSe };
510 extern __attribute__((used, weak)) const void *_ZTIPe[4]
511   = { (void *) &_ZTVN10__cxxabiv119__pointer_type_infoE[2],
512       (void *) _ZTSPe, (void *) 0L, (void *) _ZTIe };
513 extern __attribute__((used, weak)) const void *_ZTIPKe[4]
514   = { (void *) &_ZTVN10__cxxabiv119__pointer_type_infoE[2],
515       (void *) _ZTSPKe, (void *) 1L, (void *) _ZTIe };
516 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT
517
518
519
520 #ifdef _GLIBCXX_SYMVER_DARWIN
521 #if (defined(__ppc__) || defined(__ppc64__)) && defined(PIC)
522 /* __eprintf shouldn't have been made visible from libstdc++, or
523    anywhere, but on Mac OS X 10.4 it was defined in
524    libstdc++.6.0.3.dylib; so on that platform we have to keep defining
525    it to keep binary compatibility.  We can't just put the libgcc
526    version in the export list, because that doesn't work; once a
527    symbol is marked as hidden, it stays that way.  */
528
529 #include <cstdio>
530 #include <cstdlib>
531
532 using namespace std;
533
534 extern "C" void
535 __eprintf(const char *string, const char *expression,
536           unsigned int line, const char *filename)
537 {
538   fprintf(stderr, string, expression, line, filename);
539   fflush(stderr);
540   abort();
541 }
542 #endif
543 #endif