This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/1576: crash before entering main
- To: gcc-bugs at gcc dot gnu dot org, kainz at ilm dot com, gcc-gnats at gcc dot gnu dot org
- Subject: Re: libstdc++/1576: crash before entering main
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Wed, 10 Jan 2001 00:46:02 -0800
Here's a slightly different way of solving this, I believe, without
the ctor hacks and just putting all the std objects into one file
instead. Can you check it out please?
thanks,
benjamin
2001-01-09 Benjamin Kosnik <bkoz@fillmore.constant.com>
* src/stdstreams.cc: Initialize with NULL filebuf. Delete
file, move contents of this file 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.
Index: include/bits/ios_base.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/ios_base.h,v
retrieving revision 1.5
diff -c -p -r1.5 ios_base.h
*** ios_base.h 2001/01/06 02:44:10 1.5
--- ios_base.h 2001/01/10 08:40:40
*************** namespace std {
*** 294,300 ****
~Init();
private:
static int _S_ios_base_init;
! bool _M_synced_with_stdio;
filebuf* _M_cout;
filebuf* _M_cin;
filebuf* _M_cerr;
--- 294,300 ----
~Init();
private:
static int _S_ios_base_init;
! static bool _S_synced_with_stdio;
filebuf* _M_cout;
filebuf* _M_cin;
filebuf* _M_cerr;
Index: include/bits/std_iostream.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/std_iostream.h,v
retrieving revision 1.1
diff -c -p -r1.1 std_iostream.h
*** std_iostream.h 2000/10/05 11:27:01 1.1
--- std_iostream.h 2001/01/10 08:40:40
***************
*** 1,6 ****
// Standard iostream objects -*- C++ -*-
! // 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
--- 1,6 ----
// Standard iostream objects -*- C++ -*-
! // 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,45 ****
#include <bits/std_ostream.h>
#include <bits/std_istream.h>
! namespace std {
!
extern istream cin;
extern ostream cout;
extern ostream cerr;
--- 38,45 ----
#include <bits/std_ostream.h>
#include <bits/std_istream.h>
! namespace std
! {
extern istream cin;
extern ostream cout;
extern ostream cerr;
*************** namespace std {
*** 54,58 ****
// For construction of filebuffers for cout, cin, cerr, clog et. al.
static ios_base::Init __ioinit;
} // namespace std
- #endif /* _CPP_IOSTREAM */
--- 54,60 ----
// For construction of filebuffers for cout, cin, cerr, clog et. al.
static ios_base::Init __ioinit;
} // namespace std
+
+ #endif
+
Index: src/ios.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/ios.cc,v
retrieving revision 1.9
diff -c -p -r1.9 ios.cc
*** ios.cc 2001/01/06 02:44:11 1.9
--- ios.cc 2001/01/10 08:40:41
***************
*** 32,38 ****
//
#include <bits/std_ios.h>
! #include <bits/std_iostream.h>
#include <bits/std_fstream.h>
namespace std
--- 32,39 ----
//
#include <bits/std_ios.h>
! #include <bits/std_ostream.h>
! #include <bits/std_istream.h>
#include <bits/std_fstream.h>
namespace std
*************** namespace std
*** 104,112 ****
const ios_base::seekdir ios_base::cur;
const ios_base::seekdir ios_base::end;
int ios_base::Init::_S_ios_base_init = 0;
! const int ios_base::_S_local_words;
ios_base::failure::failure(const string& __str)
{
--- 105,124 ----
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;
! 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)
{
*************** namespace std
*** 126,165 ****
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;
_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();
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();
wcerr.flags(ios_base::unitbuf);
- __wold = wclog.rdbuf(_M_wcerr);
- __wold->~wstreambuf();
#endif
! _M_synced_with_stdio = true;
}
}
--- 138,167 ----
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(1, "stdout", ios_base::out);
_M_cin = new filebuf(0, "stdin", ios_base::in);
_M_cerr = new filebuf(2, "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);
!
#ifdef _GLIBCPP_USE_WCHAR_T
_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);
! 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);
#endif
! ios_base::Init::_S_synced_with_stdio = true;
}
}
*************** namespace std
*** 314,326 ****
{
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 49. Underspecification of ios_base::sync_with_stdio
! bool __ret = __ioinit._M_synced_with_stdio;
#endif
// Turn off sync with C FILE* for cin, cout, cerr, clog iff
// currently synchronized.
if (!__sync && __ret)
{
// Need to dispose of the buffers created at initialization.
__ioinit._M_cout->~filebuf();
__ioinit._M_cin->~filebuf();
--- 316,329 ----
{
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 49. Underspecification of ios_base::sync_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
// Need to dispose of the buffers created at initialization.
__ioinit._M_cout->~filebuf();
__ioinit._M_cin->~filebuf();
*************** namespace std
*** 336,358 ****
cerr.rdbuf(__ioinit._M_cerr);
cerr.flags(ios_base::unitbuf);
clog.rdbuf(__ioinit._M_cerr);
#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;
}
return __ret;
--- 339,348 ----
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;
}
return __ret;
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.62
diff -c -p -r1.62 Makefile.am
*** Makefile.am 2001/01/04 04:21:42 1.62
--- Makefile.am 2001/01/10 08:40:42
***************
*** 1,6 ****
## Makefile for the src subdirectory of the GNU C++ Standard library.
##
! ## Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
##
## This file is part of the libstdc++ version 3 distribution.
## Process this file with automake to produce Makefile.in.
--- 1,6 ----
## Makefile for the src subdirectory of the GNU C++ Standard library.
##
! ## 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.
*************** sources = \
*** 176,182 ****
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
--- 176,182 ----
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