This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Clean up sbumpc, move back _M_buf_size, do not special caseunbuffered _M_underflow...


Hi!

this is the patch that I really wanted for many days and of course thanks to Nathan for inspiring me behind the scenes.

Basically, it fixes all the issues we know well (the unbuffered seeks too!, will post later some polished seek testcases split up from the current basic_filebuf/seekoff and seekpos dirs) in a, no so humbly, neat way: just state that 'unbuffered' (27.8.1.4 para 10) means _M_buf_size == 1!

I briefly recall here that _M_buf_size the overall allocated buffer size which usually (buffered case) includes also the space for the overflow char. In the unbuffered case (_M_buf_size == 1), we use that space for the single char get area and we don't use it for overflow char!

I guess that Nathan starte wispering that to my ears not less than 1 months ago, but I never really paid the necessary attention...

Any way, here it is now!

Using regular buffering (no special cases in _M_underflow) solves in a straightforward way also the seek issue, since we already have the machineery inside seekoff.

Tested x86-linux, seeekoff/* testcases too adapted roughly to the unbuffered case too by adding pubsetbuf(0, 0) before the open.

Paolo.
2003-06-09  Paolo Carlini  <pcarlini@unitus.it>

	* include/bits/fstream.tcc (_M_underflow): Do not special
	case the unbuffered case, which really means simply a one char
	get area.
	(basic_filebuf): Initialize _M_buf_size.
	(setbuf): Unbuffered means _M_buf_size == 1, since only
	_M_buf_size - 1 == 0 chars are going to be used for the
	put area and 1 for the get area.
	* include/std/std_streambuf.h (_M_buf_size): Move to basic_filebuf.
	(~basic_streambuf): Tweak.
	(basic_streambuf): Do not initialize _M_buf_size.
	* include/std/std_fstream.h (_M_buf_size): Add from basic_streambuf.
	(~basic_filebuf): Tweak.
	(_M_set_buffer): Tweak, considering that _M_buf_size == 1 is the
	unbuffered situation (i.e., put area pointers NULL).
	* include/bits/streambuf.tcc (sbumpc): Clean up.
	* testsuite/27_io/basic_filebuf/sputbackc/char/1.cc: Split into...
	* testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc: New.
	* testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc: New.
	* testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc: New.
	* testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc: New.
	* testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc: New.
	* testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc: New.
diff -prN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
*** libstdc++-v3-orig/include/bits/fstream.tcc	Fri Jun  6 02:19:14 2003
--- libstdc++-v3/include/bits/fstream.tcc	Mon Jun  9 20:18:06 2003
*************** namespace std
*** 71,79 ****
    template<typename _CharT, typename _Traits>
      basic_filebuf<_CharT, _Traits>::
      basic_filebuf() : __streambuf_type(), _M_file(&_M_lock), 
!     _M_state_cur(__state_type()), _M_state_beg(__state_type()), _M_buf(NULL), 
!     _M_buf_allocated(false),_M_last_overflowed(false), 
!     _M_filepos(0), _M_pback(char_type()), _M_pback_cur_save(0), 
      _M_pback_end_save(0), _M_pback_init(false), _M_codecvt(0)
      { 
        this->_M_buf_unified = true; 	  
--- 71,79 ----
    template<typename _CharT, typename _Traits>
      basic_filebuf<_CharT, _Traits>::
      basic_filebuf() : __streambuf_type(), _M_file(&_M_lock), 
!     _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_filepos(0), _M_pback_cur_save(0), 
      _M_pback_end_save(0), _M_pback_init(false), _M_codecvt(0)
      { 
        this->_M_buf_unified = true; 	  
*************** namespace std
*** 193,294 ****
  	  // fileops happen...
  	  _M_destroy_pback();
  
! 	  const size_t __buflen = this->_M_buf_size 
! 	                          ? this->_M_buf_size - 1 : 0;
! 	  if (__buflen)
  	    {
! 	      if (this->_M_in_cur < this->_M_in_end)
! 		{
! 		  __ret = traits_type::to_int_type(*this->_M_in_cur);
! 		  if (__bump)
! 		    _M_move_in_cur(1);
! 		  return __ret;
! 		}
  
! 	      // Sync internal and external buffers.
! 	      if (__testout && this->_M_out_beg < this->_M_out_lim)
! 		this->overflow();
! 
! 	      // Get and convert input sequence.
! 	      streamsize __elen = 0;
! 	      streamsize __ilen = 0;
! 	      if (__check_facet(_M_codecvt).always_noconv())
  		{
! 		  __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), __buflen);
  		  __ilen = __elen;
  		}
! 	      else
  		{
! 		  char* __buf = static_cast<char*>(__builtin_alloca(__buflen));
! 		  __elen = _M_file.xsgetn(__buf, __buflen);
! 		  
! 		  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 + __buflen, __iend);
! 		  if (__r == codecvt_base::ok)
! 		    __ilen = __iend - this->_M_in_beg;
! 		  else if (__r == codecvt_base::noconv)
! 		    {
! 		      traits_type::copy(this->_M_in_beg,
!  					reinterpret_cast<char_type*>(__buf), 
! 					__elen);
!  		      __ilen = __elen;
! 		    }
! 		  else 
! 		    {
! 		      // Unwind.
! 		      __ilen = 0;
! 		      _M_file.seekoff(-__elen, ios_base::cur, ios_base::in);
! 		    }
  		}
- 
- 	      if (__ilen > 0)
- 		{
- 		  _M_set_buffer(__ilen);
- 		  __ret = traits_type::to_int_type(*this->_M_in_cur);
- 		  if (__bump)
- 		    _M_move_in_cur(1);
- 		}	   	    
  	    }
! 	  else
  	    {
! 	      // Unbuffered.
! 	      char __buf;
! 	      if (_M_file.xsgetn(&__buf, 1) > 0)
! 		{
! 		  if (__check_facet(_M_codecvt).always_noconv())
! 		    {
! 		      char_type* __cp = reinterpret_cast<char_type*>(&__buf);
! 		      __ret = traits_type::to_int_type(*__cp);
! 		    }
! 		  else
! 		    {
! 		      char_type __c;		 
! 		      const char* __eend;
! 		      char_type* __iend;
! 		      codecvt_base::result __r;
! 		      __r = _M_codecvt->in(_M_state_cur, &__buf, &__buf + 1, 
! 					   __eend, &__c, &__c + 1, __iend);
! 		      if (__r == codecvt_base::ok 
! 			  || __r == codecvt_base::noconv)
! 			__ret = traits_type::to_int_type(__c);
! 		    }
! 
! 		  // Need to put back this extracted character so that
! 		  // sgetc will not advance the input stream iff
! 		  // underflow, but cannot call pbackfail directly as
! 		  // it calls underflow... which leads to a recursive
! 		  // showdown.
! 		  if (!__bump)
! 		    {
! 		      _M_create_pback();
! 		      *this->_M_in_cur = traits_type::to_char_type(__ret); 
! 		    }
! 		}
! 	    }
  	}
        _M_last_overflowed = false;	
        return __ret;
--- 193,256 ----
  	  // fileops happen...
  	  _M_destroy_pback();
  
! 	  const size_t __buflen = this->_M_buf_size > 1
! 	                          ? this->_M_buf_size - 1 : 1;
! 
! 	  if (this->_M_in_cur < this->_M_in_end)
  	    {
! 	      __ret = traits_type::to_int_type(*this->_M_in_cur);
! 	      if (__bump)
! 		_M_move_in_cur(1);
! 	      return __ret;
! 	    }
  
! 	  // Sync internal and external buffers.
! 	  if (__testout && this->_M_out_beg < this->_M_out_lim)
! 	    this->overflow();
! 	  
! 	  // Get and convert input sequence.
! 	  streamsize __elen = 0;
! 	  streamsize __ilen = 0;
! 	  if (__check_facet(_M_codecvt).always_noconv())
! 	    {
! 	      __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), __buflen);
! 	      __ilen = __elen;
! 	    }
! 	  else
! 	    {
! 	      char* __buf = static_cast<char*>(__builtin_alloca(__buflen));
! 	      __elen = _M_file.xsgetn(__buf, __buflen);
! 	      
! 	      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 + __buflen, __iend);
! 	      if (__r == codecvt_base::ok)
! 		__ilen = __iend - this->_M_in_beg;
! 	      else if (__r == codecvt_base::noconv)
  		{
! 		  traits_type::copy(this->_M_in_beg,
! 				    reinterpret_cast<char_type*>(__buf), 
! 				    __elen);
  		  __ilen = __elen;
  		}
! 	      else 
  		{
! 		  // Unwind.
! 		  __ilen = 0;
! 		  _M_file.seekoff(-__elen, ios_base::cur, ios_base::in);
  		}
  	    }
! 
! 	  if (__ilen > 0)
  	    {
! 	      _M_set_buffer(__ilen);
! 	      __ret = traits_type::to_int_type(*this->_M_in_cur);
! 	      if (__bump)
! 		_M_move_in_cur(1);
! 	    }	   	    
  	}
        _M_last_overflowed = false;	
        return __ret;
*************** namespace std
*** 467,473 ****
      setbuf(char_type* __s, streamsize __n)
      {
        if (!this->is_open() && __s == 0 && __n == 0)
! 	this->_M_buf_size = 0;
        else if (__s && __n > 1)
  	{
  	  // This is implementation-defined behavior, and assumes that
--- 429,435 ----
      setbuf(char_type* __s, streamsize __n)
      {
        if (!this->is_open() && __s == 0 && __n == 0)
! 	this->_M_buf_size = 1;
        else if (__s && __n > 1)
  	{
  	  // This is implementation-defined behavior, and assumes that
diff -prN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
*** libstdc++-v3-orig/include/bits/streambuf.tcc	Fri Jun  6 02:19:15 2003
--- libstdc++-v3/include/bits/streambuf.tcc	Mon Jun  9 16:27:35 2003
*************** namespace std 
*** 48,59 ****
        if (_M_in_cur < _M_in_end)
  	{
  	  char_type __c = *this->_M_in_cur;
  	  __ret = traits_type::to_int_type(__c);
- 	  
- 	  if (_M_buf_size)
- 	    _M_move_in_cur(1);
- 	  else
- 	    this->underflow();
  	}
        else 
  	__ret = this->uflow();
--- 48,55 ----
        if (_M_in_cur < _M_in_end)
  	{
  	  char_type __c = *this->_M_in_cur;
+ 	  _M_move_in_cur(1);
  	  __ret = traits_type::to_int_type(__c);
  	}
        else 
  	__ret = this->uflow();
diff -prN libstdc++-v3-orig/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
*** libstdc++-v3-orig/include/std/std_fstream.h	Fri Jun  6 02:19:15 2003
--- libstdc++-v3/include/std/std_fstream.h	Mon Jun  9 20:17:20 2003
*************** namespace std
*** 121,126 ****
--- 121,135 ----
        */
        char_type*		_M_buf; 	
  
+       /**
+        *  @if maint
+        *  Actual size of internal buffer. This number is equal to the size
+        *  of the put area + 1 position, reserved for the overflow char of
+        *  a full area.
+        *  @endif
+       */
+       size_t			_M_buf_size;
+ 
        // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer.
        /**
         *  @if maint
*************** namespace std
*** 206,211 ****
--- 215,221 ----
        ~basic_filebuf()
        {
  	this->close();
+ 	_M_buf_size = 0;
  	_M_last_overflowed = false;
        }
  
*************** namespace std
*** 429,445 ****
        {
   	const bool __testin = this->_M_mode & ios_base::in;
   	const bool __testout = this->_M_mode & ios_base::out;
! 	if (this->_M_buf_size)
  	  {
! 	    if (__testin)
! 	      this->setg(this->_M_buf, this->_M_buf, this->_M_buf + __off);
! 	    if (__testout)
! 	      {
! 		this->setp(this->_M_buf, this->_M_buf + this->_M_buf_size - 1);
! 		this->_M_out_lim += __off;
! 	      }
! 	    _M_filepos = this->_M_buf + __off;
  	  }
        }
      };
  
--- 439,453 ----
        {
   	const bool __testin = this->_M_mode & ios_base::in;
   	const bool __testout = this->_M_mode & ios_base::out;
! 	
! 	if (__testin)
! 	  this->setg(this->_M_buf, this->_M_buf, this->_M_buf + __off);
! 	if (this->_M_buf_size > 1 && __testout)
  	  {
! 	    this->setp(this->_M_buf, this->_M_buf + this->_M_buf_size - 1);
! 	    this->_M_out_lim += __off;
  	  }
+ 	_M_filepos = this->_M_buf + __off;
        }
      };
  
diff -prN libstdc++-v3-orig/include/std/std_streambuf.h libstdc++-v3/include/std/std_streambuf.h
*** libstdc++-v3-orig/include/std/std_streambuf.h	Fri Jun  6 02:19:15 2003
--- libstdc++-v3/include/std/std_streambuf.h	Mon Jun  9 16:27:35 2003
*************** namespace std
*** 197,211 ****
  
        /**
         *  @if maint
-        *  Actual size of internal buffer. This number is equal to the size
-        *  of the put area + 1 position, reserved for the overflow char of
-        *  a full area.
-        *  @endif
-       */
-       size_t			_M_buf_size;
- 
-       /**
-        *  @if maint
         *  Place to stash in || out || in | out settings for current streambuf.
         *  @endif
        */
--- 197,202 ----
*************** namespace std
*** 267,273 ****
        ~basic_streambuf() 
        {
  	_M_buf_unified = false;
- 	_M_buf_size = 0;
  	_M_mode = ios_base::openmode(0);
        }
  
--- 258,263 ----
*************** namespace std
*** 468,475 ****
        */
        basic_streambuf()
        : _M_in_beg(0), _M_in_cur(0), _M_in_end(0), 
!       _M_out_beg(0), _M_out_cur(0), _M_out_end(0),_M_out_lim(0), 
!       _M_buf_unified(false), _M_buf_size(BUFSIZ), 
        _M_mode(ios_base::openmode(0)),_M_buf_locale(locale()) 
        { }
  
--- 458,465 ----
        */
        basic_streambuf()
        : _M_in_beg(0), _M_in_cur(0), _M_in_end(0), 
!       _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
!       _M_out_lim(0), _M_buf_unified(false), 
        _M_mode(ios_base::openmode(0)),_M_buf_locale(locale()) 
        { }
  
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc	Mon Jun  9 20:23:26 2003
***************
*** 0 ****
--- 1,92 ----
+ // 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 <testsuite_hooks.h>
+ #include <testsuite_io.h>
+ 
+ // @require@ %-*.tst %-*.txt
+ // @diff@ %-*.tst %*.txt
+ 
+ const char name_01[] = "sgetc.txt"; // file with data in it
+ 
+ // Test overloaded virtual functions.
+ void test01() 
+ {
+   using namespace std;
+   using namespace __gnu_cxx_test;
+   typedef std::filebuf::int_type 	int_type;
+   typedef filebuf::traits_type 		traits_type;
+ 
+   bool 					test = true;
+   int_type 			c1, c2, c3;
+ 
+   // int_type sputbackc(char_type c)
+   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+   // otherwise decrements in_cur and returns *gptr()
+ 
+   // in
+   {
+     constraint_filebuf fb_01; // in 
+     fb_01.open(name_01, ios::in);
+     VERIFY( !fb_01.write_position() );
+     c1 = fb_01.sbumpc();
+     VERIFY( c1 == '/' );
+     c2 = fb_01.sputbackc('/');
+     VERIFY( c1 == c2 );
+     c3 = fb_01.sgetc();
+     VERIFY( c3 == c2 );
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == c2 );
+     fb_01.sbumpc();
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == ' ' );
+     c1 = fb_01.sgetc();
+     c2 = fb_01.sputbackc('a');
+     VERIFY( c2 == 'a' );
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == c2 );
+     c3 = fb_01.sgetc();
+     VERIFY( c1 == c3 );
+     fb_01.pubseekoff(5, ios_base::beg, ios_base::in);
+     c1 = fb_01.sgetc();
+     VERIFY( c1 == '0' );
+     fb_01.sbumpc();
+     c1 = fb_01.sbumpc();
+     VERIFY( c1 == '1' );
+     c2 = fb_01.sputbackc('b');
+     VERIFY( c2 == 'b' );
+     fb_01.sbumpc();
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == '1' );
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == '7' );
+     VERIFY( !fb_01.write_position() );
+     VERIFY( fb_01.read_position() );
+   }
+ }
+ 
+ main() 
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc	Mon Jun  9 20:23:26 2003
***************
*** 0 ****
--- 1,99 ----
+ // 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 <testsuite_hooks.h>
+ #include <testsuite_io.h>
+ 
+ // @require@ %-*.tst %-*.txt
+ // @diff@ %-*.tst %*.txt
+ 
+ const char name_01[] = "tmp_sputbackc_1io.tst"; // empty file, need to create
+ 
+ void test01() 
+ {
+   using namespace std;
+   using namespace __gnu_cxx_test;
+ 
+   typedef filebuf::int_type 	int_type;
+   typedef filebuf::traits_type 	traits_type;
+   typedef size_t 			size_type;
+ 
+   bool 					test = true;
+   streamsize 			strmsz_1, strmsz_2;
+   int_type 			c1, c2, c3;
+ 
+   // int_type sputbackc(char_type c)
+   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+   // otherwise decrements in_cur and returns *gptr()
+ 
+   // in | out
+   {
+     constraint_filebuf fb_01; 
+     fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc);
+     VERIFY( fb_01.write_position() );
+     VERIFY( !fb_01.read_position() );
+     strmsz_1 = fb_01.sputn("racadabras", 10);//"abracadabras or what?"
+     strmsz_2 = fb_01.sputn(", i wanna reach out and", 10);
+     c1 = fb_01.sgetc(); // -1
+     c2 = fb_01.sputbackc('z');
+     strmsz_2 = fb_01.in_avail();
+     c3 = fb_01.sgetc();
+     VERIFY( c3 == c2 );
+     VERIFY( c1 != c3 );
+     VERIFY( 1 == strmsz_2 );
+     //test for _in_cur == _in_beg
+     // fb_01._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc
+     fb_01.pubseekoff(10, std::ios_base::beg, 
+ 		   std::ios_base::in | std::ios_base::out);
+     fb_01.sputc('m');
+     strmsz_1 = fb_01.in_avail(); 
+     c1 = fb_01.sgetc(); 
+     fb_01.snextc();
+     c2 = fb_01.sputbackc('z');  
+     strmsz_2 = fb_01.in_avail(); 
+     c3 = fb_01.sgetc();  
+     VERIFY( c1 != c2 );
+     VERIFY( c3 == c2 );
+     VERIFY( c1 != c3 );
+     VERIFY( c2 == 'z' );
+     // test for replacing char with identical one
+     fb_01.snextc();
+     fb_01.sputc('u');
+     fb_01.sputc('v');
+     fb_01.sputc('a');
+     strmsz_1 = fb_01.in_avail();
+     c2 = fb_01.sputbackc('a');
+     strmsz_2 = fb_01.in_avail();
+     c3 = fb_01.sgetc();
+     VERIFY( c3 == c2 );
+     VERIFY( strmsz_1 + 1 == strmsz_2 );
+     VERIFY( fb_01.write_position() );
+     VERIFY( fb_01.read_position() );
+   }
+ }
+ 
+ main() 
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc	Mon Jun  9 20:23:26 2003
***************
*** 0 ****
--- 1,70 ----
+ // 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 <testsuite_hooks.h>
+ #include <testsuite_io.h>
+ 
+ // @require@ %-*.tst %-*.txt
+ // @diff@ %-*.tst %*.txt
+ 
+ const char name_01[] = "tmp_sputbackc_1out.tst"; // empty file, need to create
+ 
+ // Test overloaded virtual functions.
+ void test01() 
+ {
+   using namespace std;
+   using namespace __gnu_cxx_test;
+   typedef std::filebuf::int_type 	int_type;
+   typedef filebuf::traits_type 		traits_type;
+ 
+   bool 					test = true;
+   int_type 			c1, c2, c3;
+ 
+   // int_type sputbackc(char_type c)
+   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+   // otherwise decrements in_cur and returns *gptr()
+ 
+   // out
+   {
+     constraint_filebuf fb_01; // out
+     fb_01.open(name_01, ios::out | ios::trunc);    
+     VERIFY( fb_01.write_position() );
+     VERIFY( !fb_01.read_position() );
+     c1 = fb_01.sgetc();
+     VERIFY( c1 == traits_type::eof() );
+     c2 = fb_01.sputbackc('a');
+     VERIFY( c2 == traits_type::eof() );
+     fb_01.sbumpc();
+     c1 = fb_01.sbumpc();
+     c2 = fb_01.sputbackc('a');
+     VERIFY( c1 == c2 );
+     VERIFY( fb_01.write_position() );
+     VERIFY( !fb_01.read_position() );
+   }
+ }
+ 
+ main() 
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/1.cc	Mon May 12 23:01:39 2003
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1.cc	Thu Jan  1 01:00:00 1970
***************
*** 1,155 ****
- // 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 <testsuite_hooks.h>
- 
- // @require@ %-*.tst %-*.txt
- // @diff@ %-*.tst %*.txt
- 
- // NB: This test assumes that _M_buf_size == 40, and not the usual
- // buffer_size length of BUFSIZ (8192), so that overflow/underflow can be
- // simulated a bit more readily.
- // NRB (Nota Really Bene): setting it to 40 breaks the test, as intended.
- const int buffer_size = 8192;
- //const int buffer_size = 40;
- 
- const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
- const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create
- const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create
- 
- class derived_filebuf: public std::filebuf
- {
-  public:
-   void
-   set_size(int_type __size) { _M_buf_size = __size; }
- };
- 
- derived_filebuf fb_01; // in 
- derived_filebuf fb_02; // out
- derived_filebuf fb_03; // in | out
- 
- // Initialize filebufs to be the same size regardless of platform.
- void test03()
- {
-   fb_01.set_size(buffer_size);
-   fb_02.set_size(buffer_size);
-   fb_03.set_size(buffer_size);
- }
- 
- // Test overloaded virtual functions.
- void test05() 
- {
-   typedef std::filebuf::int_type 	int_type;
-   typedef std::filebuf::traits_type 	traits_type;
-   typedef std::filebuf::pos_type 	pos_type;
-   typedef std::filebuf::off_type 	off_type;
-   typedef size_t 			size_type;
- 
-   bool 					test = true;
-   std::filebuf 				f_tmp;
-   std::streamsize 			strmsz_1, strmsz_2;
-   std::streamoff  			strmof_1, strmof_2;
-   int 					i = 0, j = 0, k = 0;
- 
-   fb_01.open(name_01, std::ios_base::in);
-   fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc);
-   fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc);
- 
-   int_type c1 = fb_01.sbumpc();
-   int_type c2 = fb_02.sbumpc();
-   int_type c3 = fb_01.sbumpc();
-   int_type c4 = fb_02.sbumpc();
-   int_type c5 = fb_03.sbumpc();
-   int_type c6 = fb_01.sgetc();
-   int_type c7 = fb_02.sgetc();
-   int_type c8 = fb_01.sgetc();
-   int_type c9 = fb_02.sgetc();
- 
-   // PUT
-   strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?"
-   strmsz_2 = fb_03.sputn(", i wanna reach out and", 10);
-   strmsz_1 = fb_02.sputn("racadabras", 10);
-   strmsz_1 = fb_01.sputn("racadabra", 10);
- 
-   // PUTBACK
-   // int_type pbfail(int_type c)
-   // called when gptr() null, gptr() == eback(), or traits::eq(*gptr, c) false
-   // "pending sequence" is:
-   //	1) everything as defined in underflow
-   // 	2) + if (traits::eq_int_type(c, traits::eof()), then input
-   // 	sequence is backed up one char before the pending sequence is
-   // 	determined.
-   //	3) + if (not 2) then c is prepended. Left unspecified is
-   //	whether the input sequence is backedup or modified in any way
-   // returns traits::eof() for failure, unspecified other value for success
- 
-   // int_type sputbackc(char_type c)
-   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
-   // otherwise decrements in_cur and returns *gptr()
-   c1 = fb_03.sgetc(); // -1
-   c2 = fb_03.sputbackc('z');
-   strmsz_2 = fb_03.in_avail();
-   c3 = fb_03.sgetc();
-   VERIFY( c3 == c2 );
-   VERIFY( c1 != c3 );
-   VERIFY( 1 == strmsz_2 );
-   //test for _in_cur == _in_beg
-   // fb_03._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc
-   fb_03.pubseekoff(10, std::ios_base::beg, 
- 		   std::ios_base::in | std::ios_base::out);
-   fb_03.sputc('m');
-   strmsz_1 = fb_03.in_avail(); 
-   c1 = fb_03.sgetc(); 
-   fb_03.snextc();
-   c2 = fb_03.sputbackc('z');  
-   strmsz_2 = fb_03.in_avail(); 
-   c3 = fb_03.sgetc();  
-   VERIFY( c1 != c2 );
-   VERIFY( c3 == c2 );
-   VERIFY( c1 != c3 );
-   VERIFY( c2 == 'z' );
-   //  VERIFY( strmsz_1 == strmsz_2 );
-   // test for replacing char with identical one
-   fb_03.snextc();
-   fb_03.sputc('u');
-   fb_03.sputc('v');
-   fb_03.sputc('a');
-   strmsz_1 = fb_03.in_avail();
-   c2 = fb_03.sputbackc('a');
-   strmsz_2 = fb_03.in_avail();
-   c3 = fb_03.sgetc();
-   VERIFY( c3 == c2 );
-   VERIFY( strmsz_1 + 1 == strmsz_2 );
-   //test for ios_base::out
-   c1 = fb_02.sgetc(); // undefined
-   c2 = fb_02.sputbackc('a');
-   VERIFY( c1 == c2 );
-   VERIFY( c1 == -1 );
- }
- 
- main() 
- {
-   test03();
-   test05();
-   return 0;
- }
--- 0 ----
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc	Mon Jun  9 20:23:26 2003
***************
*** 0 ****
--- 1,92 ----
+ // 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 <testsuite_hooks.h>
+ #include <testsuite_io.h>
+ 
+ // @require@ %-*.tst %-*.txt
+ // @diff@ %-*.tst %*.txt
+ 
+ const char name_01[] = "sgetc.txt"; // file with data in it
+ 
+ // Test overloaded virtual functions.
+ void test01() 
+ {
+   using namespace std;
+   using namespace __gnu_cxx_test;
+   typedef std::filebuf::int_type 	int_type;
+   typedef filebuf::traits_type 		traits_type;
+ 
+   bool 					test = true;
+   int_type 			c1, c2, c3;
+ 
+   // int_type sputbackc(char_type c)
+   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+   // otherwise decrements in_cur and returns *gptr()
+ 
+   // in
+   {
+     constraint_filebuf fb_01; // in 
+     fb_01.pubsetbuf(0, 0);
+     fb_01.open(name_01, ios::in);
+     VERIFY( fb_01.unbuffered() );
+     c1 = fb_01.sbumpc();
+     VERIFY( c1 == '/' );
+     c2 = fb_01.sputbackc('/');
+     VERIFY( c1 == c2 );
+     c3 = fb_01.sgetc();
+     VERIFY( c3 == c2 );
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == c2 );
+     fb_01.sbumpc();
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == ' ' );
+     c1 = fb_01.sgetc();
+     c2 = fb_01.sputbackc('a');
+     VERIFY( c2 == 'a' );
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == c2 );
+     c3 = fb_01.sgetc();
+     VERIFY( c1 == c3 );
+     fb_01.pubseekoff(5, ios_base::beg, ios_base::in);
+     c1 = fb_01.sgetc();
+     VERIFY( c1 == '0' );
+     fb_01.sbumpc();
+     c1 = fb_01.sbumpc();
+     VERIFY( c1 == '1' );
+     c2 = fb_01.sputbackc('b');
+     VERIFY( c2 == 'b' );
+     fb_01.sbumpc();
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == '1' );
+     c3 = fb_01.sbumpc();
+     VERIFY( c3 == '7' );
+     VERIFY( fb_01.unbuffered() );
+   }
+ }
+ 
+ main() 
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc	Mon Jun  9 20:23:26 2003
***************
*** 0 ****
--- 1,98 ----
+ // 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 <testsuite_hooks.h>
+ #include <testsuite_io.h>
+ 
+ // @require@ %-*.tst %-*.txt
+ // @diff@ %-*.tst %*.txt
+ 
+ const char name_01[] = "tmp_sputbackc_2io.tst"; // empty file, need to create
+ 
+ void test01() 
+ {
+   using namespace std;
+   using namespace __gnu_cxx_test;
+ 
+   typedef filebuf::int_type 	int_type;
+   typedef filebuf::traits_type 	traits_type;
+   typedef size_t 			size_type;
+ 
+   bool 					test = true;
+   streamsize 			strmsz_1, strmsz_2;
+   int_type 			c1, c2, c3;
+ 
+   // int_type sputbackc(char_type c)
+   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+   // otherwise decrements in_cur and returns *gptr()
+ 
+   // in | out
+   {
+     constraint_filebuf fb_01;
+     fb_01.pubsetbuf(0, 0);
+     fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc);
+     VERIFY( fb_01.unbuffered() );
+     strmsz_1 = fb_01.sputn("racadabras", 10);//"abracadabras or what?"
+     strmsz_2 = fb_01.sputn(", i wanna reach out and", 10);
+     c1 = fb_01.sgetc(); // -1
+     c2 = fb_01.sputbackc('z');
+     strmsz_2 = fb_01.in_avail();
+     c3 = fb_01.sgetc();
+     VERIFY( c3 == c2 );
+     VERIFY( c1 != c3 );
+     VERIFY( 1 == strmsz_2 );
+     //test for _in_cur == _in_beg
+     // fb_01._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc
+     fb_01.pubseekoff(10, std::ios_base::beg, 
+ 		   std::ios_base::in | std::ios_base::out);
+     fb_01.sputc('m');
+     strmsz_1 = fb_01.in_avail(); 
+     c1 = fb_01.sgetc(); 
+     fb_01.snextc();
+     c2 = fb_01.sputbackc('z');  
+     strmsz_2 = fb_01.in_avail(); 
+     c3 = fb_01.sgetc();  
+     VERIFY( c1 != c2 );
+     VERIFY( c3 == c2 );
+     VERIFY( c1 != c3 );
+     VERIFY( c2 == 'z' );
+     // test for replacing char with identical one
+     fb_01.snextc();
+     fb_01.sputc('u');
+     fb_01.sputc('v');
+     fb_01.sputc('a');
+     strmsz_1 = fb_01.in_avail();
+     c2 = fb_01.sputbackc('a');
+     strmsz_2 = fb_01.in_avail();
+     c3 = fb_01.sgetc();
+     VERIFY( c3 == c2 );
+     VERIFY( strmsz_1 == strmsz_2 );
+     VERIFY( fb_01.unbuffered() );
+   }
+ }
+ 
+ main() 
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc	Mon Jun  9 20:23:26 2003
***************
*** 0 ****
--- 1,71 ----
+ // 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 <testsuite_hooks.h>
+ #include <testsuite_io.h>
+ 
+ // @require@ %-*.tst %-*.txt
+ // @diff@ %-*.tst %*.txt
+ 
+ const char name_01[] = "tmp_sputbackc_2out.tst"; // empty file, need to create
+ 
+ // Test overloaded virtual functions.
+ void test01() 
+ {
+   using namespace std;
+   using namespace __gnu_cxx_test;
+   typedef std::filebuf::int_type 	int_type;
+   typedef filebuf::traits_type 		traits_type;
+ 
+   bool 					test = true;
+   int_type 			c1, c2, c3;
+ 
+   // int_type sputbackc(char_type c)
+   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+   // otherwise decrements in_cur and returns *gptr()
+ 
+   // out
+   {
+     constraint_filebuf fb_01; // out
+     fb_01.pubsetbuf(0, 0);
+     fb_01.open(name_01, ios::out | ios::trunc);    
+     VERIFY( fb_01.unbuffered() );
+     VERIFY( !fb_01.read_position() );
+     c1 = fb_01.sgetc();
+     VERIFY( c1 == traits_type::eof() );
+     c2 = fb_01.sputbackc('a');
+     VERIFY( c2 == traits_type::eof() );
+     fb_01.sbumpc();
+     c1 = fb_01.sbumpc();
+     c2 = fb_01.sputbackc('a');
+     VERIFY( c1 == c2 );
+     VERIFY( fb_01.unbuffered() );
+     VERIFY( !fb_01.read_position() );
+   }
+ }
+ 
+ main() 
+ {
+   test01();
+   return 0;
+ }

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