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]

Re: [RFC/Patch] What about using seekoff(-1, ...) for unbufferedunderflow?


Paolo Carlini wrote:

... however, I like even more the below, slightly simpler and which definitely
keeps pbackfail working correctly (I will prepare a testcase for this, anyway).

Actually, I believe a slight change is needed for pbackfail, in order to correctly return to the normal unbuffered situation after a sequence sgetc - putback.

I will therefore test the below together with some tests for unbuffered pback.

Paolo.

///////////
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc	2003-06-06 02:19:14.000000000 +0200
+++ libstdc++-v3/include/bits/fstream.tcc	2003-06-07 00:34:01.000000000 +0200
@@ -71,9 +71,9 @@
   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_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; 	  
@@ -256,6 +256,14 @@
 	  else
 	    {
 	      // Unbuffered.
+	      if (this->_M_in_cur)
+		{
+		  __ret = traits_type::to_int_type(*this->_M_in_cur);
+		  if (__bump)
+		    this->setg(NULL, NULL, NULL);
+		  return __ret;
+		}
+
 	      char __buf;
 	      if (_M_file.xsgetn(&__buf, 1) > 0)
 		{
@@ -284,8 +292,8 @@
 		  // showdown.
 		  if (!__bump)
 		    {
-		      _M_create_pback();
-		      *this->_M_in_cur = traits_type::to_char_type(__ret); 
+		      _M_pback = traits_type::to_char_type(__ret);
+		      this->setg(&_M_pback, &_M_pback, &_M_pback);
 		    }
 		}
 	    }
@@ -339,6 +347,8 @@
 	    __ret = traits_type::not_eof(__i);
 	  else if (!__testpb)
 	    {
+	      if (this->_M_in_end == &_M_pback)
+		this->setg(NULL, NULL, NULL);
 	      _M_create_pback();
 	      *this->_M_in_cur = traits_type::to_char_type(__i); 
 	      __ret = __i;
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc	2003-06-06 02:19:15.000000000 +0200
+++ libstdc++-v3/include/bits/streambuf.tcc	2003-06-06 18:53:29.000000000 +0200
@@ -48,12 +48,8 @@
       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);
-	  
-	  if (_M_buf_size)
-	    _M_move_in_cur(1);
-	  else
-	    this->underflow();
 	}
       else 
 	__ret = this->uflow();
diff -urN libstdc++-v3-orig/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
--- libstdc++-v3-orig/include/std/std_fstream.h	2003-06-06 02:19:15.000000000 +0200
+++ libstdc++-v3/include/std/std_fstream.h	2003-06-06 22:34:54.000000000 +0200
@@ -121,6 +121,15 @@
       */
       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
@@ -206,6 +215,7 @@
       ~basic_filebuf()
       {
 	this->close();
+	_M_buf_size = 0;
 	_M_last_overflowed = false;
       }
 
diff -urN libstdc++-v3-orig/include/std/std_streambuf.h libstdc++-v3/include/std/std_streambuf.h
--- libstdc++-v3-orig/include/std/std_streambuf.h	2003-06-06 02:19:15.000000000 +0200
+++ libstdc++-v3/include/std/std_streambuf.h	2003-06-06 22:36:50.000000000 +0200
@@ -197,15 +197,6 @@
 
       /**
        *  @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
       */
@@ -267,7 +258,6 @@
       ~basic_streambuf() 
       {
 	_M_buf_unified = false;
-	_M_buf_size = 0;
 	_M_mode = ios_base::openmode(0);
       }
 
@@ -467,10 +457,9 @@
        *  - this is not an error
       */
       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()) 
+      : _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()) 
       { }
 
       // [27.5.2.3.1] get area access

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