This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] Fix second half of libstdc++/6745
[gcc-patches removed from response, as requested.]
On Tuesday, November 19 2002, "Benjamin Kosnik" wrote to "Jonathan Lennox, pcarlini@unitus.it, gdr@integrable-solutions.net, libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org" saying:
> >A potentially much simpler solution occured to me. Could we declare that
> >Paolo's original patch (the one that started this thread) only applies to
> >cin? I.e., make the condition this:
> > if (__sbin == cin->rdbuf() && isatty(0))
>
> Hey y'all. I think a better way to think about this is that the
> streambuf is unbuffered. That way you don't have to deal with the isatty
> issue. (For unbuffered streams, _M_buf_size_opt == 0)
>
> If you do the checks based on that I think it will be cleaner.
The only downside to this it slows down stream << cin.rdbuf() unnecessarily
when cin is not a tty but sync_with_stdio is true. (Since that operation
"empties" stdin, you don't have to worry about synchronization with the C
APIs.)
The upside is that it allows user-defined types to set their preferred
buffering sizes, by calling setbuf(). It's also enormously cleaner and more
natural.
I think this is enough of a win that I agree this is the best way to go. I
didn't have my tree up to date when I was browsing the code originally, so I
didn't see the 8399 fix, or I think I would have suggested this from the
beginning.
So that's
__size = __sbin->_M_buf_size_opt > 0 ? __sbin->_M_buf_size_opt : 1;
in Paolo's original patch, just to avoid infinite loops for a zero-size
optimal buffer.
--
Jonathan Lennox
lennox at cs dot columbia dot edu