BIND 10 trac2369, updated. eb92bed532b40a0904f8397ba108d96f152abbbf [2369] Distinguish between EOF and failures in getChar()
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Nov 1 05:05:47 UTC 2012
The branch, trac2369 has been updated
via eb92bed532b40a0904f8397ba108d96f152abbbf (commit)
via 5ac6e8b56caad02994fd9352e3427e975e72f44a (commit)
from 710bac35169ec02b73a82cab2c4ce31874a8e440 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit eb92bed532b40a0904f8397ba108d96f152abbbf
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Nov 1 10:35:17 2012 +0530
[2369] Distinguish between EOF and failures in getChar()
commit 5ac6e8b56caad02994fd9352e3427e975e72f44a
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Nov 1 10:20:10 2012 +0530
[2369] Use a const variable's value for END_OF_STREAM state
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_lexer_inputsource.cc | 12 +++++++++---
src/lib/dns/master_lexer_inputsource.h | 18 +++++++++++++++++-
.../dns/tests/master_lexer_inputsource_unittest.cc | 12 ++++++------
3 files changed, 32 insertions(+), 10 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer_inputsource.cc b/src/lib/dns/master_lexer_inputsource.cc
index cd23d9c..a747dfb 100644
--- a/src/lib/dns/master_lexer_inputsource.cc
+++ b/src/lib/dns/master_lexer_inputsource.cc
@@ -63,16 +63,22 @@ InputSource::getChar() {
// getChar(). at_eof_ will be set then. We then simply return
// early.
if (at_eof_) {
- return -1;
+ return (END_OF_STREAM);
}
// We are not yet at EOF. Read from the stream.
int c = input_.get();
// Have we reached EOF now? If so, set at_eof_ and return early,
// but don't modify buffer_pos_ (which should still be equal to
// the size of buffer_).
- if (!input_.good()) {
+ if (input_.eof()) {
at_eof_ = true;
- return -1;
+ return (END_OF_STREAM);
+ }
+ // This has to come after the .eof() check as some
+ // implementations seem to check the eofbit also in .fail().
+ if (input_.fail()) {
+ isc_throw(ReadError,
+ "Error reading from the input stream: " << getName());
}
buffer_.push_back(c);
}
diff --git a/src/lib/dns/master_lexer_inputsource.h b/src/lib/dns/master_lexer_inputsource.h
index b9ac184..aec5395 100644
--- a/src/lib/dns/master_lexer_inputsource.h
+++ b/src/lib/dns/master_lexer_inputsource.h
@@ -79,8 +79,22 @@ public:
{}
};
+ /// \brief Exception thrown when we fail to read from the input
+ /// stream or file.
+ struct ReadError : public Unexpected {
+ ReadError(const char* file, size_t line, const char* what) :
+ Unexpected(file, line, what)
+ {}
+ };
+
+ /// \brief Returned by getChar() when end of stream is reached.
+ static const int END_OF_STREAM;
+
/// \brief Returns a single character from the input source. If end
- /// of file is reached, -1 is returned.
+ /// of file is reached, \c END_OF_STREAM is returned.
+ ///
+ /// \throws ReadError when reading from the input stream or file
+ /// fails.
int getChar();
/// \brief Skips backward a single character in the input
@@ -114,6 +128,8 @@ private:
std::istream& input_;
};
+const int InputSource::END_OF_STREAM = -1;
+
} // namespace master_lexer_internal
} // namespace dns
} // namespace isc
diff --git a/src/lib/dns/tests/master_lexer_inputsource_unittest.cc b/src/lib/dns/tests/master_lexer_inputsource_unittest.cc
index 27426b3..a6876d5 100644
--- a/src/lib/dns/tests/master_lexer_inputsource_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_inputsource_unittest.cc
@@ -71,7 +71,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
EXPECT_FALSE(source_.atEOF());
// This should cause EOF to be set.
- EXPECT_EQ(-1, source_.getChar());
+ EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
// Now, EOF should be set.
EXPECT_TRUE(source_.atEOF());
@@ -84,7 +84,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
EXPECT_FALSE(source_.atEOF());
// This should cause EOF to be set again.
- EXPECT_EQ(-1, source_.getChar());
+ EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
// Now, EOF should be set.
EXPECT_TRUE(source_.atEOF());
@@ -139,7 +139,7 @@ TEST_F(InputSourceTest, compact) {
EXPECT_FALSE(source_.atEOF());
// This should cause EOF to be set.
- EXPECT_EQ(-1, source_.getChar());
+ EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
// Now, EOF should be set.
EXPECT_TRUE(source_.atEOF());
@@ -158,7 +158,7 @@ TEST_F(InputSourceTest, compact) {
// Ungetting here must throw.
EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
- EXPECT_EQ(-1, source_.getChar());
+ EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
EXPECT_TRUE(source_.atEOF());
}
@@ -192,7 +192,7 @@ TEST_F(InputSourceTest, compactDuring) {
EXPECT_FALSE(source_.atEOF());
// This should cause EOF to be set.
- EXPECT_EQ(-1, source_.getChar());
+ EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
// Now, EOF should be set.
EXPECT_TRUE(source_.atEOF());
@@ -212,7 +212,7 @@ TEST_F(InputSourceTest, compactDuring) {
EXPECT_FALSE(source_.atEOF());
// This should cause EOF to be set.
- EXPECT_EQ(-1, source_.getChar());
+ EXPECT_EQ(InputSource::END_OF_STREAM, source_.getChar());
// Now, EOF should be set.
EXPECT_TRUE(source_.atEOF());
More information about the bind10-changes
mailing list