[v3] libstdc++/5268/3983
Benjamin Kosnik
bkoz@redhat.com
Tue Apr 2 18:07:00 GMT 2002
tested x86/linux
gcc
gcc-3_1-branch
2002-04-02 Benjamin Kosnik <bkoz@redhat.com>
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.
Index: include/bits/basic_ios.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.h,v
retrieving revision 1.12
diff -c -p -r1.12 basic_ios.h
*** basic_ios.h 2002/04/01 18:39:36 1.12
--- basic_ios.h 2002/04/03 01:57:29
*************** namespace std
*** 69,85 ****
basic_streambuf<_CharT, _Traits>* _M_streambuf;
// Cached use_facet<ctype>, which is based on the current locale info.
! const __ctype_type* _M_ios_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<basic_ios*>(this); }
--- 69,81 ----
basic_streambuf<_CharT, _Traits>* _M_streambuf;
// Cached use_facet<ctype>, which is based on the current locale info.
! const __ctype_type* _M_fctype;
// From ostream.
const __numput_type* _M_fnumput;
// From istream.
const __numget_type* _M_fnumget;
public:
operator void*() const
{ return this->fail() ? 0 : const_cast<basic_ios*>(this); }
Index: include/bits/basic_ios.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.tcc,v
retrieving revision 1.14
diff -c -p -r1.14 basic_ios.tcc
*** basic_ios.tcc 2002/04/01 18:39:36 1.14
--- basic_ios.tcc 2002/04/03 01:57:29
*************** namespace std
*** 67,78 ****
_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)
--- 67,72 ----
*************** namespace std
*** 113,120 ****
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);
return __ret;
}
--- 107,114 ----
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
{
char __ret = __dfault;
! if (_M_check_facet(_M_fctype))
! __ret = _M_fctype->narrow(__c, __dfault);
return __ret;
}
*************** namespace std
*** 123,130 ****
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);
return __ret;
}
--- 117,124 ----
basic_ios<_CharT, _Traits>::widen(char __c) const
{
char_type __ret = char_type();
! if (_M_check_facet(_M_fctype))
! __ret = _M_fctype->widen(__c);
return __ret;
}
*************** namespace std
*** 175,183 ****
basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc)
{
if (has_facet<__ctype_type>(__loc))
! _M_ios_fctype = &use_facet<__ctype_type>(__loc);
else
! _M_ios_fctype = 0;
// Should be filled in by ostream and istream, respectively.
if (has_facet<__numput_type>(__loc))
_M_fnumput = &use_facet<__numput_type>(__loc);
--- 169,177 ----
basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc)
{
if (has_facet<__ctype_type>(__loc))
! _M_fctype = &use_facet<__ctype_type>(__loc);
else
! _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);
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.24
diff -c -p -r1.24 istream.tcc
*** istream.tcc 2002/02/16 19:33:43 1.24
--- istream.tcc 2002/04/03 01:57:31
*************** namespace std
*** 50,61 ****
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();
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
//195. Should basic_istream::sentry's constructor ever set eofbit?
--- 50,62 ----
if (!__noskipws && (__in.flags() & ios_base::skipws))
{
const __int_type __eof = traits_type::eof();
__streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc();
!
! 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?
*************** namespace std
*** 1098,1109 ****
if (__num == 0)
__num = numeric_limits<streamsize>::max();
__streambuf_type* __sb = __in.rdbuf();
- const __ctype_type* __ctype = __in._M_get_fctype_ios();
int_type __c = __sb->sbumpc();
- const int_type __eof = _Traits::eof();
- bool __testsp = __ctype->is(ctype_base::space, __c);
bool __testeof = __c == __eof;
while (__extracted < __num - 1 && !__testeof && !__testsp)
{
--- 1099,1110 ----
if (__num == 0)
__num = numeric_limits<streamsize>::max();
+ const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
+ const int_type __eof = _Traits::eof();
__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)
{
*************** namespace std
*** 1111,1117 ****
++__extracted;
__c = __sb->sbumpc();
__testeof = __c == __eof;
! __testsp = __ctype->is(ctype_base::space, __c);
}
if (!__testeof)
--- 1112,1118 ----
++__extracted;
__c = __sb->sbumpc();
__testeof = __c == __eof;
! __testsp = __ctype.is(ctype_base::space, __c);
}
if (!__testeof)
*************** namespace std
*** 1150,1157 ****
typedef typename __istream_type::int_type __int_type;
typedef typename __istream_type::char_type __char_type;
__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;
--- 1151,1158 ----
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 __int_type __eof = _Traits::eof();
__int_type __c;
bool __testeof;
*************** namespace std
*** 1160,1167 ****
do
{
__c = __sb->sbumpc();
! __testeof = __c == __eof;
! __testsp = __ctype->is(ctype_base::space, __c);
}
while (!__testeof && __testsp);
--- 1161,1168 ----
do
{
__c = __sb->sbumpc();
! __testeof = __c == __eof;
! __testsp = __ctype.is(ctype_base::space, __c);
}
while (!__testeof && __testsp);
*************** namespace std
*** 1195,1206 ****
__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 __int_type __eof = _Traits::eof();
- bool __testsp = __ctype->is(ctype_base::space, __c);
bool __testeof = __c == __eof;
while (__extracted < __n && !__testeof && !__testsp)
{
--- 1196,1207 ----
__size_type __n;
__n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
+ const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
+ const __int_type __eof = _Traits::eof();
__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)
{
*************** namespace std
*** 1208,1214 ****
++__extracted;
__c = __sb->sbumpc();
__testeof = __c == __eof;
! __testsp = __ctype->is(ctype_base::space, __c);
}
if (!__testeof)
__sb->sputbackc(__c);
--- 1209,1215 ----
++__extracted;
__c = __sb->sbumpc();
__testeof = __c == __eof;
! __testsp = __ctype.is(ctype_base::space, __c);
}
if (!__testeof)
__sb->sputbackc(__c);
Index: src/ios.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/ios.cc,v
retrieving revision 1.26
diff -c -p -r1.26 ios.cc
*** ios.cc 2002/04/01 18:39:37 1.26
--- ios.cc 2002/04/03 01:57:34
*************** namespace std
*** 190,205 ****
// 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();
--- 190,199 ----
Index: testsuite/27_io/ios_init.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ios_init.cc,v
retrieving revision 1.7
diff -c -p -r1.7 ios_init.cc
*** ios_init.cc 2002/03/11 21:08:06 1.7
--- ios_init.cc 2002/04/03 01:57:38
*************** void test02()
*** 132,137 ****
--- 132,211 ----
VERIFY( test );
}
+ // libstdc++/3983
+ void test03()
+ {
+ using namespace std;
+ bool test = true;
+
+ // input streams
+ basic_istringstream<unsigned char> 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<unsigned char> s_uc(arr);
+ iss_uc >> s_uc;
+ }
+ catch (bad_cast& obj)
+ { }
+ catch (exception& obj)
+ { test = false; }
+
+ // output streams
+ basic_ostringstream<unsigned char> 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
*************** int main()
*** 147,151 ****
--- 221,227 ----
{
test01();
test02();
+ test03();
+ test04();
return 0;
}
More information about the Gcc-patches
mailing list