A little more help ;)
Paolo Carlini
pcarlini@unitus.it
Wed Mar 5 08:55:00 GMT 2003
Nathan Myers wrote:
>I would not expect fstat to consider stdin to be a file.
>(It looks like a "character special file".)
>
>Anyhow, the cin.peek() ought to call underflow(), which should do a
>::read(0,buf,8k), which should return 4 and put all four characters
>into the buffer. Then in_avail() should report them, and shouldn't
>call showmanyc() at all, so ::fstat() should not even be called.
>
Thanks. I'll investigate along these lines.
>(BTW, do you know the strace command? E.g. try "strace /bin/echo foo"
>and look at the last few lines.)
>
I know the command even if I don't use it so much.
In the specific case, I think that a plain gdb session should be able
to tell me what's going wrong: it's sure that showmanyc it's mistakenly
called, just I didn't (yet) put a breakpoint in the preceding cin.peek()
:(
>About the putback buffer: if a character has been put back
>in the separate putback buffer, in_avail() should return 1.
>After that character has been read out, in_avail() should
>find the buffer empty and call showmanyc(), which may fix up
>the pointers and then report what's in the regular buffer and
>any more characters it can discover. In other words, the
>putback buffer is involved in all virtuals, too.
>
Ok.
In fact, in underflow, a char is read from the buffer (and xsgetn
not called) only if M_pback_init is true, like this:
if (_M_pback_init)
{
_M_pback_destroy();
if (_M_in_cur < _M_in_end)
{
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
}
Paolo.
More information about the Libstdc++
mailing list