std_sstream.h (basic_stringbuf<>::setbuf): Simply clear the internal _M_string, adjus...
authorPaolo Carlini <pcarlini@suse.de>
Sun, 19 Feb 2006 18:27:06 +0000 (18:27 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 19 Feb 2006 18:27:06 +0000 (18:27 +0000)
2006-02-19  Paolo Carlini  <pcarlini@suse.de>

* include/std/std_sstream.h (basic_stringbuf<>::setbuf): Simply
clear the internal _M_string, adjust _M_sync call.
* include/bits/sstream.tcc (basic_stringbuf<>::_M_sync): Adjust
consistently for calls from setbuf.

From-SVN: r111274

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/sstream.tcc
libstdc++-v3/include/std/std_sstream.h

index 99af0811454f84ad4e7fb0ca81ce3851c12c266a..1e1c79fb275bc924e33dfba42ece69233763cdea 100644 (file)
@@ -1,3 +1,10 @@
+2006-02-19  Paolo Carlini  <pcarlini@suse.de>
+
+       * include/std/std_sstream.h (basic_stringbuf<>::setbuf): Simply
+       clear the internal _M_string, adjust _M_sync call.
+       * include/bits/sstream.tcc (basic_stringbuf<>::_M_sync): Adjust
+       consistently for calls from setbuf.
+
 2006-02-17  Paolo Carlini  <pcarlini@suse.de>
            Howard Hinnant  <hhinnant@apple.com>
 
index 95d3d4699beed4d4892c8b1d32fd43ed9c662056..2c5be334557d54bafce3736df0381778fcc0e12a 100644 (file)
@@ -225,9 +225,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       return __ret;
     }
 
-  // Assumes: contents of _M_string and internal buffer match exactly.
-  // __i == _M_in_cur - _M_in_beg
-  // __o == _M_out_cur - _M_out_beg
   template <class _CharT, class _Traits, class _Alloc>
     void
     basic_stringbuf<_CharT, _Traits, _Alloc>::
@@ -235,25 +232,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     {
       const bool __testin = _M_mode & ios_base::in;
       const bool __testout = _M_mode & ios_base::out;
-      char_type* __end = __base + _M_string.size();
-      
+      char_type* __endg = __base + _M_string.size();
+      char_type* __endp = __base + _M_string.capacity();
+
+      if (__base != _M_string.data())
+       {
+         // setbuf: __i == size of buffer area (_M_string.size() == 0).
+         __endg += __i;
+         __i = 0;
+         __endp = __endg;
+       }
+
       if (__testin)
-       this->setg(__base, __base + __i, __end);
+       this->setg(__base, __base + __i, __endg);
       if (__testout)
        {
-         // If __base comes from setbuf we cannot trust capacity()
-         // to match the size of the buffer area:  in general, after
-         // Step 1 in setbuf, _M_string.capacity() >= __n.
-         if (__base == _M_string.data())
-           this->setp(__base, __base + _M_string.capacity());
-         else
-           this->setp(__base, __end);
+         this->setp(__base, __endp);
          this->pbump(__o);
          // egptr() always tracks the string end.  When !__testin,
          // for the correct functioning of the streambuf inlines
          // the other get area pointers are identical.
          if (!__testin)
-           this->setg(__end, __end, __end);
+           this->setg(__endg, __endg, __endg);
        }
     }
 
index 712bf7ba3c705061095929f571b9def41aca9844..f30c23bfeac193a4601f590f05ffa9fed0710b2d 100644 (file)
@@ -211,10 +211,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
            // things will quickly blow up.
            
            // Step 1: Destroy the current internal array.
-           _M_string.assign(__s, __n);
+           _M_string.clear();
            
            // Step 2: Use the external array.
-           _M_sync(__s, 0, 0);
+           _M_sync(__s, __n, 0);
          }
        return this;
       }