This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why fixing 9533 doesn't fix 7744: revealed!


On Wed, Mar 05, 2003 at 09:55:04PM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
> 
> >The call to xsgetn is at the wrong level of abstraction.  It keeps
> >trying until it gets n characters, or EOF.  You want to call ::read()
> >in underflow(), and just go with as many characters as it returns.
> >(If it returns -1 and errno is EINTR you would call it again.)
> >Then, get rid of that isatty()!
> >
> Ok (too bad that I learned how to use some autoconf machinery for
> something which was not going to last much ;)

Don't worry, you'll use it for ::recv and its MSG_* flags, and for 
fstat and fstat64, and for S_ISREG vs S_IFREG.  Lucky you.

> To be honest, at the time Loren envisaged using read (and, at the time
> I didn't realy understand that :) but had also some perplexities:
> 
> >... POSIX IO. Someone skilled in the art could construct a
> >well-performing implementation of __basic_file<char>::xsgetn() that
> >could return short-reads [e.g. fread() (stdio) will only return a
> >short-read on error or EOF whereas read() (POSIX) will short-read
> >based on the current line discipline]. It is possible that this
> >alternate implementation should only be used when
> >ios::sync_with_stdio(false) was called (since the only portable way to
>                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >share stdio buffers is to make stdio calls).
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Do you believe I can go ahead and safely change the underlying
> implementation of xsgetn to use read instead of fread?

I just looked at config/io/basic_file_stdio.cc.  Ick.  I can't answer 
that.  Let's put it this way instead: in the sync_with_stdio code, you 
can freely replace the streambufs in cin, cout, cerr, and clog with 
ones that don't know about FILE or stdio, and which do proper ::read() 
and ::write() calls.  Or, at worst, you can set a flag in the ones you 
have, so they do the right thing then.  (You can do that first, and
plan to switch to the other scheme later.)

I do know that underflow() should not be implemented using xsgetn().
The version that must keep synchrony with stdin might reasonably use 
getc() and ungetc().  Whatever you do, you won't get both speed and 
correctness with a stdio-synchronized streambuf, and you'll just make 
yourself crazy trying, and make it impossible to get both on an
unsynchronized stream.  C's FILE interface is just too weak.

With libio you might be able to do a little better.

Nathan Myers
ncm-nospam at cantrip dot org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]