update boost

This commit is contained in:
2023-11-24 12:56:13 -06:00
parent cfc99971af
commit 19d727037a
9260 changed files with 849256 additions and 299957 deletions

View File

@@ -8,7 +8,7 @@
//
// This is a derivative work based on Zlib, copyright below:
/*
Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
Copyright (C) 1995-2018 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -40,7 +40,6 @@
#include <boost/beast/zlib/error.hpp>
#include <boost/beast/zlib/zlib.hpp>
#include <boost/beast/zlib/detail/ranges.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/optional.hpp>
@@ -371,7 +370,7 @@ protected:
// Depth of each subtree used as tie breaker for trees of equal frequency
std::uint8_t depth_[2*lCodes+1];
std::uint8_t *l_buf_; // buffer for literals or lengths
std::uint8_t *sym_buf_; // buffer for distances and literals or lengths
/* Size of match buffer for literals/lengths.
There are 4 reasons for limiting lit_bufsize to 64K:
@@ -392,13 +391,9 @@ protected:
- I can't count above 4
*/
uInt lit_bufsize_;
uInt last_lit_; // running index in l_buf_
/* Buffer for distances. To simplify the code, d_buf_ and l_buf_
have the same number of elements. To use different lengths, an
extra flag array would be necessary.
*/
std::uint16_t* d_buf_;
uInt sym_next_; /* running index in sym_buf */
uInt sym_end_; /* symbol table full when sym_next reaches this */
std::uint32_t opt_len_; // bit length of current block with optimal trees
std::uint32_t static_len_; // bit length of current block with static trees

View File

@@ -8,7 +8,7 @@
//
// This is a derivative work based on Zlib, copyright below:
/*
Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
Copyright (C) 1995-2018 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,6 @@
#include <boost/beast/zlib/detail/deflate_stream.hpp>
#include <boost/beast/zlib/detail/ranges.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/make_unique.hpp>
@@ -327,7 +326,7 @@ doParams(z_params& zs, int level, Strategy strategy, error_code& ec)
level = 6;
if(level < 0 || level > 9)
{
ec = error::stream_error;
BOOST_BEAST_ASSIGN_EC(ec, error::stream_error);
return;
}
func = get_config(level_).func;
@@ -361,15 +360,18 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
{
maybe_init();
if(zs.next_out == 0 || (zs.next_in == 0 && zs.avail_in != 0) ||
if(zs.next_in == nullptr && zs.avail_in != 0)
BOOST_THROW_EXCEPTION(std::invalid_argument{"invalid input"});
if(zs.next_out == nullptr ||
(status_ == FINISH_STATE && flush != Flush::finish))
{
ec = error::stream_error;
BOOST_BEAST_ASSIGN_EC(ec, error::stream_error);
return;
}
if(zs.avail_out == 0)
{
ec = error::need_buffers;
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
return;
}
@@ -397,21 +399,21 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
}
}
else if(zs.avail_in == 0 && (
old_flush && flush <= *old_flush
old_flush && flush <= *old_flush // Caution: depends on enum order
) && flush != Flush::finish)
{
/* Make sure there is something to do and avoid duplicate consecutive
* flushes. For repeated and useless calls with Flush::finish, we keep
* returning Z_STREAM_END instead of Z_BUF_ERROR.
*/
ec = error::need_buffers;
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
return;
}
// User must not provide more input after the first FINISH:
if(status_ == FINISH_STATE && zs.avail_in != 0)
{
ec = error::need_buffers;
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
return;
}
@@ -465,7 +467,7 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
else if(flush != Flush::block)
{
/* FULL_FLUSH or SYNC_FLUSH */
tr_stored_block((char*)0, 0L, 0);
tr_stored_block(nullptr, 0L, 0);
/* For a full flush, this empty block will be recognized
* as a special marker by inflate_sync().
*/
@@ -491,7 +493,7 @@ doWrite(z_params& zs, boost::optional<Flush> flush, error_code& ec)
if(flush == Flush::finish)
{
ec = error::end_of_stream;
BOOST_BEAST_ASSIGN_EC(ec, error::end_of_stream);
return;
}
}
@@ -503,7 +505,7 @@ doDictionary(Byte const* dict, uInt dictLength, error_code& ec)
{
if(lookahead_)
{
ec = error::stream_error;
BOOST_BEAST_ASSIGN_EC(ec, error::stream_error);
return;
}
@@ -557,9 +559,9 @@ doPrime(int bits, int value, error_code& ec)
{
maybe_init();
if((Byte *)(d_buf_) < pending_out_ + ((Buf_size + 7) >> 3))
if((Byte *)(sym_buf_) < pending_out_ + ((Buf_size + 7) >> 3))
{
ec = error::need_buffers;
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
return;
}
@@ -623,26 +625,58 @@ init()
window_ = reinterpret_cast<Byte*>(buf_.get());
prev_ = reinterpret_cast<std::uint16_t*>(buf_.get() + nwindow);
std::memset(prev_, 0, nprev);
head_ = reinterpret_cast<std::uint16_t*>(buf_.get() + nwindow + nprev);
/* We overlay pending_buf_ and d_buf_ + l_buf_. This works
since the average output size for(length, distance)
codes is <= 24 bits.
*/
auto overlay = reinterpret_cast<std::uint16_t*>(
buf_.get() + nwindow + nprev + nhead);
// nothing written to window_ yet
high_water_ = 0;
pending_buf_ =
reinterpret_cast<std::uint8_t*>(overlay);
pending_buf_size_ =
static_cast<std::uint32_t>(lit_bufsize_) *
(sizeof(std::uint16_t) + 2L);
d_buf_ = overlay + lit_bufsize_ / sizeof(std::uint16_t);
l_buf_ = pending_buf_ + (1 + sizeof(std::uint16_t)) * lit_bufsize_;
/* We overlay pending_buf and sym_buf. This works since the average size
for length/distance pairs over any compressed block is assured to be 31
bits or less.
Analysis: The longest fixed codes are a length code of 8 bits plus 5
extra bits, for lengths 131 to 257. The longest fixed distance codes are
5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
possible fixed-codes length/distance pair is then 31 bits total.
sym_buf starts one-fourth of the way into pending_buf. So there are
three bytes in sym_buf for every four bytes in pending_buf. Each symbol
in sym_buf is three bytes -- two for the distance and one for the
literal/length. As each symbol is consumed, the pointer to the next
sym_buf value to read moves forward three bytes. From that symbol, up to
31 bits are written to pending_buf. The closest the written pending_buf
bits gets to the next sym_buf symbol to read is just before the last
code is written. At that time, 31*(n-2) bits have been written, just
after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
symbols are written.) The closest the writing gets to what is unread is
then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
can range from 128 to 32768.
Therefore, at a minimum, there are 142 bits of space between what is
written and what is read in the overlain buffers, so the symbols cannot
be overwritten by the compressed data. That space is actually 139 bits,
due to the three-bit fixed-code block header.
That covers the case where either Z_FIXED is specified, forcing fixed
codes, or when the use of fixed codes is chosen, because that choice
results in a smaller compressed block than dynamic codes. That latter
condition then assures that the above analysis also covers all dynamic
blocks. A dynamic-code block will only be chosen to be emitted if it has
fewer bits than a fixed-code block would for the same set of symbols.
Therefore its average symbol length is assured to be less than 31. So
the compressed data for a dynamic block also cannot overwrite the
symbols from which it is being constructed.
*/
pending_buf_ =
buf_.get() + nwindow + nprev + nhead;
pending_buf_size_ =
static_cast<std::uint32_t>(lit_bufsize_) * 4;
sym_buf_ = pending_buf_ + lit_bufsize_;
sym_end_ = (lit_bufsize_ - 1) * 3;
pending_ = 0;
pending_out_ = pending_buf_;
@@ -698,7 +732,7 @@ init_block()
dyn_ltree_[END_BLOCK].fc = 1;
opt_len_ = 0L;
static_len_ = 0L;
last_lit_ = 0;
sym_next_ = 0;
matches_ = 0;
}
@@ -1155,16 +1189,17 @@ compress_block(
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned lx = 0; /* running index in l_buf */
unsigned sx = 0; /* running index in sym_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
if(last_lit_ != 0)
if(sym_next_ != 0)
{
do
{
dist = d_buf_[lx];
lc = l_buf_[lx++];
dist = sym_buf_[sx++] & 0xff;
dist += (unsigned)(sym_buf_[sx++] & 0xff) << 8;
lc = sym_buf_[sx++];
if(dist == 0)
{
send_code(lc, ltree); /* send a literal byte */
@@ -1194,9 +1229,9 @@ compress_block(
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
BOOST_ASSERT((uInt)(pending_) < lit_bufsize_ + 2*lx);
BOOST_ASSERT((uInt)(pending_) < lit_bufsize_ + sx);
}
while(lx < last_lit_);
while(sx < sym_next_);
}
send_code(END_BLOCK, ltree);
@@ -1205,9 +1240,9 @@ compress_block(
/* Check if the data type is TEXT or BINARY, using the following algorithm:
- TEXT if the two conditions below are satisfied:
a) There are no non-portable control characters belonging to the
"black list" (0..6, 14..25, 28..31).
"block list" (0..6, 14..25, 28..31).
b) There is at least one printable character belonging to the
"white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
"allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
- BINARY otherwise.
- The following partially-portable control characters form a
"gray list" that is ignored in this detection algorithm:
@@ -1218,19 +1253,19 @@ int
deflate_stream::
detect_data_type()
{
/* black_mask is the bit mask of black-listed bytes
/* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
unsigned long black_mask = 0xf3ffc07fUL;
unsigned long block_mask = 0xf3ffc07fUL;
int n;
// 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))
// Check for non-textual ("block-listed") bytes.
for(n = 0; n <= 31; n++, block_mask >>= 1)
if((block_mask & 1) && (dyn_ltree_[n].fc != 0))
return binary;
// Check for textual ("white-listed") bytes. */
// Check for textual ("allow-listed") bytes. */
if(dyn_ltree_[9].fc != 0 || dyn_ltree_[10].fc != 0
|| dyn_ltree_[13].fc != 0)
return text;
@@ -1238,7 +1273,7 @@ detect_data_type()
if(dyn_ltree_[n].fc != 0)
return text;
/* There are no "black-listed" or "white-listed" bytes:
/* There are no "block-listed" or "white-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only.
*/
return binary;
@@ -1295,9 +1330,9 @@ copy_block(
put_short((std::uint16_t)len);
put_short((std::uint16_t)~len);
}
// VFALCO Use memcpy?
while (len--)
put_byte(*buf++);
if(buf)
std::memcpy(&pending_buf_[pending_], buf, len);
pending_ += len;
}
//------------------------------------------------------------------------------
@@ -1362,22 +1397,24 @@ void
deflate_stream::
tr_tally_dist(std::uint16_t dist, std::uint8_t len, bool& flush)
{
d_buf_[last_lit_] = dist;
l_buf_[last_lit_++] = len;
sym_buf_[sym_next_++] = dist & 0xFF;
sym_buf_[sym_next_++] = dist >> 8;
sym_buf_[sym_next_++] = len;
dist--;
dyn_ltree_[lut_.length_code[len]+literals+1].fc++;
dyn_dtree_[d_code(dist)].fc++;
flush = (last_lit_ == lit_bufsize_-1);
flush = (sym_next_ == sym_end_);
}
void
deflate_stream::
tr_tally_lit(std::uint8_t c, bool& flush)
{
d_buf_[last_lit_] = 0;
l_buf_[last_lit_++] = c;
sym_buf_[sym_next_++] = 0;
sym_buf_[sym_next_++] = 0;
sym_buf_[sym_next_++] = c;
dyn_ltree_[c].fc++;
flush = (last_lit_ == lit_bufsize_-1);
flush = (sym_next_ == sym_end_);
}
//------------------------------------------------------------------------------
@@ -1522,6 +1559,8 @@ fill_window(z_params& zs)
match_start_ -= wsize;
strstart_ -= wsize; // we now have strstart >= max_dist
block_start_ -= (long) wsize;
if (insert_ > strstart_)
insert_ = strstart_;
/* Slide the hash table (could be avoided with 32 bit values
at the expense of memory usage). We slide even when level == 0
@@ -1990,7 +2029,7 @@ f_fast(z_params& zs, Flush flush) ->
return finish_started;
return finish_done;
}
if(last_lit_)
if(sym_next_)
{
flush_block(zs, false);
if(zs.avail_out == 0)
@@ -2135,7 +2174,7 @@ f_slow(z_params& zs, Flush flush) ->
return finish_started;
return finish_done;
}
if(last_lit_)
if(sym_next_)
{
flush_block(zs, false);
if(zs.avail_out == 0)
@@ -2221,7 +2260,7 @@ f_rle(z_params& zs, Flush flush) ->
return finish_started;
return finish_done;
}
if(last_lit_)
if(sym_next_)
{
flush_block(zs, false);
if(zs.avail_out == 0)
@@ -2275,7 +2314,7 @@ f_huff(z_params& zs, Flush flush) ->
return finish_started;
return finish_done;
}
if(last_lit_)
if(sym_next_)
{
flush_block(zs, false);
if(zs.avail_out == 0)

View File

@@ -113,12 +113,14 @@ doWrite(z_params& zs, Flush flush, error_code& ec)
if(((! r.in.used() && ! r.out.used()) ||
flush == Flush::finish) && ! ec)
ec = error::need_buffers;
{
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers);
}
};
auto const err =
[&](error e)
{
ec = e;
BOOST_BEAST_ASSIGN_EC(ec, e);
mode_ = BAD;
};
@@ -516,8 +518,10 @@ doWrite(z_params& zs, Flush flush, error_code& ec)
BOOST_FALLTHROUGH;
case DONE:
ec = error::end_of_stream;
{
BOOST_BEAST_ASSIGN_EC(ec, error::end_of_stream);
return done();
}
case BAD:
return done();
@@ -572,7 +576,7 @@ inflate_table(
code *next; // next available space in table
std::uint16_t const* base; // base value table to use
std::uint16_t const* extra; // extra bits table to use
int end; // use base and extra for symbol > end
unsigned match; // use base and extra for symbol >= match
std::uint16_t count[15+1]; // number of codes of each length
std::uint16_t offs[15+1]; // offsets in table for each length
@@ -584,7 +588,7 @@ inflate_table(
// Length codes 257..285 extra
static std::uint16_t constexpr lext[31] = {
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202};
// Distance codes 0..29 base
static std::uint16_t constexpr dbase[32] = {
@@ -666,13 +670,13 @@ inflate_table(
left -= count[len];
if (left < 0)
{
ec = error::over_subscribed_length;
BOOST_BEAST_ASSIGN_EC(ec, error::over_subscribed_length);
return;
}
}
if (left > 0 && (type == build::codes || max != 1))
{
ec = error::incomplete_length_set;
BOOST_BEAST_ASSIGN_EC(ec, error::incomplete_length_set);
return;
}
@@ -722,19 +726,17 @@ inflate_table(
{
case build::codes:
base = extra = work; /* dummy value--not used */
end = 19;
match = 20;
break;
case build::lens:
base = lbase;
base -= 257;
extra = lext;
extra -= 257;
end = 256;
match = 257;
break;
default: /* build::dists */
base = dbase;
extra = dext;
end = -1;
match = 0;
}
/* initialize state for loop */
@@ -764,15 +766,15 @@ inflate_table(
{
/* create table entry */
here.bits = (std::uint8_t)(len - drop);
if ((int)(work[sym]) < end)
if (work[sym] + 1U < match)
{
here.op = (std::uint8_t)0;
here.val = work[sym];
}
else if ((int)(work[sym]) > end)
else if (work[sym] >= match)
{
here.op = (std::uint8_t)(extra[work[sym]]);
here.val = base[work[sym]];
here.op = (std::uint8_t)(extra[work[sym] - match]);
here.val = base[work[sym] - match];
}
else
{
@@ -1039,7 +1041,7 @@ inflate_fast(ranges& r, error_code& ec)
#ifdef INFLATE_STRICT
if(dist > dmax_)
{
ec = error::invalid_distance;
BOOST_BEAST_ASSIGN_EC(ec, error::invalid_distance);
mode_ = BAD;
break;
}
@@ -1053,7 +1055,7 @@ inflate_fast(ranges& r, error_code& ec)
op = dist - op; // distance back in window
if(op > w_.size())
{
ec = error::invalid_distance;
BOOST_BEAST_ASSIGN_EC(ec, error::invalid_distance);
mode_ = BAD;
break;
}
@@ -1080,7 +1082,7 @@ inflate_fast(ranges& r, error_code& ec)
}
else
{
ec = error::invalid_distance_code;
BOOST_BEAST_ASSIGN_EC(ec, error::invalid_distance_code);
mode_ = BAD;
break;
}
@@ -1099,7 +1101,7 @@ inflate_fast(ranges& r, error_code& ec)
}
else
{
ec = error::invalid_literal_length;
BOOST_BEAST_ASSIGN_EC(ec, error::invalid_literal_length);
mode_ = BAD;
break;
}