OSDN Git Service

2011-05-26 Jonathan Wakely <jwakely.gcc@gmail.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / istream.cc
index 0f24340..f161016 100644 (file)
@@ -1,11 +1,12 @@
 // Input streams -*- C++ -*-
 
-// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+// 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)
+// Free Software Foundation; either version 3, or (at your option)
 // any later version.
 
 // This library is distributed in the hope that it will be useful,
 // 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
 
-// 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.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
 
 //
 // ISO C++ 14882: 27.6.1  Input streams
@@ -33,7 +29,9 @@
 
 #include <istream>
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<>
     basic_istream<char>&
@@ -41,11 +39,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     getline(char_type* __s, streamsize __n, char_type __delim)
     {
       _M_gcount = 0;
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+      ios_base::iostate __err = ios_base::goodbit;
       sentry __cerb(*this, true);
       if (__cerb)
        {
-          try
+          __try
            {
              const int_type __idelim = traits_type::to_int_type(__delim);
              const int_type __eof = traits_type::eof();
@@ -69,7 +67,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                        __size = __p - __sb->gptr();
                      traits_type::copy(__s, __sb->gptr(), __size);
                      __s += __size;
-                     __sb->gbump(__size);
+                     __sb->__safe_gbump(__size);
                      _M_gcount += __size;
                      __c = __sb->sgetc();
                    }
@@ -91,7 +89,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              else
                __err |= ios_base::failbit;
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            { this->_M_setstate(ios_base::badbit); }
        }
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -115,12 +118,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
       _M_gcount = 0;
       sentry __cerb(*this, true);
-      if (__cerb && __n > 0)
+      if (__n > 0 && __cerb)
        {
-         ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
-         try
+         ios_base::iostate __err = ios_base::goodbit;
+         __try
            {
-             const char_type __cdelim = traits_type::to_char_type(__delim);          
+             const char_type __cdelim = traits_type::to_char_type(__delim);
              const int_type __eof = traits_type::eof();
              __streambuf_type* __sb = this->rdbuf();
              int_type __c = __sb->sgetc();
@@ -142,7 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                                                   __cdelim);
                          if (__p)
                            __size = __p - __sb->gptr();
-                         __sb->gbump(__size);
+                         __sb->__safe_gbump(__size);
                          _M_gcount += __size;
                          __c = __sb->sgetc();
                        }
@@ -177,7 +180,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                  __sb->sbumpc();
                }
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            { this->_M_setstate(ios_base::badbit); }
          if (__err)
            this->setstate(__err);
@@ -197,11 +205,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typedef __istream_type::__ctype_type     __ctype_type;
 
       streamsize __extracted = 0;
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+      ios_base::iostate __err = ios_base::goodbit;
       __istream_type::sentry __cerb(__in, false);
       if (__cerb)
        {
-         try
+         __try
            {
              // Figure out how many characters to extract.
              streamsize __num = __in.width();
@@ -231,7 +239,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                - __sb->gptr());
                      __traits_type::copy(__s, __sb->gptr(), __size);
                      __s += __size;
-                     __sb->gbump(__size);
+                     __sb->__safe_gbump(__size);
                      __extracted += __size;
                      __c = __sb->sgetc();
                    }
@@ -251,7 +259,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              *__s = __char_type();
              __in.width(0);
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             __in._M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            { __in._M_setstate(ios_base::badbit); }
        }
       if (!__extracted)
@@ -275,11 +288,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typedef __string_type::size_type         __size_type;
 
       __size_type __extracted = 0;
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+      ios_base::iostate __err = ios_base::goodbit;
       __istream_type::sentry __cerb(__in, false);
       if (__cerb)
        {
-         try
+         __try
            {
              __str.erase();
              const streamsize __w = __in.width();
@@ -305,7 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                             __sb->gptr() + __size)
                                - __sb->gptr());
                      __str.append(__sb->gptr(), __size);
-                     __sb->gbump(__size);
+                     __sb->__safe_gbump(__size);
                      __extracted += __size;
                      __c = __sb->sgetc();
                    }
@@ -321,7 +334,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                __err |= ios_base::eofbit;
              __in.width(0);
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             __in._M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            {
              // _GLIBCXX_RESOLVE_LIB_DEFECTS
              // 91. Description of operator>> and getline() for string<>
@@ -352,11 +370,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
       __size_type __extracted = 0;
       const __size_type __n = __str.max_size();
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+      ios_base::iostate __err = ios_base::goodbit;
       __istream_type::sentry __cerb(__in, true);
       if (__cerb)
        {
-         try
+         __try
            {
              __str.erase();
              const __int_type __idelim = __traits_type::to_int_type(__delim);
@@ -379,7 +397,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                      if (__p)
                        __size = __p - __sb->gptr();
                      __str.append(__sb->gptr(), __size);
-                     __sb->gbump(__size);
+                     __sb->__safe_gbump(__size);
                      __extracted += __size;
                      __c = __sb->sgetc();
                    }
@@ -401,7 +419,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              else
                __err |= ios_base::failbit;
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             __in._M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            {
              // _GLIBCXX_RESOLVE_LIB_DEFECTS
              // 91. Description of operator>> and getline() for string<>
@@ -423,11 +446,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     getline(char_type* __s, streamsize __n, char_type __delim)
     {
       _M_gcount = 0;
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+      ios_base::iostate __err = ios_base::goodbit;
       sentry __cerb(*this, true);
       if (__cerb)
        {
-          try
+          __try
            {
              const int_type __idelim = traits_type::to_int_type(__delim);
              const int_type __eof = traits_type::eof();
@@ -451,7 +474,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                        __size = __p - __sb->gptr();
                      traits_type::copy(__s, __sb->gptr(), __size);
                      __s += __size;
-                     __sb->gbump(__size);
+                     __sb->__safe_gbump(__size);
                      _M_gcount += __size;
                      __c = __sb->sgetc();
                    }
@@ -473,7 +496,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              else
                __err |= ios_base::failbit;
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            { this->_M_setstate(ios_base::badbit); }
        }
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -497,12 +525,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
       _M_gcount = 0;
       sentry __cerb(*this, true);
-      if (__cerb && __n > 0)
+      if (__n > 0 && __cerb)
        {
-         ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
-         try
+         ios_base::iostate __err = ios_base::goodbit;
+         __try
            {
-             const char_type __cdelim = traits_type::to_char_type(__delim);          
+             const char_type __cdelim = traits_type::to_char_type(__delim);
              const int_type __eof = traits_type::eof();
              __streambuf_type* __sb = this->rdbuf();
              int_type __c = __sb->sgetc();
@@ -524,7 +552,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                                                   __cdelim);
                          if (__p)
                            __size = __p - __sb->gptr();
-                         __sb->gbump(__size);
+                         __sb->__safe_gbump(__size);
                          _M_gcount += __size;
                          __c = __sb->sgetc();
                        }
@@ -559,7 +587,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                  __sb->sbumpc();
                }
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            { this->_M_setstate(ios_base::badbit); }
          if (__err)
            this->setstate(__err);
@@ -583,11 +616,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
       __size_type __extracted = 0;
       const __size_type __n = __str.max_size();
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+      ios_base::iostate __err = ios_base::goodbit;
       __istream_type::sentry __cerb(__in, true);
       if (__cerb)
        {
-         try
+         __try
            {
              __str.erase();
              const __int_type __idelim = __traits_type::to_int_type(__delim);
@@ -610,7 +643,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                      if (__p)
                        __size = __p - __sb->gptr();
                      __str.append(__sb->gptr(), __size);
-                     __sb->gbump(__size);
+                     __sb->__safe_gbump(__size);
                      __extracted += __size;
                      __c = __sb->sgetc();
                    }
@@ -632,7 +665,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
              else
                __err |= ios_base::failbit;
            }
-         catch(...)
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             __in._M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
            {
              // _GLIBCXX_RESOLVE_LIB_DEFECTS
              // 91. Description of operator>> and getline() for string<>
@@ -648,4 +686,5 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     }
 #endif
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace