[Patch] Basic_streambuf::setg() and setp() (2nd take)

Paolo Carlini pcarlini@unitus.it
Thu May 8 05:00:00 GMT 2003


Benjamin Kosnik wrote:

>>Ok?
>>
>
>Yes, this is ok but you need to do sstream and stringbuf::setbuf as well.
>
>Also, 
>
>+	  if (!(this->_M_mode & ios_base::in))
>+	    this->_M_mode = this->_M_mode | ios_base::in;
>+	  if (!(this->_M_mode & ios_base::out))
>+	    this->_M_mode = this->_M_mode | ios_base::out;
>
>can probably just be
>
>+           // So that the replacement buffer can actually be used.
>+	    this->_M_mode =| ios_base::in;
>+	    this->_M_mode =| ios_base::out;
>
Thanks Benjamin.

However, notice (my third thought, similar to the first one ;)
that this commit would actually _change_ (improve?) the current
behaviour!

In fact, currently we have that, in basic_filebuf::setbuf():

      this->_M_buf = __s;
      this->_M_buf_size = __n;
      _M_set_indeterminate();

but, _M_set_[in]determinate():

      void
      _M_set_determinate(off_type __off)
      {
        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 (__testout)
          {
            this->setp(this->_M_buf, this->_M_buf + this->_M_buf_size);
            this->_M_out_lim += __off;
          }
        _M_filepos = this->_M_buf + __off;
      }

therefore, setg and setp are _not_ called _at all_ if __testin
(__testout, respectively) is false!

What do we really want?

Paolo.



More information about the Libstdc++ mailing list