diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2001-04-04 01:02:26 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2001-04-04 01:02:26 +0000 |
commit | 127644626f2d3fe441486566c2790a159f88654c (patch) | |
tree | 4edcf7a1442e75e1c8423db7adc2956cc77f6e87 | |
parent | 56713d55f778623e3b67ff6335ea3015c6da98ef (diff) | |
download | gcc-127644626f2d3fe441486566c2790a159f88654c.zip gcc-127644626f2d3fe441486566c2790a159f88654c.tar.gz gcc-127644626f2d3fe441486566c2790a159f88654c.tar.bz2 |
fstream.tcc: Add bool parameter to filebuf ctor.
2001-04-03 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/fstream.tcc: Add bool parameter to filebuf ctor.
* include/bits/ios_base.h(ios_base::Init): Remove _M_cout, _M_cin,
_M_cerr, _M_wcout, _M_wcin, _M_wcerr.
(ios_base::Init::_S_ios_create): New.
(ios_base::Init::_S_ios_destroy): New.
* include/bits/std_fstream.h: Change ctor args.
* src/ios.cc (ios_base::Init::Init): Use _S_ios_create.
(ios_base::Init::~Init): Use _S_ios_destroy.
(ios_base::sync_with_stdio): Use new members.
* testsuite/27_io/filebuf_members.cc: Fix calling conventions for
filebuf ctor.
From-SVN: r41072
-rw-r--r-- | libstdc++-v3/ChangeLog | 14 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/fstream.tcc | 13 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ios_base.h | 15 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/std_fstream.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/src/ios.cc | 112 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filebuf_members.cc | 2 |
6 files changed, 78 insertions, 80 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ebba1ec..09906da 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2001-04-03 Benjamin Kosnik <bkoz@redhat.com> + + * include/bits/fstream.tcc: Add bool parameter to filebuf ctor. + * include/bits/ios_base.h(ios_base::Init): Remove _M_cout, _M_cin, + _M_cerr, _M_wcout, _M_wcin, _M_wcerr. + (ios_base::Init::_S_ios_create): New. + (ios_base::Init::_S_ios_destroy): New. + * include/bits/std_fstream.h: Change ctor args. + * src/ios.cc (ios_base::Init::Init): Use _S_ios_create. + (ios_base::Init::~Init): Use _S_ios_destroy. + (ios_base::sync_with_stdio): Use new members. + * testsuite/27_io/filebuf_members.cc: Fix calling conventions for + filebuf ctor. + 2001-04-03 Peter Schmid <schmid@snake.iap.physik.tu-darmstadt.de> * include/backward/fstream.h: Expose streampos to global diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 93fe7a1..c1311e9 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -90,15 +90,22 @@ namespace std template<typename _CharT, typename _Traits> basic_filebuf<_CharT, _Traits>:: - basic_filebuf(__c_file_type* __f, ios_base::openmode __mode) + basic_filebuf(__c_file_type* __f, bool __s, ios_base::openmode __mode) : __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()), _M_state_beg(__state_type()), _M_last_overflowed(false) { _M_filebuf_init(); _M_file->sys_open(__f, __mode); if (this->is_open()) - _M_mode = __mode; - } + { + _M_mode = __mode; + if (!__s) + { + _M_allocate_buffers(); + _M_set_indeterminate(); + } + } + } template<typename _CharT, typename _Traits> basic_filebuf<_CharT, _Traits>::__filebuf_type* diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index ce68bf1..31b8d3a 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -295,17 +295,16 @@ namespace std public: Init(); ~Init(); + + static void + _S_ios_create(bool __sync); + + static void + _S_ios_destroy(); + private: static int _S_ios_base_init; static bool _S_synced_with_stdio; - filebuf* _M_cout; - filebuf* _M_cin; - filebuf* _M_cerr; -#ifdef _GLIBCPP_USE_WCHAR_T - wfilebuf* _M_wcout; - wfilebuf* _M_wcin; - wfilebuf* _M_wcerr; -#endif }; // Fmtflags state: diff --git a/libstdc++-v3/include/bits/std_fstream.h b/libstdc++-v3/include/bits/std_fstream.h index d715c23..63a86b9 100644 --- a/libstdc++-v3/include/bits/std_fstream.h +++ b/libstdc++-v3/include/bits/std_fstream.h @@ -86,7 +86,7 @@ namespace std basic_filebuf(); // Non-standard ctor: - basic_filebuf(__c_file_type* __f, ios_base::openmode __mode); + basic_filebuf(__c_file_type* __f, bool __s, ios_base::openmode __mode); virtual ~basic_filebuf() diff --git a/libstdc++-v3/src/ios.cc b/libstdc++-v3/src/ios.cc index 8926401..de577d6 100644 --- a/libstdc++-v3/src/ios.cc +++ b/libstdc++-v3/src/ios.cc @@ -133,63 +133,61 @@ namespace std ios_base::failure::what() const throw() { return _M_name; } + void + ios_base::Init::_S_ios_create(bool __sync) + { + // NB: The file std_iostream.h creates the four standard files + // with NULL buffers. At this point, we swap out these + new (&cout) ostream(new filebuf(stdout, __sync, ios_base::out)); + new (&cin) istream(new filebuf(stdin, __sync, ios_base::in)); + new (&cerr) ostream(new filebuf(stderr, __sync, ios_base::out)); + new (&clog) ostream(cerr.rdbuf()); + cin.tie(&cout); + cerr.flags(ios_base::unitbuf); + +#ifdef _GLIBCPP_USE_WCHAR_T + new (&wcout) wostream( new wfilebuf(stdout, __sync, ios_base::out)); + new (&wcin) wistream(new wfilebuf(stdin, __sync, ios_base::in)); + new (&wcerr) wostream(new wfilebuf(stderr, __sync, ios_base::out)); + new (&wclog) wostream(wcerr.rdbuf()); + wcin.tie(&wcout); + wcerr.flags(ios_base::unitbuf); +#endif + } + ios_base::Init::Init() { if (++_S_ios_base_init == 1) { - // NB: std_iostream.h creates the four standard files with - // NULL buffers. At this point, we swap out these placeholder - // objects for the properly-constructed ones - _M_cout = new filebuf(stdout, ios_base::out); - _M_cin = new filebuf(stdin, ios_base::in); - _M_cerr = new filebuf(stderr, ios_base::out); - new (&cout) ostream(_M_cout); - new (&cin) istream(_M_cin); - new (&cerr) ostream(_M_cerr); - new (&clog) ostream(_M_cerr); - cin.tie(&cout); - cerr.flags(ios_base::unitbuf); + // Standard streams default to synced with "C" operations. + ios_base::Init::_S_synced_with_stdio = true; + _S_ios_create(ios_base::Init::_S_synced_with_stdio); + } + } + void + ios_base::Init::_S_ios_destroy() + { + cout.flush(); + cerr.flush(); + clog.flush(); + delete cout.rdbuf(); + delete cin.rdbuf(); + delete cerr.rdbuf(); #ifdef _GLIBCPP_USE_WCHAR_T - _M_wcout = new wfilebuf(stdout, ios_base::out); - _M_wcin = new wfilebuf(stdin, ios_base::in); - _M_wcerr = new wfilebuf(stderr, ios_base::out); - new (&wcout) wostream(_M_wcout); - new (&wcin) wistream(_M_wcin); - new (&wcerr) wostream(_M_wcerr); - new (&wclog) wostream(_M_wcerr); - wcin.tie(&wcout); - wcerr.flags(ios_base::unitbuf); + wcout.flush(); + wcerr.flush(); + wclog.flush(); + delete wcout.rdbuf(); + delete wcin.rdbuf(); + delete wcerr.rdbuf(); #endif - ios_base::Init::_S_synced_with_stdio = true; - } } ios_base::Init::~Init() { if (--_S_ios_base_init == 0) - { - cout.flush(); - cerr.flush(); - clog.flush(); - delete _M_cout; - delete _M_cin; - delete _M_cerr; - _M_cout = NULL; - _M_cin = NULL; - _M_cerr = NULL; -#ifdef _GLIBCPP_USE_WCHAR_T - wcout.flush(); - wcerr.flush(); - wclog.flush(); - delete _M_wcout; - delete _M_wcin; - delete _M_wcerr; - _M_wcout = NULL; - _M_wcin = NULL; - _M_wcerr = NULL; -#endif - } + _S_ios_destroy(); } // 27.4.2.5 ios_base storage functions @@ -323,31 +321,11 @@ namespace std // currently synchronized. if (!__sync && __ret) { -#if 0 - // no longer need to do this - // Need to dispose of the buffers created at initialization. - __ioinit._M_cout->~filebuf(); - __ioinit._M_cin->~filebuf(); - __ioinit._M_cerr->~filebuf(); - __ioinit._M_cout = new filebuf(); - __ioinit._M_cin = new filebuf(); - __ioinit._M_cerr = new filebuf(); - __ioinit._M_cout->open("stdout", ios_base::out); - __ioinit._M_cin->open("stdin", ios_base::in); - __ioinit._M_cerr->open("stderr", ios_base::out); - cout.rdbuf(__ioinit._M_cout); - cin.rdbuf(__ioinit._M_cin); - cerr.rdbuf(__ioinit._M_cerr); - cerr.flags(ios_base::unitbuf); - clog.rdbuf(__ioinit._M_cerr); -#endif -#ifdef _GLIBCPP_USE_WCHAR_T -#endif ios_base::Init::_S_synced_with_stdio = false; + ios_base::Init::_S_ios_destroy(); + ios_base::Init::_S_ios_create(ios_base::Init::_S_synced_with_stdio); } - return __ret; } - } // namespace std diff --git a/libstdc++-v3/testsuite/27_io/filebuf_members.cc b/libstdc++-v3/testsuite/27_io/filebuf_members.cc index ecb5ae0..3eda6f5 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf_members.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf_members.cc @@ -52,7 +52,7 @@ test_01() FILE* f2 = fopen(name_01, "r"); VERIFY( f2 != NULL ); { - std::filebuf fb(f2, std::ios_base::in); + std::filebuf fb(f2, false, std::ios_base::in); } close_num = fclose(f2); VERIFY( close_num == 0 ); |