This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

re: [Patch] Fix libstdc++/9563


From: Paolo Carlini <pcarlini at unitus dot it>

> 
> 2003-02-12  Paolo Carlini  <pcarlini@unitus.it>
> 
> 	PR libstdc++/9563
> 	* include/bits/ostream.tcc (sentry::sentry): Check
> 	the state of the stream after the preparation.
> 	* testsuite/27_io/ostream_sentry.cc (test02): Add.
> 
> diff -urN libstdc++-v3-orig/include/bits/ostream.tcc libstdc++-v3/include/bits/ostream.tcc
> --- libstdc++-v3-orig/include/bits/ostream.tcc	2003-02-04 21:56:49.000000000 +0100
> +++ libstdc++-v3/include/bits/ostream.tcc	2003-02-12 14:33:40.000000000 +0100
> @@ -41,11 +41,19 @@
>    template<typename _CharT, typename _Traits>
>      basic_ostream<_CharT, _Traits>::sentry::
>      sentry(basic_ostream<_CharT,_Traits>& __os)
> -    : _M_ok(__os.good()), _M_os(__os)
> +    : _M_os(__os)
>      {
> -      // XXX MT 
> -      if (_M_ok && __os.tie())
> -	__os.tie()->flush();  
> +      // XXX MT
> +      if (__os.good() && __os.tie())
> +	__os.tie()->flush();
> +
> +      if (__os.good())
> +	_M_ok = true;
> +      else
> +	{
> +	  _M_ok = false;
> +	  __os.setstate(ios_base::failbit);
> +	}
>      }

This looks like it's going to slow down the common path by causing two tests
of good().

How about:


template<typename _CharT, typename _Traits>
  basic_ostream<_CharT, _Traits>::sentry::
  sentry(basic_ostream<_CharT,_Traits>& __os)
  : _M_ok(true), _M_os(__os)
if (__os.good())
{
  if (__os.tie())
  {
    __os.tie()->flush();
    if (!__os.good())
      _M_failed()
  }
}
else
  _M_failed();


template<typename _CharT, typename _Traits>
  void
  basic_ostream<_CharT, _Traits>::sentry::_M_failed()
  {
    _M_ok = false;
    __os.setstate(ios_base::failbit);
  }


Seems like this should reduce the impact of the extra required checking.

Jerry Quinn


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]