libstdc++/16: ios initialization bug
Benjamin Kosnik
bkoz@cygnus.com
Thu Dec 2 11:07:00 GMT 1999
The following reply was made to PR libstdc++/16; it has been noted by GNATS.
From: Benjamin Kosnik <bkoz@cygnus.com>
To: "Gibbons, Chad" <Chad_Gibbons@bmc.com>
Cc: libstdc++-gnats@sourceware.cygnus.com
Subject: RE: libstdc++/16: ios initialization bug
Date: Thu, 2 Dec 1999 10:59:06 -0800 (PST)
hmmm. If this static init object is in the iostream header, then the
initialization of the iostream std objects will take place before people
can use things like cout/cin/cerr (as they'd need the declarations in the
iostream header).
If this is put into a source file, no such guarantees are in place. I
don't believe you sent me a small, reproducable test case for this (but
maybe I'm wrong) -- can you either correct me (I admit to being
particularly flaky about this bug report, sorry) or construct one and send
it to me?
-benjamin
On Thu, 2 Dec 1999, Gibbons, Chad wrote:
> Benjamin,
>
> Here's the patch I'm using. It seems to work fine on our code, but I wasn't
> able to run the testsuite at all (even before the patch!) to try it out...
>
> Index: bits/std_iostream.h
> ===================================================================
> RCS file: /cvs/libstdc++/libstdc++/bits/std_iostream.h,v
> retrieving revision 1.11
> diff -c -3 -p -d -r1.11 std_iostream.h
> *** std_iostream.h 1999/06/25 03:55:41 1.11
> --- std_iostream.h 1999/12/02 18:11:01
> *************** namespace std {
> *** 50,58 ****
> extern wostream wcerr;
> extern wostream wclog;
> #endif
> -
> - // For construction of filebuffers for cout, cin, cerr, clog et. al.
> - static ios_base::Init __ioinit;
> } // namespace std
>
> #endif /* _CPP_IOSTREAM */
> --- 50,55 ----
> Index: src/stdstreams.cc
> ===================================================================
> RCS file: /cvs/libstdc++/libstdc++/src/stdstreams.cc,v
> retrieving revision 1.11
> diff -c -3 -p -d -r1.11 stdstreams.cc
> *** stdstreams.cc 1999/06/25 03:56:04 1.11
> --- stdstreams.cc 1999/12/02 18:11:02
> *************** namespace std {
> *** 45,48 ****
> --- 45,51 ----
> wostream wclog(&__wfileinit);
> #endif
>
> + // For construction of filebuffers for cout, cin, cerr, clog et. al.
> + static ios_base::Init __ioinit;
> +
> } // std
>
>
>
> -----Original Message-----
> From: Benjamin Kosnik [ mailto:bkoz@cygnus.com ]
> Sent: Wednesday, December 01, 1999 11:53 PM
> To: Gibbons, Chad
> Subject: RE: libstdc++/16: ios initialization bug
>
>
>
> aggh. Sorry. I just got back. Can you resend your patch please? I got a
> bit behind.
>
> -benjamin
>
> On Wed, 1 Dec 1999, Gibbons, Chad wrote:
>
> > Hiya Benjamin,
> >
> > I sent you a message back last week or so with a pseudo-patch for this
> > problem. Would it be best for me to submit a patch in the way described at
> > http://sourceware.cygnus.com/libstdc++/17_intro/contribute.html ?
> >
> > By the way, the latest CVS sources still exhibit the behavior.
> >
> > Thanks again,
> > Chad Gibbons
> >
> > -----Original Message-----
> > From: Benjamin Kosnik [ mailto:bkoz@cygnus.com ]
> > Sent: Monday, November 22, 1999 1:06 PM
> > To: Chad_Gibbons@bmc.com
> > Cc: libstdc++-gnats@sourceware.cygnus.com
> > Subject: Re: libstdc++/16: ios initialization bug
> >
> >
> >
> > Chad.
> >
> > Thanks for your bug report. Unfortunately, the snapshot you are using is
> > a bit dated now, and some of the changes that have happened in the three
> > months since we last released affected the ios_base::init member. I
> > strongly urge you to check out the CVS sources and give it a whirl, as it
> > also includes such things as floating point output, and lots of
> > stringstream fixes.
> >
> >
> > > The constructor for this object creates the file buffers for the
> standard
> > I/O stream objects and sets their references via rdbuf. If, however, the
> > constructors for those standard I/O stream objects occurs after the first
> > > call to ios_base::Init::Init(), then the pointers to these buffers are
> > overridden and all stream operations via those objects are disabled.
> > >
> > > In practice, I have only seen this in extremely large projects (on the
> > order of 50,000 symbols). For whatever Reason, the compiler/linker selects
> > several modules that are initialized before the libstdc++ modules. These
> > modules
> > > have no static data, no references to static objects, and are themselves
> > not referenced statically -- they just happen to include <iostream>.
> > >
> > > In any event, it seems the library is relying on the compiler to
> construct
> > cout/cin/etc. before ios_base::Init is constructed, and that is something
> > the language doesn't guarantee (I believe).
> >
> > 27.3 iostream objects goes over this requirement. I belive CVS sources
> > now get this behavior correct, but know that the release you are using
> > has problems.
> >
> > -benjamin
> >
>
More information about the Libstdc++-prs
mailing list