From 40e5b283996d0f4856d7c530caf390f2e0c86daf Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Wed, 3 Apr 2002 02:32:52 +0000 Subject: [PATCH] ios.cc: (ios_base::Init::_S_ios_destroy): Remove flush calls. 2002-04-02 Benjamin Kosnik libstdc++/5268 * src/ios.cc: (ios_base::Init::_S_ios_destroy): Remove flush calls. * testsuite/27_io/ios_init.cc (tests04): Add test. libstdc++/3983 * include/bits/basic_ios.h (basic_ios::_M_get_fctype_ios): Remove. (basic_ios::_M_ios_fctype): Consistently name to _M_fctype. * include/bits/basic_ios.tcc: Same. Remove outdated comments. * include/bits/istream.tcc: Use _M_fctype, make consistent with ostream. * testsuite/27_io/ios_init.cc (tests03): Add test. From-SVN: r51777 --- libstdc++-v3/ChangeLog | 14 +++++ libstdc++-v3/include/bits/basic_ios.h | 6 +- libstdc++-v3/include/bits/basic_ios.tcc | 18 ++---- libstdc++-v3/include/bits/istream.tcc | 35 +++++------ libstdc++-v3/src/ios.cc | 6 -- libstdc++-v3/testsuite/27_io/ios_init.cc | 76 ++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 40 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b61a6997c81..bbb282d2610 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2002-04-02 Benjamin Kosnik + + libstdc++/5268 + * src/ios.cc: (ios_base::Init::_S_ios_destroy): Remove flush calls. + * testsuite/27_io/ios_init.cc (tests04): Add test. + + libstdc++/3983 + * include/bits/basic_ios.h (basic_ios::_M_get_fctype_ios): Remove. + (basic_ios::_M_ios_fctype): Consistently name to _M_fctype. + * include/bits/basic_ios.tcc: Same. Remove outdated comments. + * include/bits/istream.tcc: Use _M_fctype, make consistent with + ostream. + * testsuite/27_io/ios_init.cc (tests03): Add test. + 2002-04-02 Phil Edwards * include/Makefile.am (install-data-local): Use mkinstalldirs. diff --git a/libstdc++-v3/include/bits/basic_ios.h b/libstdc++-v3/include/bits/basic_ios.h index cc8617f986f..13ad0f82e99 100644 --- a/libstdc++-v3/include/bits/basic_ios.h +++ b/libstdc++-v3/include/bits/basic_ios.h @@ -69,17 +69,13 @@ namespace std basic_streambuf<_CharT, _Traits>* _M_streambuf; // Cached use_facet, which is based on the current locale info. - const __ctype_type* _M_ios_fctype; + const __ctype_type* _M_fctype; // From ostream. const __numput_type* _M_fnumput; // From istream. const __numget_type* _M_fnumget; public: - const __ctype_type* - _M_get_fctype_ios(void) - { return _M_ios_fctype; } - operator void*() const { return this->fail() ? 0 : const_cast(this); } diff --git a/libstdc++-v3/include/bits/basic_ios.tcc b/libstdc++-v3/include/bits/basic_ios.tcc index 7dba1222cfb..1e345dc2117 100644 --- a/libstdc++-v3/include/bits/basic_ios.tcc +++ b/libstdc++-v3/include/bits/basic_ios.tcc @@ -67,12 +67,6 @@ namespace std _Words* __words = (__rhs._M_word_size <= _S_local_word_size) ? _M_local_word : new _Words[__rhs._M_word_size]; - // XXX This is the only reason _Callback_list was defined - // inline. The suspicion is that this increased compilation - // times dramatically for functions that use this member - // function (inserters_extractors, ios_manip_fmtflags). FIX ME, - // clean this stuff up. Callbacks are broken right now, anyway. - // Bump refs before doing callbacks, for safety. _Callback_list* __cb = __rhs._M_callbacks; if (__cb) @@ -113,8 +107,8 @@ namespace std basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const { char __ret = __dfault; - if (_M_check_facet(_M_ios_fctype)) - __ret = _M_ios_fctype->narrow(__c, __dfault); + if (_M_check_facet(_M_fctype)) + __ret = _M_fctype->narrow(__c, __dfault); return __ret; } @@ -123,8 +117,8 @@ namespace std basic_ios<_CharT, _Traits>::widen(char __c) const { char_type __ret = char_type(); - if (_M_check_facet(_M_ios_fctype)) - __ret = _M_ios_fctype->widen(__c); + if (_M_check_facet(_M_fctype)) + __ret = _M_fctype->widen(__c); return __ret; } @@ -175,9 +169,9 @@ namespace std basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc) { if (has_facet<__ctype_type>(__loc)) - _M_ios_fctype = &use_facet<__ctype_type>(__loc); + _M_fctype = &use_facet<__ctype_type>(__loc); else - _M_ios_fctype = 0; + _M_fctype = 0; // Should be filled in by ostream and istream, respectively. if (has_facet<__numput_type>(__loc)) _M_fnumput = &use_facet<__numput_type>(__loc); diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 4a32c659be4..7f985594f9b 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -50,12 +50,13 @@ namespace std if (!__noskipws && (__in.flags() & ios_base::skipws)) { const __int_type __eof = traits_type::eof(); - const __ctype_type* __ctype = __in._M_get_fctype_ios(); __streambuf_type* __sb = __in.rdbuf(); __int_type __c = __sb->sgetc(); - - while (__c != __eof && __ctype->is(ctype_base::space, __c)) - __c = __sb->snextc(); + + if (__in._M_check_facet(__in._M_fctype)) + while (__c != __eof + && __in._M_fctype->is(ctype_base::space, __c)) + __c = __sb->snextc(); #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS //195. Should basic_istream::sentry's constructor ever set eofbit? @@ -1098,12 +1099,12 @@ namespace std if (__num == 0) __num = numeric_limits::max(); - __streambuf_type* __sb = __in.rdbuf(); - const __ctype_type* __ctype = __in._M_get_fctype_ios(); - int_type __c = __sb->sbumpc(); + const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc()); const int_type __eof = _Traits::eof(); - bool __testsp = __ctype->is(ctype_base::space, __c); + __streambuf_type* __sb = __in.rdbuf(); + int_type __c = __sb->sbumpc(); bool __testeof = __c == __eof; + bool __testsp = __ctype.is(ctype_base::space, __c); while (__extracted < __num - 1 && !__testeof && !__testsp) { @@ -1111,7 +1112,7 @@ namespace std ++__extracted; __c = __sb->sbumpc(); __testeof = __c == __eof; - __testsp = __ctype->is(ctype_base::space, __c); + __testsp = __ctype.is(ctype_base::space, __c); } if (!__testeof) @@ -1150,8 +1151,8 @@ namespace std typedef typename __istream_type::int_type __int_type; typedef typename __istream_type::char_type __char_type; + const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc()); __streambuf_type* __sb = __in.rdbuf(); - const __ctype_type* __ctype = __in._M_get_fctype_ios(); const __int_type __eof = _Traits::eof(); __int_type __c; bool __testeof; @@ -1160,8 +1161,8 @@ namespace std do { __c = __sb->sbumpc(); - __testeof = __c == __eof; - __testsp = __ctype->is(ctype_base::space, __c); + __testeof = __c == __eof; + __testsp = __ctype.is(ctype_base::space, __c); } while (!__testeof && __testsp); @@ -1195,12 +1196,12 @@ namespace std __size_type __n; __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size(); - __streambuf_type* __sb = __in.rdbuf(); - const __ctype_type* __ctype = __in._M_get_fctype_ios(); - __int_type __c = __sb->sbumpc(); + const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc()); const __int_type __eof = _Traits::eof(); - bool __testsp = __ctype->is(ctype_base::space, __c); + __streambuf_type* __sb = __in.rdbuf(); + __int_type __c = __sb->sbumpc(); bool __testeof = __c == __eof; + bool __testsp = __ctype.is(ctype_base::space, __c); while (__extracted < __n && !__testeof && !__testsp) { @@ -1208,7 +1209,7 @@ namespace std ++__extracted; __c = __sb->sbumpc(); __testeof = __c == __eof; - __testsp = __ctype->is(ctype_base::space, __c); + __testsp = __ctype.is(ctype_base::space, __c); } if (!__testeof) __sb->sputbackc(__c); diff --git a/libstdc++-v3/src/ios.cc b/libstdc++-v3/src/ios.cc index d13ff0e73cf..0aab0a25a3a 100644 --- a/libstdc++-v3/src/ios.cc +++ b/libstdc++-v3/src/ios.cc @@ -190,16 +190,10 @@ namespace std // Explicitly call dtors to free any memory that is dynamically // allocated by filebuf ctor or member functions, but don't // deallocate all memory by calling operator delete. - cout.flush(); - cerr.flush(); - clog.flush(); buf_cout.~filebuf(); buf_cin.~filebuf(); buf_cerr.~filebuf(); #ifdef _GLIBCPP_USE_WCHAR_T - wcout.flush(); - wcerr.flush(); - wclog.flush(); buf_wcout.~wfilebuf(); buf_wcin.~wfilebuf(); buf_wcerr.~wfilebuf(); diff --git a/libstdc++-v3/testsuite/27_io/ios_init.cc b/libstdc++-v3/testsuite/27_io/ios_init.cc index 38d2e522822..72b9fb4cc85 100644 --- a/libstdc++-v3/testsuite/27_io/ios_init.cc +++ b/libstdc++-v3/testsuite/27_io/ios_init.cc @@ -132,6 +132,80 @@ void test02() VERIFY( test ); } +// libstdc++/3983 +void test03() +{ + using namespace std; + bool test = true; + + // input streams + basic_istringstream iss_uc; + unsigned char arr[6] = { 'a', 'b', 'c', 'd', 'e' }; + + // Sentry uses locale info, so have to try one formatted input. + try + { + int i; + iss_uc >> i; + } + catch (bad_cast& obj) + { } + catch (exception& obj) + { test = false; } + + try + { + iss_uc >> arr; + } + catch (bad_cast& obj) + { } + catch (exception& obj) + { test = false; } + + try + { + iss_uc >> ws; + } + catch (bad_cast& obj) + { } + catch (exception& obj) + { test = false; } + + try + { + basic_string s_uc(arr); + iss_uc >> s_uc; + } + catch (bad_cast& obj) + { } + catch (exception& obj) + { test = false; } + + // output streams + basic_ostringstream oss_uc; + + try + { + bool b = true; + oss_uc << b; + } + catch (bad_cast& obj) + { } + catch (exception& obj) + { test = false; } + + VERIFY( test ); +} + +// libstdc++/5268 +int test04() +{ + std::stringbuf b1; + std::cout.rdbuf( &b1 ); + std::cout << "hello\n"; + return 0; +} + #if !__GXX_WEAK__ // Explicitly instantiate for systems with no COMDAT or weak support. template @@ -147,5 +221,7 @@ int main() { test01(); test02(); + test03(); + test04(); return 0; }