This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Clean up sbumpc, move back _M_buf_size, do not special case unbuffered _M_underflow...
On Mon, Jun 09, 2003 at 04:02:13PM -0500, Benjamin Kosnik wrote:
> >Also (but not so as to delay applying the patch), why do we care whether
> >the stream is_open()?
>
> See:
>
> 27.8.1.4 - Overridden virtual functions
>
> If setbuf(0,0) is called on a stream before any I/O has occured on that
> stream, the stream becomes unbuffered.
>
> Both v2 and v3 assume that unopened filebufs haven't had any io.
But that's wrong in two ways. First, it could have had I/O but then
been closed. That would be OK, because the behavior is implementation
defined then. The other case, where it's already open but no I/O has
happened yet, is a problem. We do nothing, then, but the standard says
it *must* become unbuffered.
The fact is, we aren't required to care whether I/O has been done.
If there's something in a buffer, we are free to discard it. In
practice, though, we should match some old behavior. A reasonable
test is to see if the buffers are not empty (i.e. gptr() != gback() ||
pptr() != pbase()) and do nothing, then. That preserves existing
behavior where permitted, meets the standard requirement, and is
reasonable.
Something I wanted to call attention to, though, was that not all
cases had been dealt with. My proposed code handles all cases
reasonably (including __s == 0 and __n != 0), and for backward
compatibility needs only to have the test for empty buffers added.
Nathan Myers
ncm-nospam@cantrip.org