diff --git a/include/boost/iostreams/filter/bzip2.hpp b/include/boost/iostreams/filter/bzip2.hpp index 19804eb..caefbe4 100755 --- a/include/boost/iostreams/filter/bzip2.hpp +++ b/include/boost/iostreams/filter/bzip2.hpp @@ -4,6 +4,9 @@ // See http://www.boost.org/libs/iostreams for documentation. +// Note: custom allocators are not supported on VC6, since that compiler +// had trouble finding the function zlib_base::do_init. + #ifndef BOOST_IOSTREAMS_BZIP2_HPP_INCLUDED #define BOOST_IOSTREAMS_BZIP2_HPP_INCLUDED @@ -18,8 +21,9 @@ #include #include // buffer size. #include -#include #include +#include +#include #include // failure, streamsize. #include #include @@ -104,7 +108,7 @@ struct bzip2_params { // Description: Subclass of std::ios_base::failure thrown to indicate // bzip2 errors other than out-of-memory conditions. // -class BOOST_IOSTREAMS_DECL bzip2_error : public detail::failure { +class BOOST_IOSTREAMS_DECL bzip2_error : public BOOST_IOSTREAMS_FAILURE { public: explicit bzip2_error(int error); int error() const { return error_; } @@ -134,8 +138,8 @@ public: BOOST_STATIC_CONSTANT(bool, custom = (!is_same, Base>::value)); typedef typename bzip2_allocator_traits::type allocator_type; - static void* alloc(void* self, int items, int size); - static void free(void* self, void* address); + static void* allocate(void* self, int items, int size); + static void deallocate(void* self, void* address); }; class BOOST_IOSTREAMS_DECL bzip2_base { @@ -152,8 +156,10 @@ protected: { bool custom = bzip2_allocator::custom; do_init( compress, - custom ? bzip2_allocator::alloc : 0, - custom ? bzip2_allocator::free : 0, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + custom ? bzip2_allocator::allocate : 0, + custom ? bzip2_allocator::deallocate : 0, + #endif custom ? &alloc : 0 ); } void before( const char*& src_begin, const char* src_end, @@ -163,8 +169,12 @@ protected: int decompress(); void end(bool compress); private: - void do_init( bool compress, bzip2::alloc_func, - bzip2::free_func, void* derived ); + void do_init( bool compress, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + bzip2::alloc_func, + bzip2::free_func, + #endif + void* derived ); bzip2_params params_; void* stream_; // Actual type: bz_stream*. bool ready_; @@ -271,7 +281,7 @@ typedef basic_bzip2_decompressor<> bzip2_decompressor; namespace detail { template -void* bzip2_allocator::alloc(void* self, int items, int size) +void* bzip2_allocator::allocate(void* self, int items, int size) { size_type len = items * size; char* ptr = @@ -286,7 +296,7 @@ void* bzip2_allocator::alloc(void* self, int items, int size) } template -void bzip2_allocator::free(void* self, void* address) +void bzip2_allocator::deallocate(void* self, void* address) { char* ptr = reinterpret_cast(address) - sizeof(size_type); size_type len = *reinterpret_cast(ptr) + sizeof(size_type); diff --git a/include/boost/iostreams/filter/gzip.hpp b/include/boost/iostreams/filter/gzip.hpp index af3013f..f3813de 100755 --- a/include/boost/iostreams/filter/gzip.hpp +++ b/include/boost/iostreams/filter/gzip.hpp @@ -26,6 +26,7 @@ #include #include // failure. #include +#include #include #include #include @@ -142,13 +143,13 @@ struct gzip_params : zlib_params { // Description: Subclass of std::ios_base::failure thrown to indicate // zlib errors other than out-of-memory conditions. // -class gzip_error : public detail::failure { +class gzip_error : public BOOST_IOSTREAMS_FAILURE { public: explicit gzip_error(int error) - : detail::failure("gzip error"), + : BOOST_IOSTREAMS_FAILURE("gzip error"), error_(error), zlib_error_code_(zlib::okay) { } explicit gzip_error(const zlib_error& e) - : detail::failure("gzip error"), + : BOOST_IOSTREAMS_FAILURE("gzip error"), error_(gzip::zlib_error), zlib_error_code_(e.error()) { } int error() const { return error_; } @@ -246,8 +247,9 @@ private: void prepare_footer() { - write_long(this->crc(), footer_); - write_long(this->total_in(), footer_); + boost::iostreams::back_insert_device out(footer_); + write_long(this->crc(), out); + write_long(this->total_in(), out); flags_ |= f_body_done; offset_ = 0; } @@ -270,13 +272,13 @@ private: return amt; } - static void write_long(long n, std::string& str) - { - str += static_cast(0xFF & n); - str += static_cast(0xFF & (n >> 8)); - str += static_cast(0xFF & (n >> 16)); - str += static_cast(0xFF & (n >> 24)); - } + //static void write_long(long n, std::string& str) + // { + // str += static_cast(0xFF & n); + // str += static_cast(0xFF & (n >> 8)); + // str += static_cast(0xFF & (n >> 16)); + // str += static_cast(0xFF & (n >> 24)); + // } template static void write_long(long n, Sink& next) diff --git a/include/boost/iostreams/filter/zlib.hpp b/include/boost/iostreams/filter/zlib.hpp index 50a4770..c6b684f 100755 --- a/include/boost/iostreams/filter/zlib.hpp +++ b/include/boost/iostreams/filter/zlib.hpp @@ -4,6 +4,9 @@ // See http://www.boost.org/libs/iostreams for documentation. +// Note: custom allocators are not supported on VC6, since that compiler +// had trouble finding the function zlib_base::do_init. + #ifndef BOOST_IOSTREAMS_ZLIB_HPP_INCLUDED #define BOOST_IOSTREAMS_ZLIB_HPP_INCLUDED @@ -16,9 +19,11 @@ #include // allocator, bad_alloc. #include #include // MSVC, STATIC_CONSTANT, DEDUCED_TYPENAME, DINKUM. +#include #include // buffer size. #include #include +#include #include #include // failure, streamsize. #include @@ -125,7 +130,7 @@ struct zlib_params { // Description: Subclass of std::ios::failure thrown to indicate // zlib errors other than out-of-memory conditions. // -class BOOST_IOSTREAMS_DECL zlib_error : public detail::failure { +class BOOST_IOSTREAMS_DECL zlib_error : public BOOST_IOSTREAMS_FAILURE { public: explicit zlib_error(int error); int error() const { return error_; } @@ -155,8 +160,8 @@ public: BOOST_STATIC_CONSTANT(bool, custom = (!is_same, Base>::value)); typedef typename zlib_allocator_traits::type allocator_type; - static void* alloc(void* self, zlib::uint items, zlib::uint size); - static void free(void* self, void* address); + static void* allocate(void* self, zlib::uint items, zlib::uint size); + static void deallocate(void* self, void* address); }; class BOOST_IOSTREAMS_DECL zlib_base { @@ -169,13 +174,15 @@ protected: template void init( const zlib_params& p, bool compress, - zlib_allocator& alloc ) + zlib_allocator& zalloc ) { bool custom = zlib_allocator::custom; do_init( p, compress, - custom ? zlib_allocator::alloc : 0, - custom ? zlib_allocator::free : 0, - &alloc ); + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + custom ? zlib_allocator::allocate : 0, + custom ? zlib_allocator::deallocate : 0, + #endif + &zalloc ); } void before( const char*& src_begin, const char* src_end, char*& dest_begin, char* dest_end ); @@ -189,8 +196,12 @@ public: int total_in() const { return total_in_; } int total_out() const { return total_out_; } private: - void do_init( const zlib_params& p, bool compress, zlib::alloc_func, - zlib::free_func, void* derived ); + void do_init( const zlib_params& p, bool compress, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + zlib::alloc_func, + zlib::free_func, + #endif + void* derived ); void* stream_; // Actual type: z_stream*. bool calculate_crc_; zlib::ulong crc_; @@ -290,7 +301,7 @@ typedef basic_zlib_decompressor<> zlib_decompressor; namespace detail { template -void* zlib_allocator::alloc +void* zlib_allocator::allocate (void* self, zlib::uint items, zlib::uint size) { size_type len = items * size; @@ -306,7 +317,7 @@ void* zlib_allocator::alloc } template -void zlib_allocator::free(void* self, void* address) +void zlib_allocator::deallocate(void* self, void* address) { char* ptr = reinterpret_cast(address) - sizeof(size_type); size_type len = *reinterpret_cast(ptr) + sizeof(size_type); diff --git a/src/bzip2.cpp b/src/bzip2.cpp index ee1be32..72e3da1 100755 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp @@ -44,7 +44,13 @@ const int run = BZ_RUN; //------------------Implementation of bzip2_error-----------------------------// bzip2_error::bzip2_error(int error) - : detail::failure("bzip2 error"), error_(error) { } +#ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES + : std::ios_base::failure + #else + : detail::failure + #endif + ("bzip2 error"), error_(error) + { } void bzip2_error::check(int error) { @@ -110,12 +116,22 @@ int bzip2_base::decompress() return BZ2_bzDecompress(static_cast(stream_)); } -void bzip2_base::do_init( bool compress, bzip2::alloc_func alloc, - bzip2::free_func free, void* derived ) +void bzip2_base::do_init + ( bool compress, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + bzip2::alloc_func alloc, + bzip2::free_func free, + #endif + void* derived ) { bz_stream* s = static_cast(stream_); - s->bzalloc = alloc; - s->bzfree = free; + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + s->bzalloc = alloc; + s->bzfree = free; + #else + s->bzalloc = 0; + s->bzfree = 0; + #endif s->opaque = derived; bzip2_error::check( compress ? diff --git a/src/zlib.cpp b/src/zlib.cpp index 01490ea..53852e5 100755 --- a/src/zlib.cpp +++ b/src/zlib.cpp @@ -58,7 +58,8 @@ const int buf_error = Z_BUF_ERROR; //------------------Implementation of zlib_error------------------------------// zlib_error::zlib_error(int error) - : detail::failure("zlib error"), error_(error) { } + : BOOST_IOSTREAMS_FAILURE("zlib error"), error_(error) + { } void zlib_error::check(int error) { @@ -132,14 +133,22 @@ void zlib_base::reset(bool compress) zlib_error::check(compress ? deflateReset(s) : inflateReset(s)); } -void zlib_base::do_init( const zlib_params& p, bool compress, - zlib::alloc_func alloc, zlib::free_func free, - void* derived ) +void zlib_base::do_init + ( const zlib_params& p, bool compress, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + zlib::alloc_func alloc, zlib::free_func free, + #endif + void* derived ) { calculate_crc_ = p.calculate_crc; z_stream* s = static_cast(stream_); - s->zalloc = alloc; - s->zfree = free; + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + s->zalloc = alloc; + s->zfree = free; + #else + s->zalloc = 0; + s->zfree = 0; + #endif s->opaque = derived; int window_bits = p.noheader? -p.window_bits : p.window_bits; zlib_error::check(