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]

[RFC/Patch] What about using seekoff(-1, ...) for unbuffered underflow?


Hi Benjamin, hi all,

I'm looking a bit into the new framework for unbuffered input,
and I'd rather prefer having sbumpc() simple as it was before.

Also, keeping _M_buf_size in basic_filebuf only.

I have tested successfully the below.

Opinions?

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-06 14:06:58.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; 	  
@@ -283,10 +283,7 @@
 		  // 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_file.seekoff(-1, ios_base::cur, ios_base::in);
 		}
 	    }
 	}
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 13:11:53.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 14:08:20.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 14:10:08.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);
       }
 
@@ -468,8 +458,8 @@
       */
       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_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()) 
       { }
 

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