mirror of git://gcc.gnu.org/git/gcc.git
std_fstream.h (basic_filebuf::sync): Hoist unconditional flush on lower-layer handle to here...
* include/std/std_fstream.h (basic_filebuf::sync): Hoist unconditional flush on lower-layer handle to here... * include/bits/fstream.tcc (basic_filebuf::_M_really_overflow): ...from here. Optimize remaining _M_file.sync() call pattern. * testsuite/27_io/narrow_stream_objects.cc (test04): New test. (test05): Likewise. From-SVN: r52699
This commit is contained in:
parent
b602511f62
commit
9385d9cb0d
|
|
@ -1,3 +1,12 @@
|
||||||
|
2002-04-23 Loren J. Rittle <ljrittle@acm.org>
|
||||||
|
|
||||||
|
* include/std/std_fstream.h (basic_filebuf::sync): Hoist
|
||||||
|
unconditional flush on lower-layer handle to here...
|
||||||
|
* include/bits/fstream.tcc (basic_filebuf::_M_really_overflow):
|
||||||
|
...from here. Optimize remaining _M_file.sync() call pattern.
|
||||||
|
* testsuite/27_io/narrow_stream_objects.cc (test04): New test.
|
||||||
|
(test05): Likewise.
|
||||||
|
|
||||||
2002-04-23 Jason Merrill <jason@redhat.com>
|
2002-04-23 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
* include/bits/fstream.tcc (basic_filebuf::seekoff): Fix for
|
* include/bits/fstream.tcc (basic_filebuf::seekoff): Fix for
|
||||||
|
|
|
||||||
|
|
@ -476,16 +476,20 @@ namespace std
|
||||||
__elen, __plen);
|
__elen, __plen);
|
||||||
|
|
||||||
// Convert pending sequence to external representation, output.
|
// Convert pending sequence to external representation, output.
|
||||||
|
// If eof, then just attempt sync.
|
||||||
if (!traits_type::eq_int_type(__c, traits_type::eof()))
|
if (!traits_type::eq_int_type(__c, traits_type::eof()))
|
||||||
{
|
{
|
||||||
char_type __pending = traits_type::to_char_type(__c);
|
char_type __pending = traits_type::to_char_type(__c);
|
||||||
_M_convert_to_external(&__pending, 1, __elen, __plen);
|
_M_convert_to_external(&__pending, 1, __elen, __plen);
|
||||||
}
|
|
||||||
|
|
||||||
// Last, sync internal and external buffers.
|
// User code must flush when switching modes (thus don't sync).
|
||||||
// NB: Need this so that external byte sequence reflects
|
if (__elen == __plen)
|
||||||
// internal buffer plus pending sequence.
|
{
|
||||||
if (__elen == __plen && !_M_file.sync())
|
_M_set_indeterminate();
|
||||||
|
__ret = traits_type::not_eof(__c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!_M_file.sync())
|
||||||
{
|
{
|
||||||
_M_set_indeterminate();
|
_M_set_indeterminate();
|
||||||
__ret = traits_type::not_eof(__c);
|
__ret = traits_type::not_eof(__c);
|
||||||
|
|
|
||||||
|
|
@ -204,14 +204,16 @@ namespace std
|
||||||
|
|
||||||
// Make sure that the internal buffer resyncs its idea of
|
// Make sure that the internal buffer resyncs its idea of
|
||||||
// the file position with the external file.
|
// the file position with the external file.
|
||||||
if (__testput && !_M_file.sync())
|
if (__testput)
|
||||||
{
|
{
|
||||||
// Need to restore current position after the write.
|
// Need to restore current position after the write.
|
||||||
off_type __off = _M_out_cur - _M_out_end;
|
off_type __off = _M_out_cur - _M_out_end;
|
||||||
_M_really_overflow();
|
_M_really_overflow(); // _M_file.sync() will be called within
|
||||||
if (__off)
|
if (__off)
|
||||||
_M_file.seekoff(__off, ios_base::cur);
|
_M_file.seekoff(__off, ios_base::cur);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
_M_file.sync();
|
||||||
_M_last_overflowed = false;
|
_M_last_overflowed = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,38 @@ void test03()
|
||||||
cout << "i == " << i << endl;
|
cout << "i == " << i << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interactive test, to be exercised as follows:
|
||||||
|
// assign stderr to stdout in shell command line,
|
||||||
|
// pipe stdout to cat process and/or redirect stdout to file.
|
||||||
|
// "hello fine world\n" should be written to stdout in proper order.
|
||||||
|
// This is a version of the scott snyder test taken from:
|
||||||
|
// http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html
|
||||||
|
void test04()
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
cout << "hello ";
|
||||||
|
cout.flush ();
|
||||||
|
cerr << "fine ";
|
||||||
|
cerr.flush ();
|
||||||
|
cout << "world" << endl;
|
||||||
|
cout.flush ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interactive test, to be exercised as follows:
|
||||||
|
// run test under truss(1) or strace(1). Look at
|
||||||
|
// size and pattern of write system calls.
|
||||||
|
// Should be 2 or 3 write(1,[...]) calls when run interactively
|
||||||
|
// depending upon buffering mode enforced.
|
||||||
|
void test05()
|
||||||
|
{
|
||||||
|
std::cout << "hello" << ' ' << "world" <<std::endl;
|
||||||
|
std::cout << "Enter your name: ";
|
||||||
|
std::string s;
|
||||||
|
std::cin >> s;
|
||||||
|
std::cout << "hello " << s << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|
@ -120,5 +152,7 @@ main()
|
||||||
|
|
||||||
// test02();
|
// test02();
|
||||||
// test03();
|
// test03();
|
||||||
|
// test04();
|
||||||
|
// test05();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue