Author: thiru
Date: Wed Jul 4 09:10:24 2012
New Revision: 1357185
URL: http://svn.apache.org/viewvc?rev=1357185&view=rev
Log:
AVRO-1116. C++ code crashes on Data files with no data
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/c++/api/DataFile.hh
avro/trunk/lang/c++/impl/DataFile.cc
avro/trunk/lang/c++/test/DataFileTests.cc
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1357185&r1=1357184&r2=1357185&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Jul 4 09:10:24 2012
@@ -33,6 +33,8 @@ Avro 1.7.1 (unreleased)
AVRO-1115. C: Fix crash error in codec cleanup code. (Maxim Pugachev via
dcreager)
+ AVRO-1116. C++ code crashes on Data files with no data. (thiru)
+
Avro 1.7.0 (11 June 2012)
NEW FEATURES
Modified: avro/trunk/lang/c++/api/DataFile.hh
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/api/DataFile.hh?rev=1357185&r1=1357184&r2=1357185&view=diff
==============================================================================
--- avro/trunk/lang/c++/api/DataFile.hh (original)
+++ avro/trunk/lang/c++/api/DataFile.hh Wed Jul 4 09:10:24 2012
@@ -161,6 +161,7 @@ class AVRO_DECL DataFileReaderBase : boo
const std::auto_ptr<InputStream> stream_;
const DecoderPtr decoder_;
int64_t objectCount_;
+ bool eof_;
ValidSchema readerSchema_;
ValidSchema dataSchema_;
Modified: avro/trunk/lang/c++/impl/DataFile.cc
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/impl/DataFile.cc?rev=1357185&r1=1357184&r2=1357185&view=diff
==============================================================================
--- avro/trunk/lang/c++/impl/DataFile.cc (original)
+++ avro/trunk/lang/c++/impl/DataFile.cc Wed Jul 4 09:10:24 2012
@@ -151,7 +151,7 @@ void DataFileWriterBase::setMetadata(con
DataFileReaderBase::DataFileReaderBase(const char* filename) :
filename_(filename), stream_(fileInputStream(filename)),
- decoder_(binaryDecoder()), objectCount_(0)
+ decoder_(binaryDecoder()), objectCount_(0), eof_(false)
{
readHeader();
}
@@ -196,9 +196,12 @@ std::ostream& operator << (std::ostream&
bool DataFileReaderBase::hasMore()
{
- if (objectCount_ != 0) {
+ if (eof_) {
+ return false;
+ } else if (objectCount_ != 0) {
return true;
}
+
dataDecoder_->init(*dataStream_);
drain(*dataStream_);
DataFileSync s;
@@ -259,6 +262,7 @@ bool DataFileReaderBase::readDataBlock()
const uint8_t* p = 0;
size_t n = 0;
if (! stream_->next(&p, &n)) {
+ eof_ = true;
return false;
}
stream_->backup(n);
Modified: avro/trunk/lang/c++/test/DataFileTests.cc
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/test/DataFileTests.cc?rev=1357185&r1=1357184&r2=1357185&view=diff
==============================================================================
--- avro/trunk/lang/c++/test/DataFileTests.cc (original)
+++ avro/trunk/lang/c++/test/DataFileTests.cc Wed Jul 4 09:10:24 2012
@@ -44,6 +44,8 @@ using avro::ValidSchema;
using avro::GenericDatum;
using avro::GenericRecord;
+const int count = 1000;
+
template <typename T>
struct Complex {
T re;
@@ -150,7 +152,7 @@ public:
avro::DataFileWriter<ComplexInteger> df(filename, writerSchema, 100);
int64_t re = 3;
int64_t im = 5;
- for (int i = 0; i < 1000; ++i, re *= im, im += 3) {
+ for (int i = 0; i < count; ++i, re *= im, im += 3) {
ComplexInteger c(re, im);
df.write(c);
}
@@ -167,7 +169,7 @@ public:
c = GenericDatum(writerSchema.root());
GenericRecord& r = c.value<GenericRecord>();
- for (int i = 0; i < 1000; ++i, re *= im, im += 3) {
+ for (int i = 0; i < count; ++i, re *= im, im += 3) {
r.fieldAt(0) = re;
r.fieldAt(1) = im;
df.write(p);
@@ -179,7 +181,7 @@ public:
avro::DataFileWriter<ComplexDouble> df(filename, writerSchema, 100);
double re = 3.0;
double im = 5.0;
- for (int i = 0; i < 1000; ++i, re += im - 0.7, im += 3.1) {
+ for (int i = 0; i < count; ++i, re += im - 0.7, im += 3.1) {
ComplexDouble c(re, im);
df.write(c);
}
@@ -199,7 +201,7 @@ public:
im += 3;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
void testReadProjection() {
@@ -214,7 +216,7 @@ public:
im += 3;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
void testReaderGeneric() {
@@ -241,7 +243,7 @@ public:
im += 3;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
void testReaderGenericProjection() {
@@ -265,7 +267,7 @@ public:
im += 3;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
void testReadDouble() {
@@ -281,7 +283,7 @@ public:
im += 3.1;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
/**
@@ -304,7 +306,7 @@ public:
im += 3.1;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
/**
@@ -328,7 +330,7 @@ public:
im += 3.1;
++i;
}
- BOOST_CHECK_EQUAL(i, 1000);
+ BOOST_CHECK_EQUAL(i, count);
}
};