mirror of
https://github.com/boostorg/iostreams.git
synced 2026-02-22 15:32:20 +00:00
VC6 fixes
[SVN r27315]
This commit is contained in:
@@ -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 <boost/detail/workaround.hpp>
|
||||
#include <boost/iostreams/constants.hpp> // buffer size.
|
||||
#include <boost/iostreams/detail/config/auto_link.hpp>
|
||||
#include <boost/iostreams/detail/config/dyn_link.hpp>
|
||||
#include <boost/iostreams/detail/config/bzip2.hpp>
|
||||
#include <boost/iostreams/detail/config/dyn_link.hpp>
|
||||
#include <boost/iostreams/detail/config/wide_streams.hpp>
|
||||
#include <boost/iostreams/detail/ios.hpp> // failure, streamsize.
|
||||
#include <boost/iostreams/filter/symmetric_filter_adapter.hpp>
|
||||
#include <boost/iostreams/pipable.hpp>
|
||||
@@ -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<std::allocator<char>, Base>::value));
|
||||
typedef typename bzip2_allocator_traits<Alloc>::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<Alloc>::custom;
|
||||
do_init( compress,
|
||||
custom ? bzip2_allocator<Alloc>::alloc : 0,
|
||||
custom ? bzip2_allocator<Alloc>::free : 0,
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
custom ? bzip2_allocator<Alloc>::allocate : 0,
|
||||
custom ? bzip2_allocator<Alloc>::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<typename Alloc, typename Base>
|
||||
void* bzip2_allocator<Alloc, Base>::alloc(void* self, int items, int size)
|
||||
void* bzip2_allocator<Alloc, Base>::allocate(void* self, int items, int size)
|
||||
{
|
||||
size_type len = items * size;
|
||||
char* ptr =
|
||||
@@ -286,7 +296,7 @@ void* bzip2_allocator<Alloc, Base>::alloc(void* self, int items, int size)
|
||||
}
|
||||
|
||||
template<typename Alloc, typename Base>
|
||||
void bzip2_allocator<Alloc, Base>::free(void* self, void* address)
|
||||
void bzip2_allocator<Alloc, Base>::deallocate(void* self, void* address)
|
||||
{
|
||||
char* ptr = reinterpret_cast<char*>(address) - sizeof(size_type);
|
||||
size_type len = *reinterpret_cast<size_type*>(ptr) + sizeof(size_type);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <boost/iostreams/detail/char_traits.hpp>
|
||||
#include <boost/iostreams/detail/ios.hpp> // failure.
|
||||
#include <boost/iostreams/operations.hpp>
|
||||
#include <boost/iostreams/device/back_inserter.hpp>
|
||||
#include <boost/iostreams/filter/zlib.hpp>
|
||||
#include <boost/iostreams/pipable.hpp>
|
||||
#include <boost/iostreams/streambuf_facade.hpp>
|
||||
@@ -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<std::string> 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<char>(0xFF & n);
|
||||
str += static_cast<char>(0xFF & (n >> 8));
|
||||
str += static_cast<char>(0xFF & (n >> 16));
|
||||
str += static_cast<char>(0xFF & (n >> 24));
|
||||
}
|
||||
//static void write_long(long n, std::string& str)
|
||||
// {
|
||||
// str += static_cast<char>(0xFF & n);
|
||||
// str += static_cast<char>(0xFF & (n >> 8));
|
||||
// str += static_cast<char>(0xFF & (n >> 16));
|
||||
// str += static_cast<char>(0xFF & (n >> 24));
|
||||
// }
|
||||
|
||||
template<typename Sink>
|
||||
static void write_long(long n, Sink& next)
|
||||
|
||||
@@ -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 <memory> // allocator, bad_alloc.
|
||||
#include <new>
|
||||
#include <boost/config.hpp> // MSVC, STATIC_CONSTANT, DEDUCED_TYPENAME, DINKUM.
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/iostreams/constants.hpp> // buffer size.
|
||||
#include <boost/iostreams/detail/config/auto_link.hpp>
|
||||
#include <boost/iostreams/detail/config/dyn_link.hpp>
|
||||
#include <boost/iostreams/detail/config/wide_streams.hpp>
|
||||
#include <boost/iostreams/detail/config/zlib.hpp>
|
||||
#include <boost/iostreams/detail/ios.hpp> // failure, streamsize.
|
||||
#include <boost/iostreams/filter/symmetric_filter_adapter.hpp>
|
||||
@@ -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<std::allocator<char>, Base>::value));
|
||||
typedef typename zlib_allocator_traits<Alloc>::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<typename Alloc>
|
||||
void init( const zlib_params& p,
|
||||
bool compress,
|
||||
zlib_allocator<Alloc>& alloc )
|
||||
zlib_allocator<Alloc>& zalloc )
|
||||
{
|
||||
bool custom = zlib_allocator<Alloc>::custom;
|
||||
do_init( p, compress,
|
||||
custom ? zlib_allocator<Alloc>::alloc : 0,
|
||||
custom ? zlib_allocator<Alloc>::free : 0,
|
||||
&alloc );
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
custom ? zlib_allocator<Alloc>::allocate : 0,
|
||||
custom ? zlib_allocator<Alloc>::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<typename Alloc, typename Base>
|
||||
void* zlib_allocator<Alloc, Base>::alloc
|
||||
void* zlib_allocator<Alloc, Base>::allocate
|
||||
(void* self, zlib::uint items, zlib::uint size)
|
||||
{
|
||||
size_type len = items * size;
|
||||
@@ -306,7 +317,7 @@ void* zlib_allocator<Alloc, Base>::alloc
|
||||
}
|
||||
|
||||
template<typename Alloc, typename Base>
|
||||
void zlib_allocator<Alloc, Base>::free(void* self, void* address)
|
||||
void zlib_allocator<Alloc, Base>::deallocate(void* self, void* address)
|
||||
{
|
||||
char* ptr = reinterpret_cast<char*>(address) - sizeof(size_type);
|
||||
size_type len = *reinterpret_cast<size_type*>(ptr) + sizeof(size_type);
|
||||
|
||||
@@ -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<bz_stream*>(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<bz_stream*>(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 ?
|
||||
|
||||
21
src/zlib.cpp
21
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<z_stream*>(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(
|
||||
|
||||
Reference in New Issue
Block a user