diff --git a/CHANGELOG.md b/CHANGELOG.md index ab43a2d6..cf5a140e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Version 122: * Add test for issue 807 * assert on empty buffer in websocket read +* Fix zlib symbol conflicts -------------------------------------------------------------------------------- diff --git a/include/boost/beast/zlib/detail/deflate_stream.hpp b/include/boost/beast/zlib/detail/deflate_stream.hpp index ed53c93a..f0a91e8a 100644 --- a/include/boost/beast/zlib/detail/deflate_stream.hpp +++ b/include/boost/beast/zlib/detail/deflate_stream.hpp @@ -158,10 +158,10 @@ protected: static std::uint8_t constexpr DYN_TREES = 2; // Maximum value for memLevel in deflateInit2 - static std::uint8_t constexpr MAX_MEM_LEVEL = 9; + static std::uint8_t constexpr max_mem_level = 9; // Default memLevel - static std::uint8_t constexpr DEF_MEM_LEVEL = MAX_MEM_LEVEL; + static std::uint8_t constexpr DEF_MEM_LEVEL = max_mem_level; /* Note: the deflate() code requires max_lazy >= minMatch and max_chain >= 4 For deflate_fast() (levels <= 3) good is ignored and lazy has a different @@ -896,7 +896,7 @@ doReset( int memLevel, Strategy strategy) { - if(level == Z_DEFAULT_COMPRESSION) + if(level == default_size) level = 6; // VFALCO What do we do about this? @@ -912,7 +912,7 @@ doReset( BOOST_THROW_EXCEPTION(std::invalid_argument{ "invalid windowBits"}); - if(memLevel < 1 || memLevel > MAX_MEM_LEVEL) + if(memLevel < 1 || memLevel > max_mem_level) BOOST_THROW_EXCEPTION(std::invalid_argument{ "invalid memLevel"}); @@ -991,7 +991,7 @@ doParams(z_params& zs, int level, Strategy strategy, error_code& ec) { compress_func func; - if(level == Z_DEFAULT_COMPRESSION) + if(level == default_size) level = 6; if(level < 0 || level > 9) { @@ -1914,20 +1914,20 @@ detect_data_type() // Check for non-textual ("black-listed") bytes. for(n = 0; n <= 31; n++, black_mask >>= 1) if((black_mask & 1) && (dyn_ltree_[n].fc != 0)) - return Z_BINARY; + return binary; // Check for textual ("white-listed") bytes. */ if(dyn_ltree_[9].fc != 0 || dyn_ltree_[10].fc != 0 || dyn_ltree_[13].fc != 0) - return Z_TEXT; + return text; for(n = 32; n < literals; n++) if(dyn_ltree_[n].fc != 0) - return Z_TEXT; + return text; /* There are no "black-listed" or "white-listed" bytes: * this stream either is empty or has tolerated ("gray-listed") bytes only. */ - return Z_BINARY; + return binary; } /* Flush the bit buffer and align the output on a byte boundary @@ -2099,7 +2099,7 @@ tr_flush_block( if(level_ > 0) { // Check if the file is binary or text - if(zs.data_type == Z_UNKNOWN) + if(zs.data_type == unknown) zs.data_type = detect_data_type(); // Construct the literal and distance trees diff --git a/include/boost/beast/zlib/zlib.hpp b/include/boost/beast/zlib/zlib.hpp index 7d466771..b830f2d9 100644 --- a/include/boost/beast/zlib/zlib.hpp +++ b/include/boost/beast/zlib/zlib.hpp @@ -47,16 +47,16 @@ namespace beast { namespace zlib { #if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ +using Byte = unsigned char; // 8 bits #endif -typedef unsigned int uInt; /* 16 bits or more */ +using uInt = unsigned int; // 16 bits or more /* Possible values of the data_type field (though see inflate()) */ -enum z_Type +enum kind { - Z_BINARY = 0, - Z_TEXT = 1, - Z_UNKNOWN = 2 + binary = 0, + text = 1, + unknown = 2 }; /** Deflate codec parameters. @@ -106,7 +106,7 @@ struct z_params */ std::size_t total_out = 0; - int data_type = Z_UNKNOWN; // best guess about the data type: binary or text + int data_type = unknown; // best guess about the data type: binary or text }; /** Flush option. @@ -125,12 +125,12 @@ enum class Flush }; /* compression levels */ -enum z_Compression +enum compression { - Z_NO_COMPRESSION = 0, - Z_BEST_SPEED = 1, - Z_BEST_COMPRESSION = 9, - Z_DEFAULT_COMPRESSION = -1 + none = 0, + best_speed = 1, + best_size = 9, + default_size = -1 }; /** Compression strategy. diff --git a/test/beast/zlib/CMakeLists.txt b/test/beast/zlib/CMakeLists.txt index c9de3848..e5bff730 100644 --- a/test/beast/zlib/CMakeLists.txt +++ b/test/beast/zlib/CMakeLists.txt @@ -25,4 +25,5 @@ add_executable (tests-beast-zlib error.cpp deflate_stream.cpp inflate_stream.cpp + zlib.cpp ) diff --git a/test/beast/zlib/Jamfile b/test/beast/zlib/Jamfile index fca0b71e..1c0b1ade 100644 --- a/test/beast/zlib/Jamfile +++ b/test/beast/zlib/Jamfile @@ -11,6 +11,7 @@ local SOURCES = error.cpp deflate_stream.cpp inflate_stream.cpp + zlib.cpp ; local RUN_TESTS ; diff --git a/test/beast/zlib/zlib.cpp b/test/beast/zlib/zlib.cpp new file mode 100644 index 00000000..4c300cdb --- /dev/null +++ b/test/beast/zlib/zlib.cpp @@ -0,0 +1,12 @@ +// +// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +// Make sure symbols don't confict with ZLib +#include "zlib-1.2.11/zlib.h" +#include