Recent strstream regression: reversion needed?

Benjamin Kosnik bkoz@redhat.com
Wed Jun 5 01:25:00 GMT 2002


I'm convinced that removing the strstream code and just typedefing
strstream to stringstream<char>, istrstream to istringstream<char>,
ostrstream to ostringstream<char>, etc,  would work much better than the
present solution. I think it was discussed but I'm not quite sure why
the current solution is in place instead.

In addition, this stuff should not be in std::.

I'll add that to the TODO list as an ABI-breaking item to consider.

> I see the point of your patch and, whereas I'm still convinced that 
> simply returning to the old code would be a simpler and cleaner
> solution (note that, in the old code, ~strstreambuf() *calls*
> _M_free(eback()); therefore the memory *is* deallocated) I was
> confident that your patch would work.

The problem is when setbuf is used with a user-defined buffer. That's
when things get lost, and why using eback is a bad idea.

> However, to my puzzlement, your patch doesn't work for a modified 
> testcase writing more, say the first 1000 integers and we are back to
> a segfault:
> 
> #include <strstream.h>
> 
> int main()
> {
>    strstream s;
>    for (unsigned i=0 ; i!= 1000 ; ++i)
>       s << i << std::endl;
>    s << std::ends;
> 
>    return 0;
> }

I'll look at this, but I'll be travelling the next couple of days.

-benjamin



More information about the Libstdc++ mailing list