This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] PR 10975


The following is a patch attempting to addresss PR 10975.  There are a
couple of things going on here.  The patch changes all
[io]stringstreams to be considered open, even if the underlying string
is empty.  This will make tellg and tellp both return 0 instead of -1
on newly constructed [io]stringstreams.  The patch fixes up the tests
affected by this assumption.

The other bit is that the test for PR 2346 doesn't work with this
change.  It tests that tellg moves the put pointer for a
stringstream.  However, there is code implementing DR 135, which
confines tellg to only affect the get pointer.  I made the change in
the test.  It also means that 2346 would no longer be FIXED, but
INVALID.  I don't know why the test wasn't failing before.

With these test changes, passes without regressions on
i686-pc-linux-gnu.


2004-01-05  Jerry Quinn  <jlquinn@optonline.net>

	* include/bits/sstream.tcc (seekoff,seekpos): Remove capacity test.
	* testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc:
	Change tellg to tellp.
	* testsuite/27_io/basic_istream/tellg/char/1.cc,
	testsuite/27_io/basic_ostream/tellp/char/1.cc,
	testsuite/27_io/basic_ostream/tellp/char/2.cc: Initial
	position is now 0.

--- include/bits/sstream.tcc	5 Dec 2003 06:54:22 -0000	1.37
+++ include/bits/sstream.tcc	6 Jan 2004 02:31:38 -0000
@@ -139,7 +139,8 @@
       __testin &= !(__mode & ios_base::out);
       __testout &= !(__mode & ios_base::in);
 
-      if (_M_string.capacity() && (__testin || __testout || __testboth))
+      // Allow seeking to offset 0 in any direction in an empty stringbuf
+      if (__testin || __testout || __testboth)
 	{
 	  char_type* __beg = __testin ? this->eback() : this->pbase();
 
@@ -179,26 +180,24 @@
     seekpos(pos_type __sp, ios_base::openmode __mode)
     {
       pos_type __ret =  pos_type(off_type(-1));       
-      if (_M_string.capacity())
-	{
-	  off_type __pos (__sp);
-	  const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
-	  const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
-	  char_type* __beg = __testin ? this->eback() : this->pbase();
+      off_type __pos (__sp);
+      const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
+      const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
+      char_type* __beg = __testin ? this->eback() : this->pbase();
 	  
-	  _M_update_egptr();
+      _M_update_egptr();
 
-	  const bool __testpos = 0 <= __pos
-	                         && __pos <=  this->egptr() - __beg;
-	  if ((__testin || __testout) && __testpos)
-	    {
-	      if (__testin)
-		this->gbump((__beg + __pos) - this->gptr());
-	      if (__testout)
-                this->pbump((__beg + __pos) - this->pptr());
-	      __ret = pos_type(off_type(__pos));
-	    }
+      const bool __testpos = 0 <= __pos
+	&& __pos <=  this->egptr() - __beg;
+      if ((__testin || __testout) && __testpos)
+	{
+	  if (__testin)
+	    this->gbump((__beg + __pos) - this->gptr());
+	  if (__testout)
+	    this->pbump((__beg + __pos) - this->pptr());
+	  __ret = pos_type(off_type(__pos));
 	}
+
       return __ret;
     }
 
Index: testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc,v
retrieving revision 1.2
diff -u -r1.2 2346-sstream.cc
--- testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc	23 Sep 2003 20:03:09 -0000	1.2
+++ testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc	6 Jan 2004 02:31:39 -0000
@@ -36,13 +36,13 @@
   for (int j = 0; j < times; j++) 
     {
       bool test __attribute__((unused)) = true;
-      std::streampos begin = stream.tellg();
+      std::streampos begin = stream.tellp();
       
       for (int i = 0; i < times; ++i)
 	stream << j << '-' << i << s << '\n';
       
-      stream.seekg(begin);
-      std::streampos end = stream.tellg(); 
+      stream.seekp(begin);
+      std::streampos end = stream.tellp(); 
       std::streampos badpos = std::streampos(std::streambuf::off_type(-1));
     }
 }
@@ -52,7 +52,7 @@
   bool test __attribute__((unused)) = true;
 
   stream.clear();
-  stream.seekg(0, std::ios::beg);
+  stream.seekp(0, std::ios::beg);
   int i = 0;
   int loop = times * times + 2;
   while (i < loop)
Index: testsuite/27_io/basic_istream/tellg/char/1.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc,v
retrieving revision 1.2
diff -u -r1.2 1.cc
--- testsuite/27_io/basic_istream/tellg/char/1.cc	23 Sep 2003 20:03:10 -0000	1.2
+++ testsuite/27_io/basic_istream/tellg/char/1.cc	6 Jan 2004 02:31:39 -0000
@@ -37,22 +37,22 @@
   const char str_lit01[] = "istream_seeks-1.tst";
 
   // in
-  // test default ctors leave things in the same positions...
+  // istringstream is open, ifstream is not.
   istringstream ist1;
-  pos_type p3 = ist1.tellg();
+  pos_type p1 = ist1.tellg();
 
   ifstream ifs1;
-  pos_type p4 = ifs1.tellg();
+  pos_type p2 = ifs1.tellg();
 
-  VERIFY( p3 == p4 );
+  VERIFY( p1 != p2 );
 
   // in
   // test ctors leave things in the same positions...
   istringstream ist2("bob_marley:kaya");
-  p3 = ist2.tellg();
+  pos_type p3 = ist2.tellg();
 
   ifstream ifs2(str_lit01);
-  p4 = ifs2.tellg();
+  pos_type p4 = ifs2.tellg();
 
   VERIFY( p3 == p4 );
 }
Index: testsuite/27_io/basic_ostream/tellp/char/1.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc,v
retrieving revision 1.2
diff -u -r1.2 1.cc
--- testsuite/27_io/basic_ostream/tellp/char/1.cc	23 Sep 2003 20:03:15 -0000	1.2
+++ testsuite/27_io/basic_ostream/tellp/char/1.cc	6 Jan 2004 02:31:39 -0000
@@ -35,14 +35,14 @@
   const char str_lit01[] = "ostream_seeks-1.txt";
 
   // out
-  // test default ctors leave things in the same positions...
+  // ostringstream is already open, ofstream is not
   ostringstream ost1;
   pos_type p1 = ost1.tellp();
 
   ofstream ofs1;
   pos_type p2 = ofs1.tellp();
 
-  VERIFY( p1 == p2 );
+  VERIFY( p1 != p2 );
 
   // out
   // test ctors leave things in the same positions...
@@ -52,7 +52,7 @@
   ofstream ofs2(str_lit01);
   p2 = ofs2.tellp();
  
-  VERIFY( p1 == p2 );
+  VERIFY( p1 == p2);
 }
 
 int main()
Index: testsuite/27_io/basic_ostream/tellp/char/2.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc,v
retrieving revision 1.2
diff -u -r1.2 2.cc
--- testsuite/27_io/basic_ostream/tellp/char/2.cc	23 Sep 2003 20:03:15 -0000	1.2
+++ testsuite/27_io/basic_ostream/tellp/char/2.cc	6 Jan 2004 02:31:39 -0000
@@ -33,7 +33,8 @@
   ostringstream ost;
   pos_type pos1;
   pos1 = ost.tellp();
-  VERIFY( pos1 == pos_type(-1) );
+  // PR 10975
+  VERIFY( pos1 == pos_type(0) );
   ost << "RZA ";
   pos1 = ost.tellp();
   VERIFY( pos1 == pos_type(4) );


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