From 469550eb04a94073a477be716178a36e9cfa4bb9 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Wed, 10 Jan 2001 17:24:11 +0000 Subject: [PATCH] Fixes for libstdc++/1576 2001-01-09 Benjamin Kosnik Fixes for libstdc++/1576 * src/stdstreams.cc: Initialize with NULL filebuf. Delete file, move contents into.... * src/ios.cc: ...Here. Put defines for iostreams objects and initialization routines into one file to simplify DSO interaction. * include/bits/std_iostream.h: Touch. * include/bits/ios_base.h (_S_synched_with_stdio): Make static. * src/Makefile.am (sources): Remove stdstreams.cc. * src/Makefile.in: Regenerate. From-SVN: r38871 --- libstdc++-v3/ChangeLog | 16 +++++- libstdc++-v3/include/bits/ios_base.h | 2 +- libstdc++-v3/include/bits/std_iostream.h | 10 ++-- libstdc++-v3/src/Makefile.am | 6 +- libstdc++-v3/src/Makefile.in | 8 +-- libstdc++-v3/src/ios.cc | 73 +++++++++++------------- libstdc++-v3/src/stdstreams.cc | 48 ---------------- 7 files changed, 61 insertions(+), 102 deletions(-) delete mode 100644 libstdc++-v3/src/stdstreams.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 87cfab966a5..1b41104e137 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,11 +1,25 @@ +2001-01-09 Benjamin Kosnik + + + Fixes for libstdc++/1576 + * src/stdstreams.cc: Initialize with NULL filebuf. Delete + file, move contents into.... + * src/ios.cc: ...Here. Put defines for iostreams objects and + initialization routines into one file to simplify DSO interaction. + * include/bits/std_iostream.h: Touch. + * include/bits/ios_base.h (_S_synched_with_stdio): Make static. + * src/Makefile.am (sources): Remove stdstreams.cc. + * src/Makefile.in: Regenerate. + 2001-01-10 Gabriel Dos Reis * tests_flags.in (check_directory): Fix typo. 2001-01-09 Peter Schmid + * include/bits/std_complex.h: Fix a typo. -2001-01-10 Loren J. Rittle +2001-01-09 Loren J. Rittle * config/os/bsd/freebsd/bits/ctype_inline.h (is): (Make right code path:) Remove magic constants and restructure to handle diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index c5de5b8185c..6aea0429d7c 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -294,7 +294,7 @@ namespace std { ~Init(); private: static int _S_ios_base_init; - bool _M_synced_with_stdio; + static bool _S_synced_with_stdio; filebuf* _M_cout; filebuf* _M_cin; filebuf* _M_cerr; diff --git a/libstdc++-v3/include/bits/std_iostream.h b/libstdc++-v3/include/bits/std_iostream.h index b08d038046d..191e09d03ec 100644 --- a/libstdc++-v3/include/bits/std_iostream.h +++ b/libstdc++-v3/include/bits/std_iostream.h @@ -1,6 +1,6 @@ // Standard iostream objects -*- C++ -*- -// Copyright (C) 1997-1999 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -38,8 +38,8 @@ #include #include -namespace std { - +namespace std +{ extern istream cin; extern ostream cout; extern ostream cerr; @@ -55,4 +55,6 @@ namespace std { static ios_base::Init __ioinit; } // namespace std -#endif /* _CPP_IOSTREAM */ +#endif + + diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index 18acebe0951..a6e15d1c0eb 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -1,6 +1,6 @@ ## Makefile for the src subdirectory of the GNU C++ Standard library. ## -## Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. +## Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. ## ## This file is part of the libstdc++ version 3 distribution. ## Process this file with automake to produce Makefile.in. @@ -21,7 +21,7 @@ ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA. -## $Id: Makefile.am,v 1.61 2000/12/23 07:13:57 bkoz Exp $ +## $Id: Makefile.am,v 1.62 2001/01/04 04:21:42 bkoz Exp $ AUTOMAKE_OPTIONS = 1.3 gnits MAINT_CHARSET = latin1 @@ -176,7 +176,7 @@ sources = \ limitsMEMBERS.cc \ complex_io.cc \ stdexcept.cc bitset.cc \ - c++io.cc ios.cc stdstreams.cc strstream.cc \ + c++io.cc ios.cc strstream.cc \ locale.cc localename.cc codecvt.cc \ locale-inst.cc stl-inst.cc misc-inst.cc valarray-inst.cc string-inst.cc diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index cdb547cebc1..df23ffb6e27 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -170,7 +170,7 @@ std_headers = algorithm bitset complex deque fstream functional iomanip ios i build_headers = bits/std_limits.h bits/c++config.h bits/c++io.h bits/c++threads.h bits/atomicity.h bits/os_defines.h bits/ctype_base.h bits/ctype_noninline.h bits/ctype_inline.h -sources = limitsMEMBERS.cc complex_io.cc stdexcept.cc bitset.cc c++io.cc ios.cc stdstreams.cc strstream.cc locale.cc localename.cc codecvt.cc locale-inst.cc stl-inst.cc misc-inst.cc valarray-inst.cc string-inst.cc +sources = limitsMEMBERS.cc complex_io.cc stdexcept.cc bitset.cc c++io.cc ios.cc strstream.cc locale.cc localename.cc codecvt.cc locale-inst.cc stl-inst.cc misc-inst.cc valarray-inst.cc string-inst.cc wstring_sources = wstring-inst.cc @@ -258,9 +258,9 @@ libinst_wstring_la_LDFLAGS = libinst_wstring_la_LIBADD = libinst_wstring_la_OBJECTS = wstring-inst.lo libstdc___la_OBJECTS = limitsMEMBERS.lo complex_io.lo stdexcept.lo \ -bitset.lo c++io.lo ios.lo stdstreams.lo strstream.lo locale.lo \ -localename.lo codecvt.lo locale-inst.lo stl-inst.lo misc-inst.lo \ -valarray-inst.lo string-inst.lo +bitset.lo c++io.lo ios.lo strstream.lo locale.lo localename.lo \ +codecvt.lo locale-inst.lo stl-inst.lo misc-inst.lo valarray-inst.lo \ +string-inst.lo CXXFLAGS = @CXXFLAGS@ CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) CXXLD = $(CXX) diff --git a/libstdc++-v3/src/ios.cc b/libstdc++-v3/src/ios.cc index bac371ab52c..83ff7ca3aa5 100644 --- a/libstdc++-v3/src/ios.cc +++ b/libstdc++-v3/src/ios.cc @@ -32,7 +32,8 @@ // #include -#include +#include +#include #include namespace std @@ -104,9 +105,20 @@ namespace std const ios_base::seekdir ios_base::cur; const ios_base::seekdir ios_base::end; + const int ios_base::_S_local_words; int ios_base::Init::_S_ios_base_init = 0; + bool ios_base::Init::_S_synced_with_stdio = true; - const int ios_base::_S_local_words; + istream cin(NULL); + ostream cout(NULL); + ostream cerr(NULL); + ostream clog(NULL); +#ifdef _GLIBCPP_USE_WCHAR_T + wistream wcin(NULL); + wostream wcout(NULL); + wostream wcerr(NULL); + wostream wclog(NULL); +#endif ios_base::failure::failure(const string& __str) { @@ -126,40 +138,30 @@ namespace std if (++_S_ios_base_init == 1) { // NB: std_iostream.h creates the four standard files with - // default buffers. At this point, we swap out the default - // buffers for the properly-constructed ones, and dispose of - // the default buffers. - streambuf* __old; + // NULL buffers. At this point, we swap out these placeholder + // objects for the properly-constructed ones _M_cout = new filebuf(1, "stdout", ios_base::out); _M_cin = new filebuf(0, "stdin", ios_base::in); _M_cerr = new filebuf(2, "stderr", ios_base::out); - __old = cout.rdbuf(_M_cout); - __old->~streambuf(); - __old = cin.rdbuf(_M_cin); - __old->~streambuf(); + new (&cout) ostream(_M_cout); + new (&cin) istream(_M_cin); + new (&cerr) ostream(_M_cerr); + new (&clog) ostream(_M_cerr); cin.tie(&cout); - __old = cerr.rdbuf(_M_cerr); - __old->~streambuf(); cerr.flags(ios_base::unitbuf); - __old = clog.rdbuf(_M_cerr); - __old->~streambuf(); + #ifdef _GLIBCPP_USE_WCHAR_T - wstreambuf* __wold; _M_wcout = new wfilebuf(1, "stdout", ios_base::out); _M_wcin = new wfilebuf(0, "stdin", ios_base::in); _M_wcerr = new wfilebuf(2, "stderr", ios_base::out); - __wold = wcout.rdbuf(_M_wcout); - __wold->~wstreambuf(); - __wold = wcin.rdbuf(_M_wcin); - __wold->~wstreambuf(); - wcin.tie(&wcout); - __wold = wcerr.rdbuf(_M_wcerr); - __wold->~wstreambuf(); + new (&wcout) wostream(_M_wcout); + new (&wcin) wistream(_M_wcin); + new (&wcerr) wostream(_M_wcerr); + new (&wclog) wostream(_M_wcerr); + wcin.tie(&cout); wcerr.flags(ios_base::unitbuf); - __wold = wclog.rdbuf(_M_wcerr); - __wold->~wstreambuf(); #endif - _M_synced_with_stdio = true; + ios_base::Init::_S_synced_with_stdio = true; } } @@ -314,13 +316,15 @@ namespace std { #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS // 49. Underspecification of ios_base::sync_with_stdio - bool __ret = __ioinit._M_synced_with_stdio; + bool __ret = ios_base::Init::_S_synced_with_stdio; #endif // Turn off sync with C FILE* for cin, cout, cerr, clog iff // 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(); @@ -336,23 +340,10 @@ namespace std cerr.rdbuf(__ioinit._M_cerr); cerr.flags(ios_base::unitbuf); clog.rdbuf(__ioinit._M_cerr); +#endif #ifdef _GLIBCPP_USE_WCHAR_T - __ioinit._M_wcout->~wfilebuf(); - __ioinit._M_wcin->~wfilebuf(); - __ioinit._M_wcerr->~wfilebuf(); - __ioinit._M_wcout = new wfilebuf(); - __ioinit._M_wcin = new wfilebuf(); - __ioinit._M_wcerr = new wfilebuf(); - __ioinit._M_wcout->open("wstdout", ios_base::out); - __ioinit._M_wcin->open("wstdin", ios_base::in); - __ioinit._M_wcerr->open("wstderr", ios_base::out); - wcout.rdbuf(__ioinit._M_wcout); - wcin.rdbuf(__ioinit._M_wcin); - wcerr.rdbuf(__ioinit._M_wcerr); - wcerr.flags(ios_base::unitbuf); - wclog.rdbuf(__ioinit._M_wcerr); #endif - __ioinit._M_synced_with_stdio = false; + ios_base::Init::_S_synced_with_stdio = false; } return __ret; diff --git a/libstdc++-v3/src/stdstreams.cc b/libstdc++-v3/src/stdstreams.cc deleted file mode 100644 index cb69541cf94..00000000000 --- a/libstdc++-v3/src/stdstreams.cc +++ /dev/null @@ -1,48 +0,0 @@ - -// Copyright (C) 1997-1999 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include -#include -#include - -namespace std { - - filebuf __cfileinit; - istream cin(&__cfileinit); - ostream cout(&__cfileinit); - ostream cerr(&__cfileinit); - ostream clog(&__cfileinit); -#ifdef _GLIBCPP_USE_WCHAR_T - wfilebuf __wfileinit; - wistream wcin(&__wfileinit); - wostream wcout(&__wfileinit); - wostream wcerr(&__wfileinit); - wostream wclog(&__wfileinit); -#endif - -} // std -- 2.30.2