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] Move pback members from basic_streambuf to basic_filebuf


Hi,

suggested by Pétur, this seems obvious in the light of the patch
for the second half of 9701, in particular the comment preceding
the members at issue:

 *  Necessary bits for putback buffer management. Only used in
 *  the basic_filebuf class, as necessary for the standard
 *  requirements.

Tested x86-linux. Ok?

Thanks,
Paolo.

////////
2003-04-22  Paolo Carlini  <pcarlini at unitus dot it>

	* include/std/std_streambuf.h (_S_pback_size, _M_pback,
	_M_pback_cur_save, _M_pback_end_save, _M_pback_init,
	_M_pback_create(), _M_pback_destroy()): Move to basic_filebuf.
	(basic_streambuf::basic_streambuf()): Adjust.
	* include/std/std_fstream.h (_S_pback_size, _M_pback,
	_M_pback_cur_save, _M_pback_end_save, _M_pback_init,
	_M_pback_create(), _M_pback_destroy()): Moved here
	from basic_streambuf.
	* include/bits/fstream.tcc (basic_filebuf::basic_filebuf()):
	Adjust.
	(basic_filebuf::_S_pback_size): Add declaration.
	* include/bits/streambuf.tcc (basic_streambuf::_S_pback_size):
	Remove declaration.
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc	2003-04-21 22:08:14.000000000 +0200
+++ libstdc++-v3/include/bits/fstream.tcc	2003-04-22 14:43:49.000000000 +0200
@@ -40,6 +40,10 @@
 namespace std
 {
   template<typename _CharT, typename _Traits>
+    const size_t
+    basic_filebuf<_CharT, _Traits>::_S_pback_size;
+
+  template<typename _CharT, typename _Traits>
     void
     basic_filebuf<_CharT, _Traits>::
     _M_allocate_internal_buffer()
@@ -72,7 +76,8 @@
     basic_filebuf<_CharT, _Traits>::
     basic_filebuf() : __streambuf_type(), _M_file(&_M_lock), 
     _M_state_cur(__state_type()), _M_state_beg(__state_type()), 
-    _M_buf_allocated(false), _M_last_overflowed(false)
+    _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>
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc	2003-04-21 22:14:39.000000000 +0200
+++ libstdc++-v3/include/bits/streambuf.tcc	2003-04-22 14:42:30.000000000 +0200
@@ -40,10 +40,6 @@
 namespace std 
 {
   template<typename _CharT, typename _Traits>
-    const size_t
-    basic_streambuf<_CharT, _Traits>::_S_pback_size;
-
-  template<typename _CharT, typename _Traits>
     typename basic_streambuf<_CharT, _Traits>::int_type
     basic_streambuf<_CharT, _Traits>::
     sbumpc()
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-04-18 15:55:22.000000000 +0200
+++ libstdc++-v3/include/std/std_fstream.h	2003-04-22 14:51:22.000000000 +0200
@@ -134,6 +134,65 @@
       */
       char_type*		_M_filepos;
 
+      //@{
+      /**
+       *  @if maint
+       *  Necessary bits for putback buffer management.
+       *
+       *  @note pbacks of over one character are not currently supported.
+       *  @endif
+      */
+      static const size_t   	_S_pback_size = 1; 
+      char_type			_M_pback[_S_pback_size]; 
+      char_type*		_M_pback_cur_save;
+      char_type*		_M_pback_end_save;
+      bool			_M_pback_init; 
+      //@}
+
+      // Initializes pback buffers, and moves normal buffers to safety.
+      // Assumptions:
+      // _M_in_cur has already been moved back
+      void
+      _M_pback_create()
+      {
+	if (!_M_pback_init)
+	  {
+	    size_t __dist = this->_M_in_end - this->_M_in_cur;
+	    size_t __len = std::min(_S_pback_size, __dist);
+	    traits_type::copy(_M_pback, this->_M_in_cur, __len);
+	    _M_pback_cur_save = this->_M_in_cur;
+	    _M_pback_end_save = this->_M_in_end;
+	    this->setg(_M_pback, _M_pback, _M_pback + __len);
+	    _M_pback_init = true;
+	  }
+      }
+
+      // Deactivates pback buffer contents, and restores normal buffer.
+      // Assumptions:
+      // The pback buffer has only moved forward.
+      void
+      _M_pback_destroy()
+      {
+	if (_M_pback_init)
+	  {
+	    // Length _M_in_cur moved in the pback buffer.
+	    size_t __off_cur = this->_M_in_cur - _M_pback;
+	    
+	    // For in | out buffers, the end can be pushed back...
+	    size_t __off_end = 0;
+	    size_t __pback_len = this->_M_in_end - _M_pback;
+	    size_t __save_len = _M_pback_end_save - this->_M_buf;
+	    if (__pback_len > __save_len)
+	      __off_end = __pback_len - __save_len;
+
+	    this->setg(this->_M_buf, _M_pback_cur_save + __off_cur, 
+		       _M_pback_end_save + __off_end);
+	    _M_pback_cur_save = NULL;
+	    _M_pback_end_save = NULL;
+	    _M_pback_init = false;
+	  }
+      }
+
     public:
       // Constructors/destructor:
       /**
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-04-21 22:26:47.000000000 +0200
+++ libstdc++-v3/include/std/std_streambuf.h	2003-04-22 14:35:49.000000000 +0200
@@ -229,23 +229,6 @@
       */
       locale 			_M_buf_locale;	
 
-      //@{
-      /**
-       *  @if maint
-       *  Necessary bits for putback buffer management. Only used in
-       *  the basic_filebuf class, as necessary for the standard
-       *  requirements.
-       *  
-       *  @note pbacks of over one character are not currently supported.
-       *  @endif
-      */
-      static const size_t   	_S_pback_size = 1; 
-      char_type			_M_pback[_S_pback_size]; 
-      char_type*		_M_pback_cur_save;
-      char_type*		_M_pback_end_save;
-      bool			_M_pback_init; 
-      //@}
-
       /**
        *  @if maint
        *  Yet unused.
@@ -253,50 +236,6 @@
       */
       fpos<__state_type>	_M_pos;
 
-      // Initializes pback buffers, and moves normal buffers to safety.
-      // Assumptions:
-      // _M_in_cur has already been moved back
-      void
-      _M_pback_create()
-      {
-	if (!_M_pback_init)
-	  {
-	    size_t __dist = _M_in_end - _M_in_cur;
-	    size_t __len = std::min(_S_pback_size, __dist);
-	    traits_type::copy(_M_pback, _M_in_cur, __len);
-	    _M_pback_cur_save = _M_in_cur;
-	    _M_pback_end_save = _M_in_end;
-	    this->setg(_M_pback, _M_pback, _M_pback + __len);
-	    _M_pback_init = true;
-	  }
-      }
-
-      // Deactivates pback buffer contents, and restores normal buffer.
-      // Assumptions:
-      // The pback buffer has only moved forward.
-      void
-      _M_pback_destroy()
-      {
-	if (_M_pback_init)
-	  {
-	    // Length _M_in_cur moved in the pback buffer.
-	    size_t __off_cur = _M_in_cur - _M_pback;
-	    
-	    // For in | out buffers, the end can be pushed back...
-	    size_t __off_end = 0;
-	    size_t __pback_len = _M_in_end - _M_pback;
-	    size_t __save_len = _M_pback_end_save - _M_buf;
-	    if (__pback_len > __save_len)
-	      __off_end = __pback_len - __save_len;
-
-	    this->setg(_M_buf, _M_pback_cur_save + __off_cur, 
-		       _M_pback_end_save + __off_end);
-	    _M_pback_cur_save = NULL;
-	    _M_pback_end_save = NULL;
-	    _M_pback_init = false;
-	  }
-      }
-
       // Correctly sets the _M_in_cur pointer, and bumps the
       // _M_out_cur pointer as well if necessary.
       void 
@@ -541,9 +480,7 @@
       : _M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_unified(false),
       _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_mode(ios_base::openmode(0)), _M_buf_locale(locale()), 
-      _M_pback_cur_save(0), _M_pback_end_save(0), 
-      _M_pback_init(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]