diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index da392ff6a41..7ec0a9b79df 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2002-01-31 Benjamin Kosnik + + * config/locale/codecvt_specializations_ieee_1003.1-200x.h: + Initialize all data members in copy ctor. Make ctors explicit. + (__enc_traits::__enc_traits()): Default ctor does nothing. + (__enc_traits::_M_init): Guard against multiple iconv_opens. + * include/std/std_sstream.h (basic_stringbuf): Make data members + protected. + * include/std/std_fstream.h (basic_filebuf): Same. + * include/std/std_streambuf.h: Tweak. + * include/bits/streambuf.tcc: Same. + * include/bits/sstream.tcc: Same. + * include/bits/fstream.tcc: Same. + 2002-01-31 Loren Rittle * testsuite/22_locale/codecvt_members_char_char.cc: Do not diff --git a/libstdc++-v3/Makefile.in b/libstdc++-v3/Makefile.in index 3385a30a864..e1e996bf975 100644 --- a/libstdc++-v3/Makefile.in +++ b/libstdc++-v3/Makefile.in @@ -1,6 +1,6 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -308,7 +308,7 @@ maintainer-clean-recursive: dot_seen=no; \ rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ rev="$$subdir $$rev"; \ - test "$$subdir" = "." && dot_seen=yes; \ + test "$$subdir" != "." || dot_seen=yes; \ done; \ test "$$dot_seen" = "no" && rev=". $$rev"; \ target=`echo $@ | sed s/-recursive//`; \ diff --git a/libstdc++-v3/config/locale/codecvt_specializations_ieee_1003.1-200x.h b/libstdc++-v3/config/locale/codecvt_specializations_ieee_1003.1-200x.h index 3cf9fef9077..5cacffb81f8 100644 --- a/libstdc++-v3/config/locale/codecvt_specializations_ieee_1003.1-200x.h +++ b/libstdc++-v3/config/locale/codecvt_specializations_ieee_1003.1-200x.h @@ -1,6 +1,6 @@ // Locale support (codecvt) -*- C++ -*- -// Copyright (C) 2000, 2001 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -35,23 +35,18 @@ // Written by Benjamin Kosnik - // XXX - // __enc_traits may need to move up the locale header hierarchy, - // depending on if ctype ends up using it. - - // Extensions to use icov for dealing with character encodings, - // including conversions and comparisons between various character - // sets. This object encapsulates data that may need to be shared between - // char_traits, codecvt and ctype. + // XXX + // Define this here to codecvt.cc can have _S_max_size definition. +#define _GLIBCPP_USE___ENC_TRAITS 1 #if _GLIBCPP_USE_SHADOW_HEADERS using _C_legacy::CODESET; #endif - // XXX - // Define this here to codecvt.cc can have _S_max_size definition. -#define _GLIBCPP_USE___ENC_TRAITS 1 - + // Extension to use icov for dealing with character encodings, + // including conversions and comparisons between various character + // sets. This object encapsulates data that may need to be shared between + // char_traits, codecvt and ctype. class __enc_traits { public: @@ -81,7 +76,14 @@ int _M_int_bom; public: - __enc_traits(const locale& __loc = locale()) + explicit __enc_traits() + : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0) + { + memset(_M_int_enc, 0, _S_max_size); + memset(_M_ext_enc, 0, _S_max_size); + } + + explicit __enc_traits(const locale& __loc) : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0) { // __intc_end = whatever we are using internally, which is @@ -98,8 +100,8 @@ locale::facet::_S_destroy_c_locale(__cloc); } - __enc_traits(const char* __int, const char* __ext, int __ibom = 0, - int __ebom = 0) + explicit __enc_traits(const char* __int, const char* __ext, + int __ibom = 0, int __ebom = 0) : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0) { strncpy(_M_int_enc, __int, _S_max_size); @@ -111,7 +113,7 @@ // typedef STATE_T state_type // requires: state_type shall meet the requirements of // CopyConstructible types (20.1.3) - __enc_traits(const __enc_traits& __obj) + __enc_traits(const __enc_traits& __obj): _M_in_desc(0), _M_out_desc(0) { strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size); strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size); @@ -119,6 +121,18 @@ _M_int_bom = __obj._M_int_bom; } + // Need assignment operator as well. + __enc_traits& + operator=(const __enc_traits& __obj) + { + strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size); + strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size); + _M_in_desc = 0; + _M_out_desc = 0; + _M_ext_bom = __obj._M_ext_bom; + _M_int_bom = __obj._M_int_bom; + } + ~__enc_traits() { __desc_type __err = reinterpret_cast(-1); @@ -131,19 +145,25 @@ void _M_init() { - __desc_type __err = reinterpret_cast(-1); - _M_in_desc = iconv_open(_M_int_enc, _M_ext_enc); - if (_M_in_desc == __err) - __throw_runtime_error("creating iconv input descriptor failed."); - _M_out_desc = iconv_open(_M_ext_enc, _M_int_enc); - if (_M_out_desc == __err) - __throw_runtime_error("creating iconv output descriptor failed."); + const __desc_type __err = reinterpret_cast(-1); + if (!_M_in_desc) + { + _M_in_desc = iconv_open(_M_int_enc, _M_ext_enc); + if (_M_in_desc == __err) + __throw_runtime_error("creating iconv input descriptor failed."); + } + if (!_M_out_desc) + { + _M_out_desc = iconv_open(_M_ext_enc, _M_int_enc); + if (_M_out_desc == __err) + __throw_runtime_error("creating iconv output descriptor failed."); + } } bool _M_good() { - __desc_type __err = reinterpret_cast(-1); + const __desc_type __err = reinterpret_cast(-1); bool __test = _M_in_desc && _M_in_desc != __err; __test &= _M_out_desc && _M_out_desc != __err; return __test; @@ -157,14 +177,6 @@ _M_get_out_descriptor() { return &_M_out_desc; } - const char* - _M_get_internal_enc() - { return _M_int_enc; } - - const char* - _M_get_external_enc() - { return _M_ext_enc; } - int _M_get_external_bom() { return _M_ext_bom; } @@ -172,6 +184,14 @@ int _M_get_internal_bom() { return _M_int_bom; } + + const char* + _M_get_internal_enc() + { return _M_int_enc; } + + const char* + _M_get_external_enc() + { return _M_ext_enc; } }; // Partial specialization @@ -250,9 +270,7 @@ __iconv_adaptor(size_t(*iconv_func)(iconv_t, _T, size_t*, char**, size_t*), iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft) - { - return iconv_func(cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft); - } + { return iconv_func(cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft); } template codecvt_base::result diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 420516bb501..85a0e085e3f 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -143,9 +143,7 @@ namespace std int basic_filebuf<_CharT, _Traits>:: fd() - { - return _M_file->fd(); - } + { return _M_file->fd(); } template typename basic_filebuf<_CharT, _Traits>::__filebuf_type* @@ -604,14 +602,6 @@ namespace std // XXX The part in the above comment is not done. _M_last_overflowed = false; } - } // namespace std -#endif // _CPP_BITS_FSTREAM_TCC - - - - - - - +#endif diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc index ee8a6bfbf7b..d610532ae75 100644 --- a/libstdc++-v3/include/bits/sstream.tcc +++ b/libstdc++-v3/include/bits/sstream.tcc @@ -1,6 +1,7 @@ // String based streams -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2001, 2002 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -38,7 +39,6 @@ namespace std { - template typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type basic_stringbuf<_CharT, _Traits, _Alloc>:: @@ -206,8 +206,6 @@ namespace std return __ret; } - } // namespace std -#endif /* _CPP_BITS_SSTREAM_TCC */ - +#endif diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc index 9482c69c7ad..81b40716f98 100644 --- a/libstdc++-v3/include/bits/streambuf.tcc +++ b/libstdc++-v3/include/bits/streambuf.tcc @@ -1,6 +1,7 @@ // Stream buffer classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -34,8 +35,8 @@ #ifndef _CPP_BITS_STREAMBUF_TCC #define _CPP_BITS_STREAMBUF_TCC 1 -namespace std { - +namespace std +{ template typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>:: @@ -225,4 +226,4 @@ namespace std { } } // namespace std -#endif // _CPP_BITS_STREAMBUF_TCC +#endif diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h index ade2af9f7ac..7de9f30b3b3 100644 --- a/libstdc++-v3/include/std/std_fstream.h +++ b/libstdc++-v3/include/std/std_fstream.h @@ -44,8 +44,8 @@ #include #include -#include #include // For codecvt +#include #include namespace std @@ -72,7 +72,7 @@ namespace std friend class ios_base; // For sync_with_stdio. - private: + protected: // Data Members: // External buffer. __file_type* _M_file; @@ -422,7 +422,6 @@ namespace std }; } // namespace std - #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT # define export #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS @@ -431,4 +430,3 @@ namespace std #endif #endif - diff --git a/libstdc++-v3/include/std/std_sstream.h b/libstdc++-v3/include/std/std_sstream.h index b32e63df044..fc7eb05654f 100644 --- a/libstdc++-v3/include/std/std_sstream.h +++ b/libstdc++-v3/include/std/std_sstream.h @@ -66,7 +66,7 @@ namespace std typedef basic_string __string_type; typedef typename __string_type::size_type __size_type; - private: + protected: // Data Members: __string_type _M_string; @@ -360,8 +360,6 @@ namespace std }; } // namespace std - - #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT # define export #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS @@ -369,4 +367,4 @@ namespace std #endif #endif -#endif // _CPP_SSTREAM +#endif diff --git a/libstdc++-v3/include/std/std_streambuf.h b/libstdc++-v3/include/std/std_streambuf.h index ff58034ec89..48ffd97e2f7 100644 --- a/libstdc++-v3/include/std/std_streambuf.h +++ b/libstdc++-v3/include/std/std_streambuf.h @@ -83,7 +83,6 @@ namespace std __streambuf_type* __sbin,__streambuf_type* __sbout); protected: - // Pointer to the beginning of internally-allocated // space. Filebuf manually allocates/deallocates this, whereas // stringstreams attempt to use the built-in intelligence of the @@ -527,7 +526,6 @@ namespace std operator=(const __streambuf_type&); #endif }; - } // namespace std #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT @@ -537,5 +535,4 @@ namespace std #endif #endif -#endif /* _CPP_STREAMBUF */ - +#endif