This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch, RFC] Remove bogus fflush
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Andrea Arcangeli <andrea at suse dot de>, Nathan Myers <ncm at cantrip dot org>
- Date: Thu, 16 Sep 2004 18:45:44 +0200
- Subject: [Patch, RFC] Remove bogus fflush
Hi,
the below stems from private discussion with kernel developer Andrea
Arcangeli: while explaining various issues related to I/O, he pointed
out that the read/write primitives are *unbuffered*.
Now, turns out that the library still has some, essentially bogus, we
believe, fflush, remnants of the old __basic_file<> implementation,
used in 3.3, which exploited the stdio API (i.e., fread, fwrite,
fflush, and so on).
Indeed, the below regtests OK on x86 and x86_64 linux.
Anyone can spot something wrong/dangerous with it? Otherwise I will
apply it soon, say 24 hours, to mainline for wider testing.
Paolo.
////////////
2004-09-16 Paolo Carlini <pcarlini@suse.de>
Andrea Arcangeli <andrea@suse.de>
* config/io/basic_file_stdio.cc (__basic_file<>::close)): Don't
call unnecessarily sync, that is fflush: the library, since 3.4.0
does not use buffered fread/fwrite.
* include/bits/fstream.tcc (basic_filebuf<>::overflow): Likewise.
diff -prN libstdc++-v3-orig/config/io/basic_file_stdio.cc libstdc++-v3/config/io/basic_file_stdio.cc
*** libstdc++-v3-orig/config/io/basic_file_stdio.cc Mon Aug 30 13:33:54 2004
--- libstdc++-v3/config/io/basic_file_stdio.cc Thu Sep 16 18:04:21 2004
*************** namespace std
*** 259,281 ****
__basic_file* __ret = static_cast<__basic_file*>(NULL);
if (this->is_open())
{
! // In general, no need to zero errno in advance if checking
! // for error first. However, C89/C99 (at variance with IEEE
! // 1003.1, f.i.) do not mandate that fclose/fflush must set
! // errno upon error.
! int __err;
! errno = 0;
if (_M_cfile_created)
! do
! __err = fclose(_M_cfile);
! while (__err && errno == EINTR);
! else
! do
! __err = this->sync();
! while (__err && errno == EINTR);
if (!__err)
__ret = this;
- _M_cfile = 0;
}
return __ret;
}
--- 259,279 ----
__basic_file* __ret = static_cast<__basic_file*>(NULL);
if (this->is_open())
{
! int __err = 0;
if (_M_cfile_created)
! {
! // In general, no need to zero errno in advance if checking
! // for error first. However, C89/C99 (at variance with IEEE
! // 1003.1, f.i.) do not mandate that fclose must set errno
! // upon error.
! errno = 0;
! do
! __err = fclose(_M_cfile);
! while (__err && errno == EINTR);
! }
! _M_cfile = 0;
if (!__err)
__ret = this;
}
return __ret;
}
diff -prN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
*** libstdc++-v3-orig/include/bits/fstream.tcc Tue Sep 14 20:41:02 2004
--- libstdc++-v3/include/bits/fstream.tcc Thu Sep 16 17:07:20 2004
*************** namespace std
*** 396,403 ****
// Convert pending sequence to external representation,
// and output.
if (_M_convert_to_external(this->pbase(),
! this->pptr() - this->pbase())
! && (!__testeof || !_M_file.sync()))
{
_M_set_buffer(0);
__ret = traits_type::not_eof(__c);
--- 396,402 ----
// Convert pending sequence to external representation,
// and output.
if (_M_convert_to_external(this->pbase(),
! this->pptr() - this->pbase()))
{
_M_set_buffer(0);
__ret = traits_type::not_eof(__c);