C++ wrapper iostream input bug
Marc Glisse
marc.glisse at inria.fr
Tue Apr 20 07:44:04 CEST 2010
On Mon, 19 Apr 2010, Marc Glisse wrote:
> The easiest would probably be that I write a patch matching my understanding
> so you can try it.
Hello,
could you check that with the attached patch the behavior is ok? Note that
the patch only handles the mpz case, not mpq or mpf, and it may not be the
best way to do it, but it should show if the idea is the right one.
-------------- next part --------------
--- ../gmp/cxx/ismpznw.cc 2010-04-18 19:41:33.569715841 +0200
+++ ismpznw.cc 2010-04-19 21:46:35.399315699 +0200
@@ -44,12 +44,14 @@
}
base = __gmp_istream_set_base(i, c, zero, showbase); // select the base
+ ios::iostate ex=i.exceptions();
+ i.exceptions(ios::goodbit); // don't throw when we reach eof
__gmp_istream_set_digits(s, i, c, ok, base); // read the number
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); // clear failbit
if (ok)
ASSERT_NOCARRY (mpz_set_str (z, s.c_str(), base)); // extract the number
@@ -58,5 +60,6 @@
else
i.setstate(ios::failbit); // read failed
+ i.exceptions(ex);
return i;
}
More information about the gmp-bugs
mailing list