Fix zlib symbol conflicts

fix #808
This commit is contained in:
Vinnie Falco
2017-10-07 11:17:00 -07:00
parent a517df9090
commit 2ac6936312
6 changed files with 37 additions and 22 deletions

View File

@ -2,6 +2,7 @@ Version 122:
* Add test for issue 807 * Add test for issue 807
* assert on empty buffer in websocket read * assert on empty buffer in websocket read
* Fix zlib symbol conflicts
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -158,10 +158,10 @@ protected:
static std::uint8_t constexpr DYN_TREES = 2; static std::uint8_t constexpr DYN_TREES = 2;
// Maximum value for memLevel in deflateInit2 // 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 // 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 /* 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 For deflate_fast() (levels <= 3) good is ignored and lazy has a different
@ -896,7 +896,7 @@ doReset(
int memLevel, int memLevel,
Strategy strategy) Strategy strategy)
{ {
if(level == Z_DEFAULT_COMPRESSION) if(level == default_size)
level = 6; level = 6;
// VFALCO What do we do about this? // VFALCO What do we do about this?
@ -912,7 +912,7 @@ doReset(
BOOST_THROW_EXCEPTION(std::invalid_argument{ BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid windowBits"}); "invalid windowBits"});
if(memLevel < 1 || memLevel > MAX_MEM_LEVEL) if(memLevel < 1 || memLevel > max_mem_level)
BOOST_THROW_EXCEPTION(std::invalid_argument{ BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid memLevel"}); "invalid memLevel"});
@ -991,7 +991,7 @@ doParams(z_params& zs, int level, Strategy strategy, error_code& ec)
{ {
compress_func func; compress_func func;
if(level == Z_DEFAULT_COMPRESSION) if(level == default_size)
level = 6; level = 6;
if(level < 0 || level > 9) if(level < 0 || level > 9)
{ {
@ -1914,20 +1914,20 @@ detect_data_type()
// Check for non-textual ("black-listed") bytes. // Check for non-textual ("black-listed") bytes.
for(n = 0; n <= 31; n++, black_mask >>= 1) for(n = 0; n <= 31; n++, black_mask >>= 1)
if((black_mask & 1) && (dyn_ltree_[n].fc != 0)) if((black_mask & 1) && (dyn_ltree_[n].fc != 0))
return Z_BINARY; return binary;
// Check for textual ("white-listed") bytes. */ // Check for textual ("white-listed") bytes. */
if(dyn_ltree_[9].fc != 0 || dyn_ltree_[10].fc != 0 if(dyn_ltree_[9].fc != 0 || dyn_ltree_[10].fc != 0
|| dyn_ltree_[13].fc != 0) || dyn_ltree_[13].fc != 0)
return Z_TEXT; return text;
for(n = 32; n < literals; n++) for(n = 32; n < literals; n++)
if(dyn_ltree_[n].fc != 0) if(dyn_ltree_[n].fc != 0)
return Z_TEXT; return text;
/* There are no "black-listed" or "white-listed" bytes: /* There are no "black-listed" or "white-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only. * 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 /* Flush the bit buffer and align the output on a byte boundary
@ -2099,7 +2099,7 @@ tr_flush_block(
if(level_ > 0) if(level_ > 0)
{ {
// Check if the file is binary or text // 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(); zs.data_type = detect_data_type();
// Construct the literal and distance trees // Construct the literal and distance trees

View File

@ -47,16 +47,16 @@ namespace beast {
namespace zlib { namespace zlib {
#if !defined(__MACTYPES__) #if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */ using Byte = unsigned char; // 8 bits
#endif #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()) */ /* Possible values of the data_type field (though see inflate()) */
enum z_Type enum kind
{ {
Z_BINARY = 0, binary = 0,
Z_TEXT = 1, text = 1,
Z_UNKNOWN = 2 unknown = 2
}; };
/** Deflate codec parameters. /** Deflate codec parameters.
@ -106,7 +106,7 @@ struct z_params
*/ */
std::size_t total_out = 0; 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. /** Flush option.
@ -125,12 +125,12 @@ enum class Flush
}; };
/* compression levels */ /* compression levels */
enum z_Compression enum compression
{ {
Z_NO_COMPRESSION = 0, none = 0,
Z_BEST_SPEED = 1, best_speed = 1,
Z_BEST_COMPRESSION = 9, best_size = 9,
Z_DEFAULT_COMPRESSION = -1 default_size = -1
}; };
/** Compression strategy. /** Compression strategy.

View File

@ -25,4 +25,5 @@ add_executable (tests-beast-zlib
error.cpp error.cpp
deflate_stream.cpp deflate_stream.cpp
inflate_stream.cpp inflate_stream.cpp
zlib.cpp
) )

View File

@ -11,6 +11,7 @@ local SOURCES =
error.cpp error.cpp
deflate_stream.cpp deflate_stream.cpp
inflate_stream.cpp inflate_stream.cpp
zlib.cpp
; ;
local RUN_TESTS ; local RUN_TESTS ;

12
test/beast/zlib/zlib.cpp Normal file
View File

@ -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 <boost/beast/zlib.hpp>