avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject svn commit: r1182350 - in /avro/trunk: CHANGES.txt lang/c++/api/Stream.hh lang/c++/test/CodecTests.cc
Date Wed, 12 Oct 2011 13:15:19 GMT
Author: thiru
Date: Wed Oct 12 13:15:18 2011
New Revision: 1182350

URL: http://svn.apache.org/viewvc?rev=1182350&view=rev
Log:
AVRO-869. Lifetimes of streams and encoder/decoders not managed propertly

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c++/api/Stream.hh
    avro/trunk/lang/c++/test/CodecTests.cc

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1182350&r1=1182349&r2=1182350&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Oct 12 13:15:18 2011
@@ -149,6 +149,8 @@ Avro 1.6.0 (unreleased)
 
     AVRO-916. 0xff in binary stream is interpreted as end-of-stream. (thiru)
 
+    AVRO-869. Lifetimes of streams and encoder/decoders not managed propertly. (thiru)
+
 Avro 1.5.4 (12 September 2011)
 
   IMPROVEMENTS

Modified: avro/trunk/lang/c++/api/Stream.hh
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/api/Stream.hh?rev=1182350&r1=1182349&r2=1182350&view=diff
==============================================================================
--- avro/trunk/lang/c++/api/Stream.hh (original)
+++ avro/trunk/lang/c++/api/Stream.hh Wed Oct 12 13:15:18 2011
@@ -139,7 +139,7 @@ struct StreamReader {
     StreamReader(InputStream& in) : in_(0), next_(0), end_(0) { reset(in); }
 
     void reset(InputStream& is) {
-        if (in_ != 0) {
+        if (in_ != 0 && end_ != next_) {
             in_->backup(end_ - next_);
         }
         in_ = &is;
@@ -213,7 +213,7 @@ struct StreamWriter {
     StreamWriter(OutputStream& out) : out_(0), next_(0), end_(0) { reset(out); }
 
     void reset(OutputStream& os) {
-        if (out_ != 0) {
+        if (out_ != 0 && end_ != next_) {
             out_->backup(end_ - next_);
         }
         out_ = &os;

Modified: avro/trunk/lang/c++/test/CodecTests.cc
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/test/CodecTests.cc?rev=1182350&r1=1182349&r2=1182350&view=diff
==============================================================================
--- avro/trunk/lang/c++/test/CodecTests.cc (original)
+++ avro/trunk/lang/c++/test/CodecTests.cc Wed Oct 12 13:15:18 2011
@@ -1400,6 +1400,27 @@ void add_tests(boost::unit_test::test_su
 }
 
 }   // namespace parsing
+
+static void testStreamLifetimes()
+{
+    EncoderPtr e = binaryEncoder();
+    {
+        std::auto_ptr<OutputStream> s1 = memoryOutputStream();
+        e->init(*s1);
+        e->encodeInt(100);
+        e->encodeDouble(4.73);
+        e->flush();
+    }
+
+    {
+        std::auto_ptr<OutputStream> s2 = memoryOutputStream();
+        e->init(*s2);
+        e->encodeDouble(3.14);
+        e->flush();
+    }
+
+}
+
 }   // namespace avro
 
 boost::unit_test::test_suite*
@@ -1407,8 +1428,9 @@ init_unit_test_suite( int argc, char* ar
 {
     using namespace boost::unit_test;
 
-    test_suite* ts= BOOST_TEST_SUITE("Avro C++ unit test suite");
+    test_suite* ts= BOOST_TEST_SUITE("Avro C++ unit tests for codecs");
     avro::parsing::add_tests(*ts);
+    ts->add(BOOST_TEST_CASE(avro::testStreamLifetimes));
 
     return ts;
 }



Mime
View raw message