This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] cache codecvt in basic_filebuf


tested x86/linux

2003-05-12  Benjamin Kosnik  <bkoz@redhat.com>

	* include/std/std_fstream.h (basic_filebuf::_M_codecvt): Add
	cached member.
	* include/bits/fstream.tcc (basic_filebuf::basic_filebuf):
	Initialize _M_codecvt.
	(basic_filebuf::imbue): Same.
	(basic_filebuf::showmanyc): Use it.
	(basic_filebuf::underflow): Use it.
	(basic_filebuf::_M_convert_to_external): Use it.
	(basic_filebuf::seekoff): Use it.
	(basic_filebuf::imbue): Use it, tweaks.
	* include/bits/localefwd.h (__check_facet): New.
	* include/bits/locale_classes.h: Tweaks.
	* include/bits/locale_facets.tcc: Tweaks.	
	* include/bits/basic_ios.h (basic_ios::_M_check_facet): Remove.
	_M_fctype to _M_ctype, _M_fnumput to _M_num_put, _M_fnumget to
	_M_num_get. Change _M_check_facet to __check_facet. Tweaks.
	* include/bits/basic_ios.tcc: Same.	
	* include/bits/istream.tcc: Same.
	* include/bits/ostream.tcc: Same.
	* include/std/std_streambuf.h: Same.
	* testsuite/27_io/basic_filebuf/imbue/char/2.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/char/3.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc: New.

Index: include/bits/basic_ios.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.h,v
retrieving revision 1.20
diff -c -p -r1.20 basic_ios.h
*** include/bits/basic_ios.h	7 May 2003 05:01:57 -0000	1.20
--- include/bits/basic_ios.h	13 May 2003 19:52:37 -0000
*************** namespace std 
*** 90,100 ****
        basic_streambuf<_CharT, _Traits>*              _M_streambuf;
  
        // Cached use_facet<ctype>, which is based on the current locale info.
!       const __ctype_type*                            _M_fctype;      
        // For ostream.
!       const __numput_type*                           _M_fnumput;
        // For istream.
!       const __numget_type*                           _M_fnumget;
  
      public:
        //@{
--- 90,100 ----
        basic_streambuf<_CharT, _Traits>*              _M_streambuf;
  
        // Cached use_facet<ctype>, which is based on the current locale info.
!       const __ctype_type*                            _M_ctype;      
        // For ostream.
!       const __numput_type*                           _M_num_put;
        // For istream.
!       const __numget_type*                           _M_num_get;
  
      public:
        //@{
*************** namespace std 
*** 241,247 ****
        */
        explicit 
        basic_ios(basic_streambuf<_CharT, _Traits>* __sb) 
!       : ios_base(), _M_fctype(0), _M_fnumput(0), _M_fnumget(0)
        { this->init(__sb); }
  
        /**
--- 241,247 ----
        */
        explicit 
        basic_ios(basic_streambuf<_CharT, _Traits>* __sb) 
!       : ios_base(), _M_ctype(0), _M_num_put(0), _M_num_get(0)
        { this->init(__sb); }
  
        /**
*************** namespace std 
*** 419,425 ****
         *  The default constructor does nothing and is not normally
         *  accessible to users.
        */
!       basic_ios() : ios_base(), _M_fctype(0), _M_fnumput(0), _M_fnumget(0)
        { }
  
        /**
--- 419,425 ----
         *  The default constructor does nothing and is not normally
         *  accessible to users.
        */
!       basic_ios() : ios_base(), _M_ctype(0), _M_num_put(0), _M_num_get(0)
        { }
  
        /**
*************** namespace std 
*** 430,443 ****
        */
        void 
        init(basic_streambuf<_CharT, _Traits>* __sb);
- 
-       bool
-       _M_check_facet(const locale::facet* __f) const
-       {
- 	if (!__f)
- 	  __throw_bad_cast();
- 	return true;
-       }
  
        void
        _M_cache_locale(const locale& __loc);
--- 430,435 ----
Index: include/bits/basic_ios.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.tcc,v
retrieving revision 1.20
diff -c -p -r1.20 basic_ios.tcc
*** include/bits/basic_ios.tcc	28 Apr 2003 23:05:57 -0000	1.20
--- include/bits/basic_ios.tcc	13 May 2003 19:52:37 -0000
*************** namespace std
*** 110,131 ****
    template<typename _CharT, typename _Traits>
      char
      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;
!     }
  
    template<typename _CharT, typename _Traits>
      _CharT
      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;
!     }
  
    // Locales:
    template<typename _CharT, typename _Traits>
--- 110,121 ----
    template<typename _CharT, typename _Traits>
      char
      basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
!     { return __check_facet(_M_ctype).narrow(__c, __dfault); }
  
    template<typename _CharT, typename _Traits>
      _CharT
      basic_ios<_CharT, _Traits>::widen(char __c) const
!     { return __check_facet(_M_ctype).widen(__c); }
  
    // Locales:
    template<typename _CharT, typename _Traits>
*************** namespace std
*** 181,191 ****
      basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
      {
        if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
! 	_M_fctype = &use_facet<__ctype_type>(__loc);
        if (__builtin_expect(has_facet<__numput_type>(__loc), true))
! 	_M_fnumput = &use_facet<__numput_type>(__loc); 
        if (__builtin_expect(has_facet<__numget_type>(__loc), true))
! 	_M_fnumget = &use_facet<__numget_type>(__loc); 
        static_cast<__locale_cache<_CharT>&>(_M_cache())._M_init(__loc); 
      }
  
--- 171,181 ----
      basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
      {
        if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
! 	_M_ctype = &use_facet<__ctype_type>(__loc);
        if (__builtin_expect(has_facet<__numput_type>(__loc), true))
! 	_M_num_put = &use_facet<__numput_type>(__loc); 
        if (__builtin_expect(has_facet<__numget_type>(__loc), true))
! 	_M_num_get = &use_facet<__numget_type>(__loc); 
        static_cast<__locale_cache<_CharT>&>(_M_cache())._M_init(__loc); 
      }
  
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.74
diff -c -p -r1.74 fstream.tcc
*** include/bits/fstream.tcc	12 May 2003 18:12:27 -0000	1.74
--- include/bits/fstream.tcc	13 May 2003 19:52:37 -0000
*************** namespace std
*** 78,85 ****
      _M_state_cur(__state_type()), _M_state_beg(__state_type()), 
      _M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_allocated(false),
      _M_last_overflowed(false), _M_pback_cur_save(0),
!     _M_pback_end_save(0), _M_pback_init(false)
!     { this->_M_buf_unified = true; }
  
    template<typename _CharT, typename _Traits>
      typename basic_filebuf<_CharT, _Traits>::__filebuf_type* 
--- 78,90 ----
      _M_state_cur(__state_type()), _M_state_beg(__state_type()), 
      _M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_allocated(false),
      _M_last_overflowed(false), _M_pback_cur_save(0),
!     _M_pback_end_save(0), _M_pback_init(false), _M_codecvt(0)
!     { 
!       this->_M_buf_unified = true; 	  
!       if (__builtin_expect(has_facet<__codecvt_type>(this->_M_buf_locale), 
! 			                             true))
! 	_M_codecvt = &use_facet<__codecvt_type>(this->_M_buf_locale);
!     }
  
    template<typename _CharT, typename _Traits>
      typename basic_filebuf<_CharT, _Traits>::__filebuf_type* 
*************** namespace std
*** 163,179 ****
      {
        streamsize __ret = -1;
        const bool __testin = this->_M_mode & ios_base::in;
-       const locale __loc = this->getloc();
-       const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
  
        if (__testin && this->is_open())
  	{
- 	  __ret = this->_M_in_end - this->_M_in_cur;
- 
  	  // For a stateful encoding (-1) the pending sequence might be just
  	  // shift and unshift prefixes with no actual character.
! 	  if (__cvt.encoding() >= 0)
! 	    __ret += _M_file.showmanyc() / __cvt.max_length();
  	}
  
        _M_last_overflowed = false;	
--- 168,181 ----
      {
        streamsize __ret = -1;
        const bool __testin = this->_M_mode & ios_base::in;
  
        if (__testin && this->is_open())
  	{
  	  // For a stateful encoding (-1) the pending sequence might be just
  	  // shift and unshift prefixes with no actual character.
! 	  __ret = this->_M_in_end - this->_M_in_cur;
! 	  if (__check_facet(_M_codecvt).encoding() >= 0)
! 	    __ret += _M_file.showmanyc() / _M_codecvt->max_length();
  	}
  
        _M_last_overflowed = false;	
*************** namespace std
*** 220,228 ****
  	    {
  	      streamsize __elen = 0;
  	      streamsize __ilen = 0;
! 	      const locale __loc = this->getloc();
! 	      const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
! 	      if (__cvt.always_noconv())
  		{
  		  __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), _M_buf_size);
  		  __ilen = __elen;
--- 222,229 ----
  	    {
  	      streamsize __elen = 0;
  	      streamsize __ilen = 0;
! 
! 	      if (__check_facet(_M_codecvt).always_noconv())
  		{
  		  __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), _M_buf_size);
  		  __ilen = __elen;
*************** namespace std
*** 235,243 ****
  		  const char* __eend;
  		  char_type* __iend;
  		  codecvt_base::result __r;
! 		  __r = __cvt.in(_M_state_cur, __buf, __buf + __elen, __eend, 
! 				 this->_M_in_beg, 
! 				 this->_M_in_beg + _M_buf_size, __iend);
  		  if (__r == codecvt_base::ok)
  		    __ilen = __iend - this->_M_in_beg;
  		  else if (__r == codecvt_base::noconv)
--- 236,244 ----
  		  const char* __eend;
  		  char_type* __iend;
  		  codecvt_base::result __r;
! 		  __r = _M_codecvt->in(_M_state_cur, __buf, __buf + __elen, 
! 				       __eend, this->_M_in_beg, 
! 				       this->_M_in_beg + _M_buf_size, __iend);
  		  if (__r == codecvt_base::ok)
  		    __ilen = __iend - this->_M_in_beg;
  		  else if (__r == codecvt_base::noconv)
*************** namespace std
*** 400,406 ****
  	  else 
  	    __ret = this->_M_overflow(__c);
  	}
- 
        _M_last_overflowed = false;    // Set in _M_overflow, below.
        return __ret;
      }
--- 401,406 ----
*************** namespace std
*** 414,422 ****
        streamsize __elen = 0;
        streamsize __plen = 0;
  
!       const locale __loc = this->getloc();
!       const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
!       if (__cvt.always_noconv() && __ilen)
  	{
  	  __elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
  	  __plen += __ilen;
--- 414,420 ----
        streamsize __elen = 0;
        streamsize __plen = 0;
  
!       if (__check_facet(_M_codecvt).always_noconv() && __ilen)
  	{
  	  __elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
  	  __plen += __ilen;
*************** namespace std
*** 424,430 ****
        else
  	{
  	  // Worst-case number of external bytes needed.
! 	  int __ext_multiplier = __cvt.encoding();
  	  if (__ext_multiplier ==  -1 || __ext_multiplier == 0)
  	    __ext_multiplier = sizeof(char_type);
  	  streamsize __blen = __ilen * __ext_multiplier;
--- 422,428 ----
        else
  	{
  	  // Worst-case number of external bytes needed.
! 	  int __ext_multiplier = _M_codecvt->encoding();
  	  if (__ext_multiplier ==  -1 || __ext_multiplier == 0)
  	    __ext_multiplier = sizeof(char_type);
  	  streamsize __blen = __ilen * __ext_multiplier;
*************** namespace std
*** 432,439 ****
  	  char* __bend;
  	  const char_type* __iend;
  	  codecvt_base::result __r;
! 	  __r = __cvt.out(_M_state_cur, __ibuf, __ibuf + __ilen,
! 			  __iend, __buf, __buf + __blen, __bend);
  	  
  	  if (__r == codecvt_base::ok || __r == codecvt_base::partial)
  	    __blen = __bend - __buf;
--- 430,437 ----
  	  char* __bend;
  	  const char_type* __iend;
  	  codecvt_base::result __r;
! 	  __r = _M_codecvt->out(_M_state_cur, __ibuf, __ibuf + __ilen,
! 				__iend, __buf, __buf + __blen, __bend);
  	  
  	  if (__r == codecvt_base::ok || __r == codecvt_base::partial)
  	    __blen = __bend - __buf;
*************** namespace std
*** 460,467 ****
  	    {
  	      const char_type* __iresume = __iend;
  	      streamsize __rlen = this->_M_out_lim - __iend;
! 	      __r = __cvt.out(_M_state_cur, __iresume, __iresume + __rlen, 
! 			      __iend, __buf, __buf + __blen, __bend);
  	      if (__r != codecvt_base::error)
  		{
  		  __rlen = __bend - __buf;
--- 458,466 ----
  	    {
  	      const char_type* __iresume = __iend;
  	      streamsize __rlen = this->_M_out_lim - __iend;
! 	      __r = _M_codecvt->out(_M_state_cur, __iresume,
! 				    __iresume + __rlen, __iend, __buf, 
! 				    __buf + __blen, __bend);
  	      if (__r != codecvt_base::error)
  		{
  		  __rlen = __bend - __buf;
*************** namespace std
*** 470,476 ****
  		}
  	    }
  	}
- 
        return __elen && __elen == __plen;
      }
  
--- 469,474 ----
*************** namespace std
*** 510,517 ****
        const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
        
        int __width = 0;
!       if (has_facet<__codecvt_type>(this->_M_buf_locale))
! 	  __width = use_facet<__codecvt_type>(this->_M_buf_locale).encoding();
        if (__width < 0)
  	__width = 0;
  
--- 508,515 ----
        const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
        
        int __width = 0;
!       if (_M_codecvt)
! 	  __width = _M_codecvt->encoding();
        if (__width < 0)
  	__width = 0;
  
*************** namespace std
*** 523,542 ****
  
  	  if (__way != ios_base::cur || __off != 0)
  	    { 
! 	      off_type __computed_off = __width * __off;
! 	      
  	      const bool __testget = this->_M_in_beg < this->_M_in_end;
  	      const bool __testput = this->_M_out_beg < this->_M_out_lim;
! 	      // Sync the internal and external streams.
! 	      // out
  	      if (__testput || _M_last_overflowed)
  		{
  		  // Part one: update the output sequence.
  		  this->sync();
  		  // Part two: output unshift sequence.
  		  _M_output_unshift();
  		}
- 	      //in
  	      else if (__testget && __way == ios_base::cur)
  		__computed_off += this->_M_in_cur - _M_filepos;
  
--- 521,539 ----
  
  	  if (__way != ios_base::cur || __off != 0)
  	    { 
! 	      // Sync the internal and external streams.	      
  	      const bool __testget = this->_M_in_beg < this->_M_in_end;
  	      const bool __testput = this->_M_out_beg < this->_M_out_lim;
! 	      off_type __computed_off = __width * __off;
! 
  	      if (__testput || _M_last_overflowed)
  		{
  		  // Part one: update the output sequence.
  		  this->sync();
+ 
  		  // Part two: output unshift sequence.
  		  _M_output_unshift();
  		}
  	      else if (__testget && __way == ios_base::cur)
  		__computed_off += this->_M_in_cur - _M_filepos;
  
*************** namespace std
*** 544,553 ****
  	      __ret = _M_file.seekoff(__computed_off, __way, __mode);
  	      _M_set_indeterminate();
  	    }
- 	  // NB: Need to do this in case _M_file in indeterminate
- 	  // state, ie _M_file._offset == -1
  	  else
  	    {
  	      pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, __mode);
  	      if (__tmp >= 0)
  		{
--- 541,550 ----
  	      __ret = _M_file.seekoff(__computed_off, __way, __mode);
  	      _M_set_indeterminate();
  	    }
  	  else
  	    {
+ 	      // NB: Need to do this in case _M_file in indeterminate
+ 	      // state, ie _M_file._offset == -1
  	      pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, __mode);
  	      if (__tmp >= 0)
  		{
*************** namespace std
*** 584,599 ****
      basic_filebuf<_CharT, _Traits>::
      imbue(const locale& __loc)
      {
!       const bool __testbeg = this->_M_in_cur == this->_M_in_beg
! 	                     && this->_M_out_cur == this->_M_out_beg;
  
!       if (__testbeg && this->_M_buf_locale != __loc)
! 	this->_M_buf_locale = __loc;
! 
!       // NB this may require the reconversion of previously
!       // converted chars. This in turn may cause the reconstruction
!       // of the original file. YIKES!!
!       // XXX The part in the above comment is not done.
        _M_last_overflowed = false;	
      }
  
--- 581,603 ----
      basic_filebuf<_CharT, _Traits>::
      imbue(const locale& __loc)
      {
!       const bool __testbeg = !this->seekoff(0, ios_base::cur, this->_M_mode);
!       const bool __teststate = __check_facet(_M_codecvt).encoding() == -1;
  
!       if (this->_M_buf_locale != __loc 
! 	  && (!this->is_open() || (__testbeg && !__teststate)))
! 	{
! 	  this->_M_buf_locale = __loc;
! 	  if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
! 	    _M_codecvt = &use_facet<__codecvt_type>(__loc);
! 
! 	  // NB This may require the reconversion of previously
! 	  // converted chars. This in turn may cause the
! 	  // reconstruction of the original file. YIKES!!  This
! 	  // implementation interprets this requirement as requiring
! 	  // the file position be at the beginning, and a stateless
! 	  // encoding, or that the filebuf be closed. Opinions may differ.
! 	}
        _M_last_overflowed = false;	
      }
  
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.45
diff -c -p -r1.45 istream.tcc
*** include/bits/istream.tcc	23 Apr 2003 07:21:27 -0000	1.45
--- include/bits/istream.tcc	13 May 2003 19:52:39 -0000
*************** namespace std 
*** 53,62 ****
  	      __streambuf_type* __sb = __in.rdbuf();
  	      __int_type __c = __sb->sgetc();
  
! 	      if (__in._M_check_facet(__in._M_fctype))
! 		while (!traits_type::eq_int_type(__c, __eof)
! 		       && __in._M_fctype->is(ctype_base::space, 
! 					     traits_type::to_char_type(__c)))
  		  __c = __sb->snextc();
  
  #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
--- 53,62 ----
  	      __streambuf_type* __sb = __in.rdbuf();
  	      __int_type __c = __sb->sgetc();
  
! 	      __check_facet(__in._M_ctype);
! 	      while (!traits_type::eq_int_type(__c, __eof)
! 		     && __in._M_ctype->is(ctype_base::space, 
! 					  traits_type::to_char_type(__c)))
  		  __c = __sb->snextc();
  
  #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
*************** namespace std 
*** 114,121 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 114,120 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 142,149 ****
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
  	      long __l;
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __l);
  #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
  	      // 118. basic_istream uses nonexistent num_get member functions.
  	      if (!(__err & ios_base::failbit)
--- 141,147 ----
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
  	      long __l;
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __l);
  #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
  	      // 118. basic_istream uses nonexistent num_get member functions.
  	      if (!(__err & ios_base::failbit)
*************** namespace std 
*** 178,185 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 176,182 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 206,213 ****
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
  	      long __l;
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __l);
  #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
  	      // 118. basic_istream uses nonexistent num_get member functions.
  	      if (!(__err & ios_base::failbit)
--- 203,209 ----
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
  	      long __l;
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __l);
  #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
  	      // 118. basic_istream uses nonexistent num_get member functions.
  	      if (!(__err & ios_base::failbit)
*************** namespace std 
*** 242,249 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 238,244 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 269,276 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 264,270 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 296,303 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 290,296 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 324,331 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 317,323 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 351,358 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 343,349 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 379,386 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 370,376 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 406,413 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 396,402 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 433,440 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 422,428 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
*************** namespace std 
*** 460,467 ****
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      if (_M_check_facet(this->_M_fnumget))
! 		this->_M_fnumget->get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
--- 448,454 ----
  	  try 
  	    {
  	      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	      __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
  	      this->setstate(__err);
  	    }
  	  catch(...)
Index: include/bits/locale_classes.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_classes.h,v
retrieving revision 1.5
diff -c -p -r1.5 locale_classes.h
*** include/bits/locale_classes.h	28 Apr 2003 03:41:49 -0000	1.5
--- include/bits/locale_classes.h	13 May 2003 19:52:40 -0000
*************** namespace std
*** 65,77 ****
      friend class _Impl;
  
      template<typename _Facet>
-       friend const _Facet& 
-       use_facet(const locale&);
-     
-     template<typename _Facet>
        friend bool 
        has_facet(const locale&) throw();
!  
      // Category values:
      // NB: Order must match _S_facet_categories definition in locale.cc
      static const category none		= 0;
--- 65,77 ----
      friend class _Impl;
  
      template<typename _Facet>
        friend bool 
        has_facet(const locale&) throw();
! 
!     template<typename _Facet>
!       friend const _Facet& 
!       use_facet(const locale&);
!      
      // Category values:
      // NB: Order must match _S_facet_categories definition in locale.cc
      static const category none		= 0;
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.97
diff -c -p -r1.97 locale_facets.tcc
*** include/bits/locale_facets.tcc	7 May 2003 05:01:57 -0000	1.97
--- include/bits/locale_facets.tcc	13 May 2003 19:52:42 -0000
*************** namespace std
*** 67,89 ****
      }
  
    template<typename _Facet>
!     const _Facet&
!     use_facet(const locale& __loc)
      {
        size_t __i = _Facet::id._M_id();
        const locale::facet** __facets = __loc._M_impl->_M_facets;
!       if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
!         __throw_bad_cast();
!       return static_cast<const _Facet&>(*__facets[__i]);
      }
  
    template<typename _Facet>
!     bool
!     has_facet(const locale& __loc) throw()
      {
        size_t __i = _Facet::id._M_id();
        const locale::facet** __facets = __loc._M_impl->_M_facets;
!       return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
      }
  
  
--- 67,89 ----
      }
  
    template<typename _Facet>
!     inline bool
!     has_facet(const locale& __loc) throw()
      {
        size_t __i = _Facet::id._M_id();
        const locale::facet** __facets = __loc._M_impl->_M_facets;
!       return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
      }
  
    template<typename _Facet>
!     inline const _Facet&
!     use_facet(const locale& __loc)
      {
        size_t __i = _Facet::id._M_id();
        const locale::facet** __facets = __loc._M_impl->_M_facets;
!       if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
!         __throw_bad_cast();
!       return static_cast<const _Facet&>(*__facets[__i]);
      }
  
  
Index: include/bits/localefwd.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/localefwd.h,v
retrieving revision 1.33
diff -c -p -r1.33 localefwd.h
*** include/bits/localefwd.h	22 Jan 2003 16:51:51 -0000	1.33
--- include/bits/localefwd.h	13 May 2003 19:52:42 -0000
*************** namespace std
*** 172,183 ****
      class messages_byname;
  
    template<typename _Facet>
      const _Facet&
      use_facet(const locale& __loc);
  
    template<typename _Facet>
!     bool
!     has_facet(const locale& __loc) throw();
  } // namespace std
  
  #endif
--- 172,192 ----
      class messages_byname;
  
    template<typename _Facet>
+     bool
+     has_facet(const locale& __loc) throw();
+ 
+   template<typename _Facet>
      const _Facet&
      use_facet(const locale& __loc);
  
    template<typename _Facet>
!     inline const _Facet&
!     __check_facet(const _Facet* __f)
!     { 
!       if (!__f)
! 	__throw_bad_cast(); 
!       return *__f;
!     }
  } // namespace std
  
  #endif
Index: include/bits/ostream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.38
diff -c -p -r1.38 ostream.tcc
*** include/bits/ostream.tcc	18 Apr 2003 03:46:43 -0000	1.38
--- include/bits/ostream.tcc	13 May 2003 19:52:43 -0000
*************** namespace std 
*** 157,166 ****
  	{
  	  try 
  	    {
! 	      if (_M_check_facet(this->_M_fnumput))
! 		if (this->_M_fnumput->put(*this, *this, 
! 					  this->fill(), __n).failed())
! 		  this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
--- 157,166 ----
  	{
  	  try 
  	    {
! 	      __check_facet(this->_M_num_put);
! 	      if (this->_M_num_put->put(*this, *this, this->fill(), 
! 					__n).failed())
! 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 183,205 ****
  	{
  	  try 
  	    {
  	      char_type __c = this->fill();
  	      ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
! 	      if (_M_check_facet(this->_M_fnumput))
  		{
! 		  bool __b = false;
! 		  if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
! 		    {
! 		      unsigned long __l = static_cast<unsigned long>(__n);
! 		      __b = this->_M_fnumput->put(*this, *this, 
! 						  __c, __l).failed();
! 		    }
! 		  else
! 		    __b = this->_M_fnumput->put(*this, *this,
! 						__c, __n).failed();
! 		  if (__b)  
! 		    this->setstate(ios_base::badbit);
  		}
  	    }
  	  catch(...)
  	    {
--- 183,201 ----
  	{
  	  try 
  	    {
+ 	      bool __b = false;
  	      char_type __c = this->fill();
  	      ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
! 	      __check_facet(this->_M_num_put);
! 	      if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
  		{
! 		  unsigned long __l = static_cast<unsigned long>(__n);
! 		  __b = this->_M_num_put->put(*this, *this, __c, __l).failed();
  		}
+ 	      else
+ 		__b = this->_M_num_put->put(*this, *this, __c, __n).failed();
+ 	      if (__b)  
+ 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 222,231 ****
  	{
  	  try 
  	    {
! 	      if (_M_check_facet(this->_M_fnumput))
! 		if (this->_M_fnumput->put(*this, *this, 
! 					  this->fill(), __n).failed())
! 		  this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
--- 218,227 ----
  	{
  	  try 
  	    {
! 	      __check_facet(this->_M_num_put);
! 	      if (this->_M_num_put->put(*this, *this, this->fill(), 
! 					__n).failed())
! 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 249,272 ****
  	{
  	  try 
  	    {
  	      char_type __c = this->fill();
  	      ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
! 	      if (_M_check_facet(this->_M_fnumput))
  		{
! 		  bool __b = false;
! 		  if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
! 		    {
! 		      unsigned long long __l;
! 		      __l = static_cast<unsigned long long>(__n);
! 		      __b = this->_M_fnumput->put(*this, *this,
! 						  __c, __l).failed();
! 		    }
! 		  else
! 		    __b = this->_M_fnumput->put(*this, *this,
! 						__c, __n).failed();
! 		  if (__b)  
! 		    this->setstate(ios_base::badbit);
  		}
  	    }
  	  catch(...)
  	    {
--- 245,264 ----
  	{
  	  try 
  	    {
+ 	      bool __b = false;
  	      char_type __c = this->fill();
  	      ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
! 	      __check_facet(this->_M_num_put);
! 	      if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
  		{
! 		  unsigned long long __l;
! 		  __l = static_cast<unsigned long long>(__n);
! 		  __b = this->_M_num_put->put(*this, *this, __c, __l).failed();
  		}
+ 	      else
+ 		__b = this->_M_num_put->put(*this, *this, __c, __n).failed();
+ 	      if (__b)  
+ 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 289,298 ****
  	{
  	  try 
  	    {
! 	      if (_M_check_facet(this->_M_fnumput))
! 		if (this->_M_fnumput->put(*this, *this, 
! 					  this->fill(), __n).failed())
! 		  this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
--- 281,290 ----
  	{
  	  try 
  	    {
! 	      __check_facet(this->_M_num_put);
! 	      if (this->_M_num_put->put(*this, *this, this->fill(), 
! 					__n).failed())
! 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 316,325 ****
  	{
  	  try 
  	    {
! 	      if (_M_check_facet(this->_M_fnumput))
! 		if (this->_M_fnumput->put(*this, *this, 
! 					  this->fill(), __n).failed())
! 		  this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
--- 308,317 ----
  	{
  	  try 
  	    {
! 	      __check_facet(this->_M_num_put);
! 	      if (this->_M_num_put->put(*this, *this, this->fill(), 
! 					__n).failed())
! 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 342,351 ****
  	{
  	  try 
  	    {
! 	      if (_M_check_facet(this->_M_fnumput))
! 		if (this->_M_fnumput->put(*this, *this, 
! 					  this->fill(), __n).failed())
! 		  this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
--- 334,343 ----
  	{
  	  try 
  	    {
! 	      __check_facet(this->_M_num_put);
! 	      if (this->_M_num_put->put(*this, *this, this->fill(), 
! 					__n).failed())
! 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
*************** namespace std 
*** 368,377 ****
  	{
  	  try 
  	    {
! 	      if (_M_check_facet(this->_M_fnumput))
! 		if (this->_M_fnumput->put(*this, *this, 
! 					  this->fill(), __n).failed())
! 		  this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
--- 360,369 ----
  	{
  	  try 
  	    {
! 	      __check_facet(this->_M_num_put);
! 	      if (this->_M_num_put->put(*this, *this, this->fill(), 
! 					__n).failed())
! 		this->setstate(ios_base::badbit);
  	    }
  	  catch(...)
  	    {
Index: include/std/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_fstream.h,v
retrieving revision 1.36
diff -c -p -r1.36 std_fstream.h
*** include/std/std_fstream.h	12 May 2003 18:12:27 -0000	1.36
--- include/std/std_fstream.h	13 May 2003 19:52:45 -0000
*************** namespace std
*** 163,168 ****
--- 163,171 ----
        bool			_M_pback_init; 
        //@}
  
+       // Cached codecvt facet.
+       const __codecvt_type* 	_M_codecvt;
+ 
        // Initializes pback buffers, and moves normal buffers to safety.
        // Assumptions:
        // _M_in_cur has already been moved back
*************** namespace std
*** 403,409 ****
  	  }
  	else
  	  _M_file.sync();
- 
  	_M_last_overflowed = false;
  	return __ret;
        }
--- 406,411 ----
Index: include/std/std_streambuf.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_streambuf.h,v
retrieving revision 1.28
diff -c -p -r1.28 std_streambuf.h
*** include/std/std_streambuf.h	8 May 2003 11:47:45 -0000	1.28
--- include/std/std_streambuf.h	13 May 2003 19:52:45 -0000
*************** namespace std
*** 343,351 ****
        int_type 
        snextc()
        {
! 	int_type __eof = traits_type::eof();
! 	return (traits_type::eq_int_type(this->sbumpc(), __eof) 
! 		? __eof : this->sgetc());
        }
  
        /**
--- 343,352 ----
        int_type 
        snextc()
        {
! 	int_type __ret = traits_type::eof();
! 	if (!traits_type::eq_int_type(this->sbumpc(), __ret))
! 	  __ret = this->sgetc();
! 	return __ret;
        }
  
        /**
*************** namespace std
*** 699,706 ****
        uflow() 
        {
  	int_type __ret = traits_type::eof();
! 	const bool __testeof =
! 	  traits_type::eq_int_type(this->underflow(), __ret);
  	if (!__testeof && _M_in_cur < _M_in_end)
  	  {
  	    __ret = traits_type::to_int_type(*_M_in_cur);
--- 700,707 ----
        uflow() 
        {
  	int_type __ret = traits_type::eof();
! 	const bool __testeof = traits_type::eq_int_type(this->underflow(), 
! 							__ret);
  	if (!__testeof && _M_in_cur < _M_in_end)
  	  {
  	    __ret = traits_type::to_int_type(*_M_in_cur);
Index: testsuite/27_io/basic_filebuf/imbue/char/2.cc
===================================================================
RCS file: testsuite/27_io/basic_filebuf/imbue/char/2.cc
diff -N testsuite/27_io/basic_filebuf/imbue/char/2.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/basic_filebuf/imbue/char/2.cc	13 May 2003 19:52:47 -0000
***************
*** 0 ****
--- 1,54 ----
+ // 2003-05-13 Benjamin Kosnik  <bkoz@redhat.com>
+ 
+ // Copyright (C) 2003 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.8.1.4 Overridden virtual functions
+ 
+ #include <fstream>
+ #include <locale>
+ #include <testsuite_hooks.h>
+ 
+ void test02()
+ {
+   using namespace std;
+   bool test = true;
+   const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
+ 
+   locale loc;
+   filebuf ob;
+   VERIFY( ob.getloc() == loc );
+   ob.open(name_01, ios_base::in);
+   VERIFY( ob.is_open() );
+  
+   typedef streambuf::pos_type pos_type;
+   pos_type bad = pos_type(streambuf::off_type(-1));
+   pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
+   VERIFY( p != bad);
+ 
+   // 1 "if file is not positioned at its beginning" fails...
+   locale loc_de = __gnu_cxx_test::try_named_locale("de_DE");
+   locale ret = ob.pubimbue(loc_de);
+   VERIFY( ob.getloc() == loc );
+ }
+ 
+ main() 
+ {
+   test02();
+   return 0;
+ }
Index: testsuite/27_io/basic_filebuf/imbue/char/3.cc
===================================================================
RCS file: testsuite/27_io/basic_filebuf/imbue/char/3.cc
diff -N testsuite/27_io/basic_filebuf/imbue/char/3.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/basic_filebuf/imbue/char/3.cc	13 May 2003 19:52:47 -0000
***************
*** 0 ****
--- 1,55 ----
+ // 2003-05-13 Benjamin Kosnik  <bkoz@redhat.com>
+ 
+ // Copyright (C) 2003 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.8.1.4 Overridden virtual functions
+ 
+ #include <fstream>
+ #include <locale>
+ #include <testsuite_hooks.h>
+ 
+ class state_codecvt : public std::codecvt<char, char, std::mbstate_t>
+ {
+ protected:
+   int
+   do_encoding() const throw()
+   { return -1; }
+ };
+ 
+ void test03()
+ {
+   using namespace std;
+   bool test = true;
+ 
+   locale loc_s(locale::classic(), new state_codecvt);
+   filebuf ob;
+   ob.pubimbue(loc_s);
+   VERIFY( ob.getloc() == loc_s );
+ 
+   // 2 "if encoding of current locale is state dependent" fails...
+   locale loc_c = locale::classic();
+   locale ret = ob.pubimbue(loc_s);
+   VERIFY( ob.getloc() == loc_s );
+ }
+ 
+ main() 
+ {
+   test03();
+   return 0;
+ }
Index: testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc
===================================================================
RCS file: testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc
diff -N testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc	13 May 2003 19:52:47 -0000
***************
*** 0 ****
--- 1,45 ----
+ // 981208 bkoz test functionality of basic_stringbuf for char_type == char
+ 
+ // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+ // 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ #include <fstream>
+ #include <testsuite_hooks.h>
+ 
+ std::wfilebuf fbuf;
+ 
+ // test the filebuf locale settings
+ void test02() 
+ {
+   std::locale loc_c = std::locale::classic();
+   loc_c = fbuf.getloc();
+   fbuf.pubimbue(loc_c); //This should initialize _M_init to true
+   std::locale loc_tmp = fbuf.getloc(); 
+   VERIFY( loc_tmp == loc_c );
+ }
+ 
+ int main()
+ {
+   test02();
+   return 0;
+ }
+ 
+ 
+ 
+ // more candy!!!
Index: testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc
===================================================================
RCS file: testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc
diff -N testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc	13 May 2003 19:52:47 -0000
***************
*** 0 ****
--- 1,54 ----
+ // 2003-05-13 Benjamin Kosnik  <bkoz@redhat.com>
+ 
+ // Copyright (C) 2003 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.8.1.4 Overridden virtual functions
+ 
+ #include <fstream>
+ #include <locale>
+ #include <testsuite_hooks.h>
+ 
+ void test02()
+ {
+   using namespace std;
+   bool test = true;
+   const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
+ 
+   locale loc;
+   wfilebuf ob;
+   VERIFY( ob.getloc() == loc );
+   ob.open(name_01, ios_base::in);
+   VERIFY( ob.is_open() );
+  
+   typedef streambuf::pos_type pos_type;
+   pos_type bad = pos_type(streambuf::off_type(-1));
+   pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
+   VERIFY( p != bad);
+ 
+   // 1 "if file is not positioned at its beginning" fails...
+   locale loc_de = __gnu_cxx_test::try_named_locale("de_DE");
+   locale ret = ob.pubimbue(loc_de);
+   VERIFY( ob.getloc() == loc );
+ }
+ 
+ main() 
+ {
+   test02();
+   return 0;
+ }
Index: testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc
===================================================================
RCS file: testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc
diff -N testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc	13 May 2003 19:52:47 -0000
***************
*** 0 ****
--- 1,55 ----
+ // 2003-05-13 Benjamin Kosnik  <bkoz@redhat.com>
+ 
+ // Copyright (C) 2003 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.8.1.4 Overridden virtual functions
+ 
+ #include <fstream>
+ #include <locale>
+ #include <testsuite_hooks.h>
+ 
+ class state_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t>
+ {
+ protected:
+   int
+   do_encoding() const throw()
+   { return -1; }
+ };
+ 
+ void test03()
+ {
+   using namespace std;
+   bool test = true;
+ 
+   locale loc_s(locale::classic(), new state_codecvt);
+   wfilebuf ob;
+   ob.pubimbue(loc_s);
+   VERIFY( ob.getloc() == loc_s );
+ 
+   // 2 "if encoding of current locale is state dependent" fails...
+   locale loc_c = locale::classic();
+   locale ret = ob.pubimbue(loc_s);
+   VERIFY( ob.getloc() == loc_s );
+ }
+ 
+ main() 
+ {
+   test03();
+   return 0;
+ }
Index: testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc
===================================================================
RCS file: testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc
diff -N testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc	13 May 2003 19:52:47 -0000
***************
*** 0 ****
--- 1,53 ----
+ // 2001-05-21 Benjamin Kosnik  <bkoz@redhat.com>
+ 
+ // Copyright (C) 2001, 2002, 2003 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.8.1.4 Overridden virtual functions
+ 
+ #include <fstream>
+ #include <locale>
+ #include <testsuite_hooks.h>
+ 
+ // libstdc++/9322
+ void test07()
+ {
+   using std::locale;
+   bool test = true;
+ 
+   locale loc;
+   std::wfilebuf ob;
+   VERIFY( ob.getloc() == loc );
+ 
+   locale::global(__gnu_cxx_test::try_named_locale("en_US"));
+   VERIFY( ob.getloc() == loc );
+ 
+   locale loc_de = __gnu_cxx_test::try_named_locale("de_DE");
+   locale ret = ob.pubimbue(loc_de);
+   VERIFY( ob.getloc() == loc_de );
+   VERIFY( ret == loc );
+ 
+   locale::global(loc);
+   VERIFY( ob.getloc() == loc_de );
+ }
+ 
+ main() 
+ {
+   test07();
+   return 0;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]