|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60666 - in branches/release: boost/iostreams boost/iostreams/filter libs/iostreams libs/iostreams/src libs/iostreams/test
From: daniel_james_at_[hidden]
Date: 2010-03-16 20:23:33
Author: danieljames
Date: 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
New Revision: 60666
URL: http://svn.boost.org/trac/boost/changeset/60666
Log:
Merge iostreams.
- Fix write_device_impl<ostream_tag>. Fixes #3839
- Fix error checks after calling SetFilePointer. Fixes #3953
- Gzip filter shouldn't require its source to be peekable. Fixes #3723.
- In `position_to_offset`, only cast to `stream_offset` after calculating
`_Myoff`. Fixes #3969.
- ptrdiff_t is in std. Fixes #2505.
Properties modified:
branches/release/boost/iostreams/ (props changed)
branches/release/libs/iostreams/ (props changed)
Text files modified:
branches/release/boost/iostreams/filter/gzip.hpp | 6 +++-
branches/release/boost/iostreams/positioning.hpp | 6 +++-
branches/release/boost/iostreams/write.hpp | 2
branches/release/libs/iostreams/src/mapped_file.cpp | 14 ++++++----
branches/release/libs/iostreams/test/grep_test.cpp | 2
branches/release/libs/iostreams/test/gzip_test.cpp | 18 +++++++++++++
branches/release/libs/iostreams/test/mapped_file_test.cpp | 17 +++++++++++++
branches/release/libs/iostreams/test/newline_test.cpp | 52 ++++++++++++++++++++++++++++++---------
branches/release/libs/iostreams/test/stream_offset_64bit_test.cpp | 17 ++++++++++++
9 files changed, 109 insertions(+), 25 deletions(-)
Modified: branches/release/boost/iostreams/filter/gzip.hpp
==============================================================================
--- branches/release/boost/iostreams/filter/gzip.hpp (original)
+++ branches/release/boost/iostreams/filter/gzip.hpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -32,6 +32,7 @@
#include <boost/iostreams/detail/adapter/range_adapter.hpp>
#include <boost/iostreams/detail/char_traits.hpp>
#include <boost/iostreams/detail/ios.hpp> // failure.
+#include <boost/iostreams/detail/error.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/filter/zlib.hpp>
@@ -531,10 +532,11 @@
{
if (offset_) {
putback_[--offset_] = c;
- return true;
} else {
- return boost::iostreams::putback(src_, c);
+ boost::throw_exception(
+ boost::iostreams::detail::bad_putback());
}
+ return true;
}
void putback(const string_type& s)
{
Modified: branches/release/boost/iostreams/positioning.hpp
==============================================================================
--- branches/release/boost/iostreams/positioning.hpp (original)
+++ branches/release/boost/iostreams/positioning.hpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -102,8 +102,10 @@
inline stream_offset position_to_offset(std::streampos pos)
{
return fpos_t_to_offset(streampos_to_fpos_t(pos)) +
- static_cast<stream_offset>(static_cast<std::streamoff>(pos)) -
- static_cast<stream_offset>(_FPOSOFF(streampos_to_fpos_t(pos)));
+ static_cast<stream_offset>(
+ static_cast<std::streamoff>(pos) -
+ _FPOSOFF(streampos_to_fpos_t(pos))
+ );
}
# endif // # ifndef BOOST_IOSTREAMS_HAS_DINKUMWARE_FPOS
Modified: branches/release/boost/iostreams/write.hpp
==============================================================================
--- branches/release/boost/iostreams/write.hpp (original)
+++ branches/release/boost/iostreams/write.hpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -83,7 +83,7 @@
{
typedef typename char_type_of<T>::type char_type;
typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type;
- return !traits_type::eq_int_type( t.rdbuf()->s.sputc(),
+ return !traits_type::eq_int_type( t.rdbuf()->sputc(c),
traits_type::eof() );
}
Modified: branches/release/libs/iostreams/src/mapped_file.cpp
==============================================================================
--- branches/release/libs/iostreams/src/mapped_file.cpp (original)
+++ branches/release/libs/iostreams/src/mapped_file.cpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -128,12 +128,13 @@
cleanup_and_throw("failed unmapping file");
#ifdef BOOST_IOSTREAMS_WINDOWS
stream_offset offset = ::SetFilePointer(handle_, 0, NULL, FILE_CURRENT);
- if (::GetLastError() != NO_ERROR)
- cleanup_and_throw("failed querying file pointer");
+ if (offset == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR)
+ cleanup_and_throw("failed querying file pointer");
LONG sizehigh = (new_size >> (sizeof(LONG) * 8));
LONG sizelow = (new_size & 0xffffffff);
- ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
- if (::GetLastError() != NO_ERROR || !::SetEndOfFile(handle_))
+ DWORD result = ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
+ if ((result == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR)
+ || !::SetEndOfFile(handle_))
cleanup_and_throw("failed resizing mapped file");
sizehigh = (offset >> (sizeof(LONG) * 8));
sizelow = (offset & 0xffffffff);
@@ -197,8 +198,9 @@
if (p.new_file_size != 0 && !readonly) {
LONG sizehigh = (p.new_file_size >> (sizeof(LONG) * 8));
LONG sizelow = (p.new_file_size & 0xffffffff);
- ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
- if (::GetLastError() != NO_ERROR || !::SetEndOfFile(handle_))
+ DWORD result = ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
+ if ((result == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR)
+ || !::SetEndOfFile(handle_))
cleanup_and_throw("failed setting file size");
}
Modified: branches/release/libs/iostreams/test/grep_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/grep_test.cpp (original)
+++ branches/release/libs/iostreams/test/grep_test.cpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -253,7 +253,7 @@
const std::string& output )
{
// Count lines in output
- ptrdiff_t count = std::count(output.begin(), output.end(), '\n');
+ std::ptrdiff_t count = std::count(output.begin(), output.end(), '\n');
// Test as input filter
{
Modified: branches/release/libs/iostreams/test/gzip_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/gzip_test.cpp (original)
+++ branches/release/libs/iostreams/test/gzip_test.cpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -83,10 +83,28 @@
BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2));
}
+void array_source_test()
+{
+ std::string data = "simple test string.";
+ std::string encoded;
+
+ filtering_ostream out;
+ out.push(gzip_compressor());
+ out.push(io::back_inserter(encoded));
+ io::copy(make_iterator_range(data), out);
+
+ std::string res;
+ io::array_source src(encoded.data(),encoded.length());
+ io::copy(io::compose(io::gzip_decompressor(), src), io::back_inserter(res));
+
+ BOOST_CHECK_EQUAL(data, res);
+}
+
test_suite* init_unit_test_suite(int, char* [])
{
test_suite* test = BOOST_TEST_SUITE("gzip test");
test->add(BOOST_TEST_CASE(&compression_test));
test->add(BOOST_TEST_CASE(&multiple_member_test));
+ test->add(BOOST_TEST_CASE(&array_source_test));
return test;
}
Modified: branches/release/libs/iostreams/test/mapped_file_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/mapped_file_test.cpp (original)
+++ branches/release/libs/iostreams/test/mapped_file_test.cpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -175,6 +175,23 @@
);
}
+ //--------------Writing to a pre-existing file---------------------------//
+ {
+ // Test for Bug #3953 - writing to a pre-existing mapped file.
+ boost::iostreams::test::test_file first, test;
+
+ mapped_file_params p(first.name());
+ p.new_file_size = boost::iostreams::test::data_reps * boost::iostreams::test::data_length();
+ boost::iostreams::stream<mapped_file_sink> out;
+ out.open(mapped_file_sink(p));
+ boost::iostreams::test::write_data_in_chars(out);
+ out.close();
+ BOOST_CHECK_MESSAGE(
+ boost::iostreams::test::compare_files(first.name(), test.name()),
+ "failed writing to pre-existing mapped file in chars"
+ );
+ }
+
//--------------Random access with a mapped_file--------------------------//
{
Modified: branches/release/libs/iostreams/test/newline_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/newline_test.cpp (original)
+++ branches/release/libs/iostreams/test/newline_test.cpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -163,30 +163,58 @@
BOOST_CHECK(test_input_filter(newline_filter(newline::mac), mixed, mac));
}
+// Verify that a filter works as expected with both a non-blocking sink
+// and a normal output stream.
+//
+// test_output_filter only tests for a non-blocking sink.
+// TODO: Other tests should probably test with an output stream.
+
+template<typename Filter>
+bool my_test_output_filter(Filter filter,
+ const std::string& input,
+ const std::string& output)
+{
+ const std::streamsize default_increment = 5;
+
+ for ( int inc = default_increment;
+ inc < default_increment * 40;
+ inc += default_increment )
+ {
+ io::array_source src(input.data(), input.data() + input.size());
+
+ std::ostringstream stream;
+ io::copy(src, compose(filter, stream));
+ if (stream.str() != output )
+ return false;
+
+ }
+ return test_output_filter(filter, input, output);
+}
+
void write_newline_filter()
{
using namespace io;
// Test converting to posix format.
- BOOST_CHECK(test_output_filter(newline_filter(newline::posix), posix, posix));
- BOOST_CHECK(test_output_filter(newline_filter(newline::posix), dos, posix));
- BOOST_CHECK(test_output_filter(newline_filter(newline::posix), mac, posix));
- BOOST_CHECK(test_output_filter(newline_filter(newline::posix), mixed, posix));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::posix), posix, posix));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::posix), dos, posix));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::posix), mac, posix));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::posix), mixed, posix));
// Test converting to dos format.
- BOOST_CHECK(test_output_filter(newline_filter(newline::dos), posix, dos));
- BOOST_CHECK(test_output_filter(newline_filter(newline::dos), dos, dos));
- BOOST_CHECK(test_output_filter(newline_filter(newline::dos), mac, dos));
- BOOST_CHECK(test_output_filter(newline_filter(newline::dos), mixed, dos));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::dos), posix, dos));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::dos), dos, dos));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::dos), mac, dos));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::dos), mixed, dos));
// Test converting to mac format.
- BOOST_CHECK(test_output_filter(newline_filter(newline::mac), posix, mac));
- BOOST_CHECK(test_output_filter(newline_filter(newline::mac), dos, mac));
- BOOST_CHECK(test_output_filter(newline_filter(newline::mac), mac, mac));
- BOOST_CHECK(test_output_filter(newline_filter(newline::mac), mixed, mac));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::mac), posix, mac));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::mac), dos, mac));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::mac), mac, mac));
+ BOOST_CHECK(my_test_output_filter(newline_filter(newline::mac), mixed, mac));
}
void test_input_against_flags(int flags, const std::string& input, bool read)
Modified: branches/release/libs/iostreams/test/stream_offset_64bit_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/stream_offset_64bit_test.cpp (original)
+++ branches/release/libs/iostreams/test/stream_offset_64bit_test.cpp 2010-03-16 20:23:32 EDT (Tue, 16 Mar 2010)
@@ -56,15 +56,30 @@
<< hex
<< static_cast<unsigned int>(off >> 32)
<< " and (off & 0xFFFFFFFF) == 0x"
- << static_cast<unsigned int>(off & 0xFFFFFFFF);
+ << static_cast<unsigned int>(off & 0xFFFFFFFF)
+ << std::endl;
BOOST_REQUIRE_MESSAGE(0, s.str().c_str());
}
}
}
+void stream_offset_64bit_test2()
+{
+ boost::int64_t val = boost::int64_t(1) << 31;
+ std::streampos pos = boost::iostreams::offset_to_position(val);
+ pos -= 2;
+ BOOST_CHECK_EQUAL(val - 2, boost::iostreams::position_to_offset(pos));
+
+ val = -val;
+ pos = boost::iostreams::offset_to_position(val);
+ pos += 2;
+ BOOST_CHECK_EQUAL(val + 2, boost::iostreams::position_to_offset(pos));
+}
+
test_suite* init_unit_test_suite(int, char* [])
{
test_suite* test = BOOST_TEST_SUITE("stream_offset 64-bit test");
test->add(BOOST_TEST_CASE(&stream_offset_64bit_test));
+ test->add(BOOST_TEST_CASE(&stream_offset_64bit_test2));
return test;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk