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: [v3] more istream::ignore cleanups


Benjamin Kosnik wrote:

Are those discussions recorded somewhere? In the LWG reflector? I would be
interested in the details: actually, strictly speaking, the whole LFS idea is not compatible with the C++ standard in the present form...


... on the archives of this list.

See:
http://gcc.gnu.org/ml/libstdc++/2004-09/msg00110.html
http://gcc.gnu.org/ml/libstdc++/2004-09/msg00126.html

etc, etc, etc.

Try google with (streamsize lfs site:gcc.gnu.org)


Ok, you convinced me that probably this is the most consistent solution.

The below is what I'm finishing regtesting.

Paolo.

//////////////////
2005-01-11  Paolo Carlini  <pcarlini@suse.de>
	    Benjamin Kosnik  <bkoz@redhat.com>

	* src/istream.cc (basic_istream<char>::ignore(streamsize),
	basic_istream<char>::ignore(streamsize, int_type),
	basic_istream<wchar_t>::ignore(streamsize),
	basic_istream<wchar_t>::ignore(streamsize, int_type)): In case
	more than numeric_limits<streamsize>::max() chars are skipped,
	set _M_gcount = max().
	* include/bits/istream.tcc (ignore(streamsize), ignore(streamsize,
	int_type)): Likewise; keep simple, don't forward.
diff -urN libstdc++-v3-orig/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
--- libstdc++-v3-orig/include/bits/istream.tcc	2005-01-11 17:21:24.000000000 +0100
+++ libstdc++-v3/include/bits/istream.tcc	2005-01-11 20:33:39.000000000 +0100
@@ -671,9 +671,6 @@
     basic_istream<_CharT, _Traits>::
     ignore(streamsize __n)
     {
-      if (__n == 1)
-	return ignore();
-
       _M_gcount = 0;
       sentry __cerb(*this, true);
       if (__cerb && __n > 0)
@@ -692,6 +689,7 @@
 	      // by definition, when more than 2G chars are actually ignored,
 	      // _M_gcount (the return value of gcount, that is) cannot be
 	      // really correct, being unavoidably too small.
+	      bool __large_ignore = false;
 	      while (true)
 		{
 		  while (_M_gcount < __n
@@ -702,11 +700,17 @@
 		    }
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof))
-		    _M_gcount = numeric_limits<streamsize>::min();
+		    {
+		      _M_gcount = numeric_limits<streamsize>::min();
+		      __large_ignore = true;
+		    }
 		  else
 		    break;
 		}
 
+	      if (__large_ignore)
+		_M_gcount = numeric_limits<streamsize>::max();
+
 	      if (traits_type::eq_int_type(__c, __eof))
                 __err |= ios_base::eofbit;
             }
@@ -723,9 +727,6 @@
     basic_istream<_CharT, _Traits>::
     ignore(streamsize __n, int_type __delim)
     {
-      if (traits_type::eq_int_type(__delim, traits_type::eof()))
-	return ignore(__n);
-
       _M_gcount = 0;
       sentry __cerb(*this, true);
       if (__cerb && __n > 0)
@@ -738,6 +739,7 @@
               int_type __c = __sb->sgetc();
 
 	      // See comment above.
+	      bool __large_ignore = false;
 	      while (true)
 		{
 		  while (_M_gcount < __n
@@ -750,16 +752,23 @@
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof)
 		      && !traits_type::eq_int_type(__c, __delim))
-		    _M_gcount = numeric_limits<streamsize>::min();
+		    {
+		      _M_gcount = numeric_limits<streamsize>::min();
+		      __large_ignore = true;
+		    }
 		  else
 		    break;
 		}
 
+	      if (__large_ignore)
+		_M_gcount = numeric_limits<streamsize>::max();
+
               if (traits_type::eq_int_type(__c, __eof))
                 __err |= ios_base::eofbit;
 	      else if (traits_type::eq_int_type(__c, __delim))
 		{
-		  ++_M_gcount;
+		  if (_M_gcount < numeric_limits<streamsize>::max())
+		    ++_M_gcount;
 		  __sb->sbumpc();
 		}
             }
diff -urN libstdc++-v3-orig/src/istream.cc libstdc++-v3/src/istream.cc
--- libstdc++-v3-orig/src/istream.cc	2005-01-11 17:23:00.000000000 +0100
+++ libstdc++-v3/src/istream.cc	2005-01-11 20:06:20.000000000 +0100
@@ -125,6 +125,7 @@
 	      int_type __c = __sb->sgetc();
 
 	      // See comment in istream.tcc.
+	      bool __large_ignore = false;
 	      while (true)
 		{
 		  while (_M_gcount < __n
@@ -147,11 +148,17 @@
 		    }
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof))
-		    _M_gcount = numeric_limits<streamsize>::min();
+		    {
+		      _M_gcount = numeric_limits<streamsize>::min();
+		      __large_ignore = true;
+		    }
 		  else
 		    break;
 		}
 
+	      if (__large_ignore)
+		_M_gcount = numeric_limits<streamsize>::max();
+
 	      if (traits_type::eq_int_type(__c, __eof))
 		__err |= ios_base::eofbit;
 	    }
@@ -183,6 +190,7 @@
 	      __streambuf_type* __sb = this->rdbuf();
 	      int_type __c = __sb->sgetc();
 
+	      bool __large_ignore = false;
 	      while (true)
 		{
 		  while (_M_gcount < __n
@@ -212,16 +220,23 @@
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof)
 		      && !traits_type::eq_int_type(__c, __delim))
-		    _M_gcount = numeric_limits<streamsize>::min();
+		    {
+		      _M_gcount = numeric_limits<streamsize>::min();
+		      __large_ignore = true;
+		    }
 		  else
 		    break;
 		}
 
+	      if (__large_ignore)
+		_M_gcount = numeric_limits<streamsize>::max();
+
 	      if (traits_type::eq_int_type(__c, __eof))
 		__err |= ios_base::eofbit;
 	      else if (traits_type::eq_int_type(__c, __delim))
 		{
-		  ++_M_gcount;
+		  if (_M_gcount < numeric_limits<streamsize>::max())
+		    ++_M_gcount;
 		  __sb->sbumpc();
 		}
 	    }
@@ -403,6 +418,7 @@
 	      __streambuf_type* __sb = this->rdbuf();
 	      int_type __c = __sb->sgetc();
 
+	      bool __large_ignore = false;
 	      while (true)
 		{
 		  while (_M_gcount < __n
@@ -425,11 +441,17 @@
 		    }
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof))
-		    _M_gcount = numeric_limits<streamsize>::min();
+		    {
+		      _M_gcount = numeric_limits<streamsize>::min();
+		      __large_ignore = true;
+		    }
 		  else
 		    break;
 		}
 
+	      if (__large_ignore)
+		_M_gcount = numeric_limits<streamsize>::max();
+
 	      if (traits_type::eq_int_type(__c, __eof))
 		__err |= ios_base::eofbit;
 	    }
@@ -461,6 +483,7 @@
 	      __streambuf_type* __sb = this->rdbuf();
 	      int_type __c = __sb->sgetc();
 
+	      bool __large_ignore = false;
 	      while (true)
 		{
 		  while (_M_gcount < __n
@@ -490,16 +513,23 @@
 		  if (__n == numeric_limits<streamsize>::max()
 		      && !traits_type::eq_int_type(__c, __eof)
 		      && !traits_type::eq_int_type(__c, __delim))
-		    _M_gcount = numeric_limits<streamsize>::min();
+		    {
+		      _M_gcount = numeric_limits<streamsize>::min();
+		      __large_ignore = true;
+		    }
 		  else
 		    break;
 		}
 
+	      if (__large_ignore)
+		_M_gcount = numeric_limits<streamsize>::max();
+
 	      if (traits_type::eq_int_type(__c, __eof))
 		__err |= ios_base::eofbit;
 	      else if (traits_type::eq_int_type(__c, __delim))
 		{
-		  ++_M_gcount;
+		  if (_M_gcount < numeric_limits<streamsize>::max())
+		    ++_M_gcount;
 		  __sb->sbumpc();
 		}
 	    }

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