[Gmp-commit] /var/hg/gmp: Keep eofbit after istream read to the end.

mercurial at gmplib.org mercurial at gmplib.org
Wed Mar 9 17:46:31 CET 2011


details:   /var/hg/gmp/rev/ae522d3a27ab
changeset: 14018:ae522d3a27ab
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Wed Mar 09 17:46:08 2011 +0100
description:
Keep eofbit after istream read to the end.

diffstat:

 ChangeLog              |  11 +++++
 cxx/ismpf.cc           |   2 +-
 cxx/ismpq.cc           |   2 +-
 cxx/ismpznw.cc         |   2 +-
 tests/cxx/t-istream.cc |  92 +++++++++++++++++++++++++++++++++++++++++--------
 tests/cxx/t-misc.cc    |  24 ++++++------
 tests/cxx/t-ostream.cc |   4 +-
 7 files changed, 104 insertions(+), 33 deletions(-)

diffs (truncated from 441 to 300 lines):

diff -r d0a1227b5f35 -r ae522d3a27ab ChangeLog
--- a/ChangeLog	Wed Mar 09 17:39:18 2011 +0100
+++ b/ChangeLog	Wed Mar 09 17:46:08 2011 +0100
@@ -1,3 +1,14 @@
+2011-03-09  Marc Glisse  <marc.glisse at inria.fr>
+
+	* tests/cxx/t-ostream.cc: Use bool instead of int.
+	* tests/cxx/t-istream.cc: Likewise.
+	* tests/cxx/t-misc.cc: Likewise.
+
+	* cxx/ismpznw.cc: Don't clear eofbit.
+	* cxx/ismpq.cc: Likewise.
+	* cxx/ismpf.cc: Likewise.
+	* tests/cxx/t-istream.cc: Test accordingly.
+
 2011-03-09 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpn/x86/atom/sse2/bdiv_dbm1c.asm: New file.
diff -r d0a1227b5f35 -r ae522d3a27ab cxx/ismpf.cc
--- a/cxx/ismpf.cc	Wed Mar 09 17:39:18 2011 +0100
+++ b/cxx/ismpf.cc	Wed Mar 09 17:46:08 2011 +0100
@@ -120,7 +120,7 @@
   if (i.good()) // last character read was non-numeric
     i.putback(c);
   else if (i.eof() && ok) // stopped just before eof
-    i.clear();
+    i.clear(ios::eofbit);
 
   if (ok)
     ASSERT_NOCARRY (mpf_set_str(f, s.c_str(), base)); // extract the number
diff -r d0a1227b5f35 -r ae522d3a27ab cxx/ismpq.cc
--- a/cxx/ismpq.cc	Wed Mar 09 17:39:18 2011 +0100
+++ b/cxx/ismpq.cc	Wed Mar 09 17:46:08 2011 +0100
@@ -49,7 +49,7 @@
       if (i.good())
         i.putback(c);
       else if (i.eof())
-        i.clear();
+        i.clear(ios::eofbit);
     }
 
   return i;
diff -r d0a1227b5f35 -r ae522d3a27ab cxx/ismpznw.cc
--- a/cxx/ismpznw.cc	Wed Mar 09 17:39:18 2011 +0100
+++ b/cxx/ismpznw.cc	Wed Mar 09 17:46:08 2011 +0100
@@ -49,7 +49,7 @@
   if (i.good()) // last character read was non-numeric
     i.putback(c);
   else if (i.eof() && (ok || zero)) // stopped just before eof
-    i.clear();
+    i.clear(ios::eofbit);
 
   if (ok)
     ASSERT_NOCARRY (mpz_set_str (z, s.c_str(), base)); // extract the number
diff -r d0a1227b5f35 -r ae522d3a27ab tests/cxx/t-istream.cc
--- a/tests/cxx/t-istream.cc	Wed Mar 09 17:39:18 2011 +0100
+++ b/tests/cxx/t-istream.cc	Wed Mar 09 17:46:08 2011 +0100
@@ -37,7 +37,7 @@
 // since there's no mantissa digits, but g++ reads the whole thing and only
 // then decides it's bad.
 
-int   option_check_standard = 0;
+bool option_check_standard = false;
 
 
 // On some versions of g++ 2.96 it's been observed that putback() may leave
@@ -45,7 +45,7 @@
 // result of a bug, since for instance it's ok in g++ 2.95 and g++ 3.3.  We
 // detect the problem at runtime and disable affected checks.
 
-int putback_tellg_works = 1;
+bool putback_tellg_works = true;
 
 void
 check_putback_tellg (void)
@@ -63,7 +63,7 @@
     {
       cout << "Warning, istringstream has a bug: putback() doesn't update tellg().\n";;
       cout << "Tests on tellg() will be skipped.\n";
-      putback_tellg_works = 0;
+      putback_tellg_works = false;
     }
 }
 
@@ -132,7 +132,8 @@
   };
 
   mpz_t      got, want;
-  int        got_ok, want_ok;
+  bool       got_ok, want_ok;
+  bool       got_eof, want_eof;
   long       got_si, want_si;
   streampos  init_tellg, got_pos, want_pos;
 
@@ -141,8 +142,10 @@
 
   for (size_t i = 0; i < numberof (data); i++)
     {
+      size_t input_length = strlen (data[i].input);
       want_pos = (data[i].want_pos == -1
-                  ? strlen (data[i].input) : data[i].want_pos);
+                  ? input_length : data[i].want_pos);
+      want_eof = (want_pos == input_length);
 
       want_ok = (data[i].want != NULL);
 
@@ -159,7 +162,8 @@
           want_si = mpz_get_si (want);
 
           input >> got_si;
-          got_ok = (input ? 1 : 0);
+          got_ok = !input.fail();
+          got_eof = input.eof();
           input.clear();
           got_pos = input.tellg() - init_tellg;
 
@@ -175,6 +179,12 @@
               cout << "  got_si:  " << got_si << "\n";
               cout << "  want_si: " << want_si << "\n";
             }
+          if (want_ok && got_eof != want_eof)
+            {
+              WRONG ("stdc++ operator>> wrong EOF state, check_mpz");
+              cout << "  got_eof:  " << got_eof << "\n";
+              cout << "  want_eof: " << want_eof << "\n";
+            }
           if (putback_tellg_works && got_pos != want_pos)
             {
               WRONG ("stdc++ operator>> wrong position, check_mpz");
@@ -190,7 +200,8 @@
 
         mpz_set_ui (got, 0xDEAD);
         input >> got;
-        got_ok = (input ? 1 : 0);
+        got_ok = !input.fail();
+	got_eof = input.eof();
         input.clear();
         got_pos = input.tellg() - init_tellg;
 
@@ -208,6 +219,13 @@
             mpz_trace ("  want", want);
             abort ();
           }
+        if (want_ok && got_eof != want_eof)
+          {
+            WRONG ("mpz operator>> wrong EOF state");
+            cout << "  want_eof: " << want_eof << "\n";
+            cout << "  got_eof:  " << got_eof << "\n";
+            abort ();
+          }
         if (putback_tellg_works && got_pos != want_pos)
           {
             WRONG ("mpz operator>> wrong position");
@@ -271,10 +289,17 @@
 
     { " 123",  0, NULL,  (ios::fmtflags) 0 },   // not without skipws
     { " 123", -1, "123", ios::skipws },
+
+    { "123 /456",    3, "123",  (ios::fmtflags) 0 },
+    { "123/ 456",    4,  NULL,  (ios::fmtflags) 0 },
+    { "123/"    ,   -1,  NULL,  (ios::fmtflags) 0 },
+    { "123 /456",    3, "123",  ios::skipws },
+    { "123/ 456",    4,  NULL,  ios::skipws },
   };
 
   mpq_t      got, want;
-  int        got_ok, want_ok;
+  bool       got_ok, want_ok;
+  bool       got_eof, want_eof;
   long       got_si, want_si;
   streampos  init_tellg, got_pos, want_pos;
 
@@ -283,8 +308,10 @@
 
   for (size_t i = 0; i < numberof (data); i++)
     {
+      size_t input_length = strlen (data[i].input);
       want_pos = (data[i].want_pos == -1
-                  ? strlen (data[i].input) : data[i].want_pos);
+                  ? input_length : data[i].want_pos);
+      want_eof = (want_pos == input_length);
 
       want_ok = (data[i].want != NULL);
 
@@ -303,7 +330,8 @@
           want_si = mpz_get_si (mpq_numref(want));
 
           input >> got_si;
-          got_ok = (input ? 1 : 0);
+          got_ok = !input.fail();
+          got_eof = input.eof();
           input.clear();
           got_pos = input.tellg() - init_tellg;
 
@@ -319,6 +347,12 @@
               cout << "  got_si:  " << got_si << "\n";
               cout << "  want_si: " << want_si << "\n";
             }
+          if (want_ok && got_eof != want_eof)
+            {
+              WRONG ("stdc++ operator>> wrong EOF state, check_mpq");
+              cout << "  got_eof:  " << got_eof << "\n";
+              cout << "  want_eof: " << want_eof << "\n";
+            }
           if (putback_tellg_works && got_pos != want_pos)
             {
               WRONG ("stdc++ operator>> wrong position, check_mpq");
@@ -334,7 +368,8 @@
         mpq_set_si (got, 0xDEAD, 0xBEEF);
 
         input >> got;
-        got_ok = (input ? 1 : 0);
+        got_ok = !input.fail();
+	got_eof = input.eof();
         input.clear();
         got_pos = input.tellg() - init_tellg;
 
@@ -355,6 +390,13 @@
             mpq_trace ("  want", want);
             abort ();
           }
+        if (want_ok && got_eof != want_eof)
+          {
+            WRONG ("mpq operator>> wrong EOF state");
+            cout << "  want_eof: " << want_eof << "\n";
+            cout << "  got_eof:  " << got_eof << "\n";
+            abort ();
+          }
         if (putback_tellg_works && got_pos != want_pos)
           {
             WRONG ("mpq operator>> wrong position");
@@ -428,7 +470,8 @@
   };
 
   mpf_t      got, want;
-  int        got_ok, want_ok;
+  bool       got_ok, want_ok;
+  bool       got_eof, want_eof;
   double     got_d, want_d;
   streampos  init_tellg, got_pos, want_pos;
 
@@ -437,8 +480,10 @@
 
   for (size_t i = 0; i < numberof (data); i++)
     {
+      size_t input_length = strlen (data[i].input);
       want_pos = (data[i].want_pos == -1
-                  ? strlen (data[i].input) : data[i].want_pos);
+                  ? input_length : data[i].want_pos);
+      want_eof = (want_pos == input_length);
 
       want_ok = (data[i].want != NULL);
 
@@ -455,7 +500,8 @@
           init_tellg = input.tellg();
 
           input >> got_d;
-          got_ok = (input ? 1 : 0);
+          got_ok = !input.fail();
+          got_eof = input.eof();
           input.clear();
           got_pos = input.tellg() - init_tellg;
 
@@ -471,6 +517,12 @@
               cout << "  got:   " << got_d << "\n";
               cout << "  want:  " << want_d << "\n";
             }
+          if (want_ok && got_eof != want_eof)
+            {
+              WRONG ("stdc++ operator>> wrong EOF state, check_mpf");
+              cout << "  got_eof:  " << got_eof << "\n";
+              cout << "  want_eof: " << want_eof << "\n";
+            }
           if (putback_tellg_works && got_pos != want_pos)
             {
               WRONG ("stdc++ operator>> wrong position, check_mpf");
@@ -486,7 +538,8 @@
 
         mpf_set_ui (got, 0xDEAD);
         input >> got;
-        got_ok = (input ? 1 : 0);
+        got_ok = !input.fail();
+	got_eof = input.eof();
         input.clear();
         got_pos = input.tellg() - init_tellg;
 
@@ -504,6 +557,13 @@
             mpf_trace ("  want", want);
             abort ();
           }
+        if (want_ok && got_eof != want_eof)
+          {
+            WRONG ("mpf operator>> wrong EOF state");
+            cout << "  want_eof: " << want_eof << "\n";
+            cout << "  got_eof:  " << got_eof << "\n";
+            abort ();
+          }
         if (putback_tellg_works && got_pos != want_pos)
           {
             WRONG ("mpf operator>> wrong position");


More information about the gmp-commit mailing list