parent
79cbb00075
commit
58ad9e27f4
6
deps/PackageList.txt
vendored
6
deps/PackageList.txt
vendored
@ -44,9 +44,9 @@ utf8-cpp (UTF-8 with C++ in a Portable Way)
|
||||
http://utfcpp.sourceforge.net/
|
||||
Version: 2.3.4
|
||||
|
||||
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library - fork of Cloudflare)
|
||||
https://github.com/cloudflare/zlib (based on http://www.zlib.net/)
|
||||
Version: 23-12-2024
|
||||
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library)
|
||||
http://www.zlib.net/
|
||||
Version: 1.2.12
|
||||
|
||||
gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings)
|
||||
http://gsoap2.sourceforge.net/
|
||||
|
||||
4
deps/g3dlite/source/BinaryInput.cpp
vendored
4
deps/g3dlite/source/BinaryInput.cpp
vendored
@ -89,7 +89,7 @@ BinaryInput::BinaryInput(
|
||||
debugAssert(m_freeBuffer);
|
||||
m_buffer = (uint8*)System::alignedMalloc(m_length, 16);
|
||||
|
||||
uint64_t L = (uint64_t)m_length;
|
||||
unsigned long L = (unsigned long)m_length;
|
||||
// Decompress with zlib
|
||||
int64 result = uncompress(m_buffer, &L, data + 4, (uLong)dataLen - 4);
|
||||
m_length = L;
|
||||
@ -257,7 +257,7 @@ void BinaryInput::decompress() {
|
||||
debugAssert(isValidHeapPointer(tempBuffer));
|
||||
debugAssert(isValidHeapPointer(m_buffer));
|
||||
|
||||
uint64_t L = (uint64_t)m_length;
|
||||
unsigned long L = (unsigned long)m_length;
|
||||
int64 result = (int64)uncompress(m_buffer, &L, tempBuffer + 4, (uLong)tempLength - 4);
|
||||
m_length = L;
|
||||
m_bufferLength = m_length;
|
||||
|
||||
2
deps/g3dlite/source/BinaryOutput.cpp
vendored
2
deps/g3dlite/source/BinaryOutput.cpp
vendored
@ -281,7 +281,7 @@ void BinaryOutput::compress(int level) {
|
||||
alwaysAssertM(m_bufferLen < 0xFFFFFFFF, "Compress only works for 32-bit files.");
|
||||
|
||||
// This is the worst-case size, as mandated by zlib
|
||||
uint64_t compressedSize = iCeil(m_bufferLen * 1.001) + 12;
|
||||
unsigned long compressedSize = iCeil(m_bufferLen * 1.001) + 12;
|
||||
|
||||
// Save the old buffer and reallocate to the worst-case size
|
||||
const uint8* src = m_buffer;
|
||||
|
||||
41
deps/zlib/adler32.c
vendored
41
deps/zlib/adler32.c
vendored
@ -7,6 +7,8 @@
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
||||
|
||||
#define BASE 65521U /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
@ -57,20 +59,15 @@
|
||||
# define MOD63(a) a %= BASE
|
||||
#endif
|
||||
|
||||
#if defined(ADLER32_SIMD_NEON) || defined (ADLER32_SIMD_SSSE3)
|
||||
#include "adler32_simd.h"
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
|
||||
uLong ZEXPORT adler32_z(adler, buf, len)
|
||||
uLong adler;
|
||||
const Bytef *buf;
|
||||
z_size_t len;
|
||||
{
|
||||
unsigned long sum2;
|
||||
unsigned n;
|
||||
|
||||
#if defined(ADLER32_SIMD_NEON) || defined(ADLER32_SIMD_SSSE3)
|
||||
if (buf && len >= 64)
|
||||
return adler32_simd_(adler, buf, len);
|
||||
#endif
|
||||
|
||||
/* split Adler-32 into component sums */
|
||||
sum2 = (adler >> 16) & 0xffff;
|
||||
adler &= 0xffff;
|
||||
@ -134,12 +131,20 @@ uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
|
||||
uLong ZEXPORT adler32(adler, buf, len)
|
||||
uLong adler;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
return adler32_z(adler, buf, len);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||
local uLong adler32_combine_(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned rem;
|
||||
@ -164,10 +169,18 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
|
||||
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off_t len2;
|
||||
{
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
|
||||
uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
|
||||
387
deps/zlib/adler32_simd.c
vendored
387
deps/zlib/adler32_simd.c
vendored
@ -1,387 +0,0 @@
|
||||
/* adler32_simd.c
|
||||
*
|
||||
* (C) 1995-2013 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Jean-loup Gailly Mark Adler
|
||||
* jloup@gzip.org madler@alumni.caltech.edu
|
||||
*
|
||||
* Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the Chromium source repository LICENSE file.
|
||||
*
|
||||
* Per http://en.wikipedia.org/wiki/Adler-32 the adler32 A value (aka s1) is
|
||||
* the sum of N input data bytes D1 ... DN,
|
||||
*
|
||||
* A = A0 + D1 + D2 + ... + DN
|
||||
*
|
||||
* where A0 is the initial value.
|
||||
*
|
||||
* SSE2 _mm_sad_epu8() can be used for byte sums (see http://bit.ly/2wpUOeD,
|
||||
* for example) and accumulating the byte sums can use SSE shuffle-adds (see
|
||||
* the "Integer" section of http://bit.ly/2erPT8t for details). Arm NEON has
|
||||
* similar instructions.
|
||||
*
|
||||
* The adler32 B value (aka s2) sums the A values from each step:
|
||||
*
|
||||
* B0 + (A0 + D1) + (A0 + D1 + D2) + ... + (A0 + D1 + D2 + ... + DN) or
|
||||
*
|
||||
* B0 + N.A0 + N.D1 + (N-1).D2 + (N-2).D3 + ... + (N-(N-1)).DN
|
||||
*
|
||||
* B0 being the initial value. For 32 bytes (ideal for garden-variety SIMD):
|
||||
*
|
||||
* B = B0 + 32.A0 + [D1 D2 D3 ... D32] x [32 31 30 ... 1].
|
||||
*
|
||||
* Adjacent blocks of 32 input bytes can be iterated with the expressions to
|
||||
* compute the adler32 s1 s2 of M >> 32 input bytes [1].
|
||||
*
|
||||
* As M grows, the s1 s2 sums grow. If left unchecked, they would eventually
|
||||
* overflow the precision of their integer representation (bad). However, s1
|
||||
* and s2 also need to be computed modulo the adler BASE value (reduced). If
|
||||
* at most NMAX bytes are processed before a reduce, s1 s2 _cannot_ overflow
|
||||
* a uint32_t type (the NMAX constraint) [2].
|
||||
*
|
||||
* [1] the iterative equations for s2 contain constant factors; these can be
|
||||
* hoisted from the n-blocks do loop of the SIMD code.
|
||||
*
|
||||
* [2] zlib adler32_z() uses this fact to implement NMAX-block-based updates
|
||||
* of the adler s1 s2 of uint32_t type (see adler32.c).
|
||||
*/
|
||||
|
||||
#include "adler32_simd.h"
|
||||
|
||||
/* Definitions from adler32.c: largest prime smaller than 65536 */
|
||||
#define BASE 65521U
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
#define NMAX 5552
|
||||
|
||||
#if defined(ADLER32_SIMD_SSSE3)
|
||||
|
||||
#include <tmmintrin.h>
|
||||
|
||||
uint32_t ZLIB_INTERNAL adler32_simd_( /* SSSE3 */
|
||||
uint32_t adler,
|
||||
const unsigned char *buf,
|
||||
unsigned long len)
|
||||
{
|
||||
/*
|
||||
* Split Adler-32 into component sums.
|
||||
*/
|
||||
uint32_t s1 = adler & 0xffff;
|
||||
uint32_t s2 = adler >> 16;
|
||||
|
||||
/*
|
||||
* Process the data in blocks.
|
||||
*/
|
||||
const unsigned BLOCK_SIZE = 1 << 5;
|
||||
|
||||
unsigned long blocks = len / BLOCK_SIZE;
|
||||
len -= blocks * BLOCK_SIZE;
|
||||
|
||||
while (blocks)
|
||||
{
|
||||
unsigned n = NMAX / BLOCK_SIZE; /* The NMAX constraint. */
|
||||
if (n > blocks)
|
||||
n = (unsigned) blocks;
|
||||
blocks -= n;
|
||||
|
||||
const __m128i tap1 =
|
||||
_mm_setr_epi8(32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17);
|
||||
const __m128i tap2 =
|
||||
_mm_setr_epi8(16,15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
|
||||
const __m128i zero =
|
||||
_mm_setr_epi8( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
const __m128i ones =
|
||||
_mm_set_epi16( 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
|
||||
/*
|
||||
* Process n blocks of data. At most NMAX data bytes can be
|
||||
* processed before s2 must be reduced modulo BASE.
|
||||
*/
|
||||
__m128i v_ps = _mm_set_epi32(0, 0, 0, s1 * n);
|
||||
__m128i v_s2 = _mm_set_epi32(0, 0, 0, s2);
|
||||
__m128i v_s1 = _mm_set_epi32(0, 0, 0, 0);
|
||||
|
||||
do {
|
||||
/*
|
||||
* Load 32 input bytes.
|
||||
*/
|
||||
const __m128i bytes1 = _mm_loadu_si128((__m128i*)(buf));
|
||||
const __m128i bytes2 = _mm_loadu_si128((__m128i*)(buf + 16));
|
||||
|
||||
/*
|
||||
* Add previous block byte sum to v_ps.
|
||||
*/
|
||||
v_ps = _mm_add_epi32(v_ps, v_s1);
|
||||
|
||||
/*
|
||||
* Horizontally add the bytes for s1, multiply-adds the
|
||||
* bytes by [ 32, 31, 30, ... ] for s2.
|
||||
*/
|
||||
v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes1, zero));
|
||||
const __m128i mad1 = _mm_maddubs_epi16(bytes1, tap1);
|
||||
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(mad1, ones));
|
||||
|
||||
v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes2, zero));
|
||||
const __m128i mad2 = _mm_maddubs_epi16(bytes2, tap2);
|
||||
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(mad2, ones));
|
||||
|
||||
buf += BLOCK_SIZE;
|
||||
|
||||
} while (--n);
|
||||
|
||||
v_s2 = _mm_add_epi32(v_s2, _mm_slli_epi32(v_ps, 5));
|
||||
|
||||
/*
|
||||
* Sum epi32 ints v_s1(s2) and accumulate in s1(s2).
|
||||
*/
|
||||
|
||||
#define S23O1 _MM_SHUFFLE(2,3,0,1) /* A B C D -> B A D C */
|
||||
#define S1O32 _MM_SHUFFLE(1,0,3,2) /* A B C D -> C D A B */
|
||||
|
||||
v_s1 = _mm_add_epi32(v_s1, _mm_shuffle_epi32(v_s1, S23O1));
|
||||
v_s1 = _mm_add_epi32(v_s1, _mm_shuffle_epi32(v_s1, S1O32));
|
||||
|
||||
s1 += _mm_cvtsi128_si32(v_s1);
|
||||
|
||||
v_s2 = _mm_add_epi32(v_s2, _mm_shuffle_epi32(v_s2, S23O1));
|
||||
v_s2 = _mm_add_epi32(v_s2, _mm_shuffle_epi32(v_s2, S1O32));
|
||||
|
||||
s2 = _mm_cvtsi128_si32(v_s2);
|
||||
|
||||
#undef S23O1
|
||||
#undef S1O32
|
||||
|
||||
/*
|
||||
* Reduce.
|
||||
*/
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle leftover data.
|
||||
*/
|
||||
if (len) {
|
||||
if (len >= 16) {
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
len -= 16;
|
||||
}
|
||||
|
||||
while (len--) {
|
||||
s2 += (s1 += *buf++);
|
||||
}
|
||||
|
||||
if (s1 >= BASE)
|
||||
s1 -= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the recombined sums.
|
||||
*/
|
||||
return s1 | (s2 << 16);
|
||||
}
|
||||
|
||||
#elif defined(ADLER32_SIMD_NEON)
|
||||
|
||||
#include <arm_neon.h>
|
||||
|
||||
uint32_t ZLIB_INTERNAL adler32_simd_( /* NEON */
|
||||
uint32_t adler,
|
||||
const unsigned char *buf,
|
||||
unsigned long len)
|
||||
{
|
||||
/*
|
||||
* Split Adler-32 into component sums.
|
||||
*/
|
||||
uint32_t s1 = adler & 0xffff;
|
||||
uint32_t s2 = adler >> 16;
|
||||
|
||||
/*
|
||||
* Serially compute s1 & s2, until the data is 16-byte aligned.
|
||||
*/
|
||||
if ((uintptr_t)buf & 15) {
|
||||
while ((uintptr_t)buf & 15) {
|
||||
s2 += (s1 += *buf++);
|
||||
--len;
|
||||
}
|
||||
|
||||
if (s1 >= BASE)
|
||||
s1 -= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process the data in blocks.
|
||||
*/
|
||||
const unsigned BLOCK_SIZE = 1 << 5;
|
||||
|
||||
unsigned long blocks = len / BLOCK_SIZE;
|
||||
len -= blocks * BLOCK_SIZE;
|
||||
|
||||
while (blocks)
|
||||
{
|
||||
unsigned n = NMAX / BLOCK_SIZE; /* The NMAX constraint. */
|
||||
if (n > blocks)
|
||||
n = blocks;
|
||||
blocks -= n;
|
||||
|
||||
/*
|
||||
* Process n blocks of data. At most NMAX data bytes can be
|
||||
* processed before s2 must be reduced modulo BASE.
|
||||
*/
|
||||
uint32x4_t v_s2 = (uint32x4_t) { 0, 0, 0, s1 * n };
|
||||
uint32x4_t v_s1 = (uint32x4_t) { 0, 0, 0, 0 };
|
||||
|
||||
uint16x8_t v_column_sum_1 = vdupq_n_u16(0);
|
||||
uint16x8_t v_column_sum_2 = vdupq_n_u16(0);
|
||||
uint16x8_t v_column_sum_3 = vdupq_n_u16(0);
|
||||
uint16x8_t v_column_sum_4 = vdupq_n_u16(0);
|
||||
|
||||
do {
|
||||
/*
|
||||
* Load 32 input bytes.
|
||||
*/
|
||||
const uint8x16_t bytes1 = vld1q_u8((uint8_t*)(buf));
|
||||
const uint8x16_t bytes2 = vld1q_u8((uint8_t*)(buf + 16));
|
||||
|
||||
/*
|
||||
* Add previous block byte sum to v_s2.
|
||||
*/
|
||||
v_s2 = vaddq_u32(v_s2, v_s1);
|
||||
|
||||
/*
|
||||
* Horizontally add the bytes for s1.
|
||||
*/
|
||||
v_s1 = vpadalq_u16(v_s1, vpadalq_u8(vpaddlq_u8(bytes1), bytes2));
|
||||
|
||||
/*
|
||||
* Vertically add the bytes for s2.
|
||||
*/
|
||||
v_column_sum_1 = vaddw_u8(v_column_sum_1, vget_low_u8 (bytes1));
|
||||
v_column_sum_2 = vaddw_u8(v_column_sum_2, vget_high_u8(bytes1));
|
||||
v_column_sum_3 = vaddw_u8(v_column_sum_3, vget_low_u8 (bytes2));
|
||||
v_column_sum_4 = vaddw_u8(v_column_sum_4, vget_high_u8(bytes2));
|
||||
|
||||
buf += BLOCK_SIZE;
|
||||
|
||||
} while (--n);
|
||||
|
||||
v_s2 = vshlq_n_u32(v_s2, 5);
|
||||
|
||||
/*
|
||||
* Multiply-add bytes by [ 32, 31, 30, ... ] for s2.
|
||||
*/
|
||||
v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_1),
|
||||
(uint16x4_t) { 32, 31, 30, 29 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1),
|
||||
(uint16x4_t) { 28, 27, 26, 25 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_2),
|
||||
(uint16x4_t) { 24, 23, 22, 21 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_2),
|
||||
(uint16x4_t) { 20, 19, 18, 17 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_3),
|
||||
(uint16x4_t) { 16, 15, 14, 13 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_3),
|
||||
(uint16x4_t) { 12, 11, 10, 9 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_4),
|
||||
(uint16x4_t) { 8, 7, 6, 5 });
|
||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_4),
|
||||
(uint16x4_t) { 4, 3, 2, 1 });
|
||||
|
||||
/*
|
||||
* Sum epi32 ints v_s1(s2) and accumulate in s1(s2).
|
||||
*/
|
||||
uint32x2_t sum1 = vpadd_u32(vget_low_u32(v_s1), vget_high_u32(v_s1));
|
||||
uint32x2_t sum2 = vpadd_u32(vget_low_u32(v_s2), vget_high_u32(v_s2));
|
||||
uint32x2_t s1s2 = vpadd_u32(sum1, sum2);
|
||||
|
||||
s1 += vget_lane_u32(s1s2, 0);
|
||||
s2 += vget_lane_u32(s1s2, 1);
|
||||
|
||||
/*
|
||||
* Reduce.
|
||||
*/
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle leftover data.
|
||||
*/
|
||||
if (len) {
|
||||
if (len >= 16) {
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
s2 += (s1 += *buf++);
|
||||
|
||||
len -= 16;
|
||||
}
|
||||
|
||||
while (len--) {
|
||||
s2 += (s1 += *buf++);
|
||||
}
|
||||
|
||||
if (s1 >= BASE)
|
||||
s1 -= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the recombined sums.
|
||||
*/
|
||||
return s1 | (s2 << 16);
|
||||
}
|
||||
|
||||
#endif /* ADLER32_SIMD_SSSE3 */
|
||||
37
deps/zlib/adler32_simd.h
vendored
37
deps/zlib/adler32_simd.h
vendored
@ -1,37 +0,0 @@
|
||||
/* adler32_simd.h
|
||||
*
|
||||
* (C) 1995-2013 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Jean-loup Gailly Mark Adler
|
||||
* jloup@gzip.org madler@alumni.caltech.edu
|
||||
*
|
||||
* Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the Chromium source repository LICENSE file.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "zconf.h"
|
||||
#include "zutil.h"
|
||||
|
||||
uint32_t ZLIB_INTERNAL adler32_simd_(
|
||||
uint32_t adler,
|
||||
const unsigned char *buf,
|
||||
unsigned long len);
|
||||
558
deps/zlib/chunkcopy.h
vendored
558
deps/zlib/chunkcopy.h
vendored
@ -1,558 +0,0 @@
|
||||
/* chunkcopy.h -- fast chunk copy and set operations
|
||||
*
|
||||
* (C) 1995-2013 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Jean-loup Gailly Mark Adler
|
||||
* jloup@gzip.org madler@alumni.caltech.edu
|
||||
*
|
||||
* Copyright (C) 2017 ARM, Inc.
|
||||
* Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the Chromium source repository LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef CHUNKCOPY_H
|
||||
#define CHUNKCOPY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "zutil.h"
|
||||
|
||||
#define Z_STATIC_ASSERT(name, assert) typedef char name[(assert) ? 1 : -1]
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
#define Z_RESTRICT restrict
|
||||
#else
|
||||
#define Z_RESTRICT
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__llvm__)
|
||||
#define Z_BUILTIN_MEMCPY __builtin_memcpy
|
||||
#define Z_BUILTIN_MEMSET __builtin_memset
|
||||
#else
|
||||
#define Z_BUILTIN_MEMCPY zmemcpy
|
||||
#define Z_BUILTIN_MEMSET zmemset
|
||||
#endif
|
||||
|
||||
#if defined(INFLATE_CHUNK_SIMD_NEON)
|
||||
#include <arm_neon.h>
|
||||
typedef uint8x16_t z_vec128i_t;
|
||||
#elif defined(INFLATE_CHUNK_SIMD_SSE2)
|
||||
#include <emmintrin.h>
|
||||
typedef __m128i z_vec128i_t;
|
||||
#else
|
||||
typedef struct { uint8_t x[16]; } z_vec128i_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* chunk copy type: the z_vec128i_t type size should be exactly 128-bits
|
||||
* and equal to CHUNKCOPY_CHUNK_SIZE.
|
||||
*/
|
||||
#define CHUNKCOPY_CHUNK_SIZE sizeof(z_vec128i_t)
|
||||
|
||||
Z_STATIC_ASSERT(vector_128_bits_wide,
|
||||
CHUNKCOPY_CHUNK_SIZE == sizeof(int8_t) * 16);
|
||||
|
||||
/*
|
||||
* Ask the compiler to perform a wide, unaligned load with a machine
|
||||
* instruction appropriate for the z_vec128i_t type.
|
||||
*/
|
||||
static inline z_vec128i_t loadchunk(
|
||||
const unsigned char FAR* s) {
|
||||
z_vec128i_t v;
|
||||
Z_BUILTIN_MEMCPY(&v, s, sizeof(v));
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask the compiler to perform a wide, unaligned store with a machine
|
||||
* instruction appropriate for the z_vec128i_t type.
|
||||
*/
|
||||
static inline void storechunk(
|
||||
unsigned char FAR* d,
|
||||
const z_vec128i_t v) {
|
||||
Z_BUILTIN_MEMCPY(d, &v, sizeof(v));
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform a memcpy-like operation, assuming that length is non-zero and that
|
||||
* it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE bytes of output even if
|
||||
* the length is shorter than this.
|
||||
*
|
||||
* It also guarantees that it will properly unroll the data if the distance
|
||||
* between `out` and `from` is at least CHUNKCOPY_CHUNK_SIZE, which we rely on
|
||||
* in chunkcopy_relaxed().
|
||||
*
|
||||
* Aside from better memory bus utilisation, this means that short copies
|
||||
* (CHUNKCOPY_CHUNK_SIZE bytes or fewer) will fall straight through the loop
|
||||
* without iteration, which will hopefully make the branch prediction more
|
||||
* reliable.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkcopy_core(
|
||||
unsigned char FAR* out,
|
||||
const unsigned char FAR* from,
|
||||
unsigned len) {
|
||||
const int bump = (--len % CHUNKCOPY_CHUNK_SIZE) + 1;
|
||||
storechunk(out, loadchunk(from));
|
||||
out += bump;
|
||||
from += bump;
|
||||
len /= CHUNKCOPY_CHUNK_SIZE;
|
||||
while (len-- > 0) {
|
||||
storechunk(out, loadchunk(from));
|
||||
out += CHUNKCOPY_CHUNK_SIZE;
|
||||
from += CHUNKCOPY_CHUNK_SIZE;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like chunkcopy_core(), but avoid writing beyond of legal output.
|
||||
*
|
||||
* Accepts an additional pointer to the end of safe output. A generic safe
|
||||
* copy would use (out + len), but it's normally the case that the end of the
|
||||
* output buffer is beyond the end of the current copy, and this can still be
|
||||
* exploited.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkcopy_core_safe(
|
||||
unsigned char FAR* out,
|
||||
const unsigned char FAR* from,
|
||||
unsigned len,
|
||||
unsigned char FAR* limit) {
|
||||
Assert(out + len <= limit, "chunk copy exceeds safety limit");
|
||||
if ((limit - out) < (ptrdiff_t)CHUNKCOPY_CHUNK_SIZE) {
|
||||
const unsigned char FAR* Z_RESTRICT rfrom = from;
|
||||
if (len & 8) {
|
||||
Z_BUILTIN_MEMCPY(out, rfrom, 8);
|
||||
out += 8;
|
||||
rfrom += 8;
|
||||
}
|
||||
if (len & 4) {
|
||||
Z_BUILTIN_MEMCPY(out, rfrom, 4);
|
||||
out += 4;
|
||||
rfrom += 4;
|
||||
}
|
||||
if (len & 2) {
|
||||
Z_BUILTIN_MEMCPY(out, rfrom, 2);
|
||||
out += 2;
|
||||
rfrom += 2;
|
||||
}
|
||||
if (len & 1) {
|
||||
*out++ = *rfrom++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return chunkcopy_core(out, from, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform short copies until distance can be rewritten as being at least
|
||||
* CHUNKCOPY_CHUNK_SIZE.
|
||||
*
|
||||
* Assumes it's OK to overwrite at least the first 2*CHUNKCOPY_CHUNK_SIZE
|
||||
* bytes of output even if the copy is shorter than this. This assumption
|
||||
* holds within zlib inflate_fast(), which starts every iteration with at
|
||||
* least 258 bytes of output space available (258 being the maximum length
|
||||
* output from a single token; see inffast.c).
|
||||
*/
|
||||
static inline unsigned char FAR* chunkunroll_relaxed(
|
||||
unsigned char FAR* out,
|
||||
unsigned FAR* dist,
|
||||
unsigned FAR* len) {
|
||||
const unsigned char FAR* from = out - *dist;
|
||||
while (*dist < *len && *dist < CHUNKCOPY_CHUNK_SIZE) {
|
||||
storechunk(out, loadchunk(from));
|
||||
out += *dist;
|
||||
*len -= *dist;
|
||||
*dist += *dist;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#if defined(INFLATE_CHUNK_SIMD_NEON)
|
||||
/*
|
||||
* v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in
|
||||
* every 64-bit component of the 128-bit result (64-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load64_dup(const void* src) {
|
||||
return vcombine_u8(vld1_u8(src), vld1_u8(src));
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in
|
||||
* every 32-bit component of the 128-bit result (32-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load32_dup(const void* src) {
|
||||
int32_t i32;
|
||||
Z_BUILTIN_MEMCPY(&i32, src, sizeof(i32));
|
||||
return vreinterpretq_u8_s32(vdupq_n_s32(i32));
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in
|
||||
* every 16-bit component of the 128-bit result (16-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load16_dup(const void* src) {
|
||||
int16_t i16;
|
||||
Z_BUILTIN_MEMCPY(&i16, src, sizeof(i16));
|
||||
return vreinterpretq_u8_s16(vdupq_n_s16(i16));
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit
|
||||
* component of the 128-bit result (8-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load8_dup(const void* src) {
|
||||
return vld1q_dup_u8((const uint8_t*)src);
|
||||
}
|
||||
|
||||
/*
|
||||
* v_store_128(): store the 128-bit vec in a memory destination (that might
|
||||
* not be 16-byte aligned) void* out.
|
||||
*/
|
||||
static inline void v_store_128(void* out, const z_vec128i_t vec) {
|
||||
vst1q_u8(out, vec);
|
||||
}
|
||||
#elif defined (INFLATE_CHUNK_SIMD_SSE2)
|
||||
/*
|
||||
* v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in
|
||||
* every 64-bit component of the 128-bit result (64-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load64_dup(const void* src) {
|
||||
int64_t i64;
|
||||
Z_BUILTIN_MEMCPY(&i64, src, sizeof(i64));
|
||||
return _mm_set1_epi64x(i64);
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in
|
||||
* every 32-bit component of the 128-bit result (32-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load32_dup(const void* src) {
|
||||
int32_t i32;
|
||||
Z_BUILTIN_MEMCPY(&i32, src, sizeof(i32));
|
||||
return _mm_set1_epi32(i32);
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in
|
||||
* every 16-bit component of the 128-bit result (16-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load16_dup(const void* src) {
|
||||
int16_t i16;
|
||||
Z_BUILTIN_MEMCPY(&i16, src, sizeof(i16));
|
||||
return _mm_set1_epi16(i16);
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit
|
||||
* component of the 128-bit result (8-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load8_dup(const void* src) {
|
||||
return _mm_set1_epi8(*(const char*)src);
|
||||
}
|
||||
|
||||
/*
|
||||
* v_store_128(): store the 128-bit vec in a memory destination (that might
|
||||
* not be 16-byte aligned) void* out.
|
||||
*/
|
||||
static inline void v_store_128(void* out, const z_vec128i_t vec) {
|
||||
_mm_storeu_si128((__m128i*)out, vec);
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Default implementations for chunk-copy functions rely on memcpy() being
|
||||
* inlined by the compiler for best performance. This is most likely to work
|
||||
* as expected when the length argument is constant (as is the case here) and
|
||||
* the target supports unaligned loads and stores. Since that's not always a
|
||||
* safe assumption, this may need extra compiler arguments such as
|
||||
* `-mno-strict-align` or `-munaligned-access`, or the availability of
|
||||
* extensions like SIMD.
|
||||
*/
|
||||
|
||||
/*
|
||||
* v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in
|
||||
* every 64-bit component of the 128-bit result (64-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load64_dup(const void* src) {
|
||||
int64_t in;
|
||||
Z_BUILTIN_MEMCPY(&in, src, sizeof(in));
|
||||
z_vec128i_t out;
|
||||
for (int i = 0; i < sizeof(out); i += sizeof(in)) {
|
||||
Z_BUILTIN_MEMCPY((uint8_t*)&out + i, &in, sizeof(in));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in
|
||||
* every 32-bit component of the 128-bit result (32-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load32_dup(const void* src) {
|
||||
int32_t in;
|
||||
Z_BUILTIN_MEMCPY(&in, src, sizeof(in));
|
||||
z_vec128i_t out;
|
||||
for (int i = 0; i < sizeof(out); i += sizeof(in)) {
|
||||
Z_BUILTIN_MEMCPY((uint8_t*)&out + i, &in, sizeof(in));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in
|
||||
* every 16-bit component of the 128-bit result (16-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load16_dup(const void* src) {
|
||||
int16_t in;
|
||||
Z_BUILTIN_MEMCPY(&in, src, sizeof(in));
|
||||
z_vec128i_t out;
|
||||
for (int i = 0; i < sizeof(out); i += sizeof(in)) {
|
||||
Z_BUILTIN_MEMCPY((uint8_t*)&out + i, &in, sizeof(in));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit
|
||||
* component of the 128-bit result (8-bit int splat).
|
||||
*/
|
||||
static inline z_vec128i_t v_load8_dup(const void* src) {
|
||||
int8_t in = *(uint8_t const*)src;
|
||||
z_vec128i_t out;
|
||||
Z_BUILTIN_MEMSET(&out, in, sizeof(out));
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* v_store_128(): store the 128-bit vec in a memory destination (that might
|
||||
* not be 16-byte aligned) void* out.
|
||||
*/
|
||||
static inline void v_store_128(void* out, const z_vec128i_t vec) {
|
||||
Z_BUILTIN_MEMCPY(out, &vec, sizeof(vec));
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Perform an overlapping copy which behaves as a memset() operation, but
|
||||
* supporting periods other than one, and assume that length is non-zero and
|
||||
* that it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE*3 bytes of output
|
||||
* even if the length is shorter than this.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkset_core(
|
||||
unsigned char FAR* out,
|
||||
unsigned period,
|
||||
unsigned len) {
|
||||
z_vec128i_t v;
|
||||
const int bump = ((len - 1) % sizeof(v)) + 1;
|
||||
|
||||
switch (period) {
|
||||
case 1:
|
||||
v = v_load8_dup(out - 1);
|
||||
v_store_128(out, v);
|
||||
out += bump;
|
||||
len -= bump;
|
||||
while (len > 0) {
|
||||
v_store_128(out, v);
|
||||
out += sizeof(v);
|
||||
len -= sizeof(v);
|
||||
}
|
||||
return out;
|
||||
case 2:
|
||||
v = v_load16_dup(out - 2);
|
||||
v_store_128(out, v);
|
||||
out += bump;
|
||||
len -= bump;
|
||||
if (len > 0) {
|
||||
v = v_load16_dup(out - 2);
|
||||
do {
|
||||
v_store_128(out, v);
|
||||
out += sizeof(v);
|
||||
len -= sizeof(v);
|
||||
} while (len > 0);
|
||||
}
|
||||
return out;
|
||||
case 4:
|
||||
v = v_load32_dup(out - 4);
|
||||
v_store_128(out, v);
|
||||
out += bump;
|
||||
len -= bump;
|
||||
if (len > 0) {
|
||||
v = v_load32_dup(out - 4);
|
||||
do {
|
||||
v_store_128(out, v);
|
||||
out += sizeof(v);
|
||||
len -= sizeof(v);
|
||||
} while (len > 0);
|
||||
}
|
||||
return out;
|
||||
case 8:
|
||||
v = v_load64_dup(out - 8);
|
||||
v_store_128(out, v);
|
||||
out += bump;
|
||||
len -= bump;
|
||||
if (len > 0) {
|
||||
v = v_load64_dup(out - 8);
|
||||
do {
|
||||
v_store_128(out, v);
|
||||
out += sizeof(v);
|
||||
len -= sizeof(v);
|
||||
} while (len > 0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
out = chunkunroll_relaxed(out, &period, &len);
|
||||
return chunkcopy_core(out, out - period, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform a memcpy-like operation, but assume that length is non-zero and that
|
||||
* it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE bytes of output even if
|
||||
* the length is shorter than this.
|
||||
*
|
||||
* Unlike chunkcopy_core() above, no guarantee is made regarding the behaviour
|
||||
* of overlapping buffers, regardless of the distance between the pointers.
|
||||
* This is reflected in the `restrict`-qualified pointers, allowing the
|
||||
* compiler to re-order loads and stores.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkcopy_relaxed(
|
||||
unsigned char FAR* Z_RESTRICT out,
|
||||
const unsigned char FAR* Z_RESTRICT from,
|
||||
unsigned len) {
|
||||
return chunkcopy_core(out, from, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like chunkcopy_relaxed(), but avoid writing beyond of legal output.
|
||||
*
|
||||
* Unlike chunkcopy_core_safe() above, no guarantee is made regarding the
|
||||
* behaviour of overlapping buffers, regardless of the distance between the
|
||||
* pointers. This is reflected in the `restrict`-qualified pointers, allowing
|
||||
* the compiler to re-order loads and stores.
|
||||
*
|
||||
* Accepts an additional pointer to the end of safe output. A generic safe
|
||||
* copy would use (out + len), but it's normally the case that the end of the
|
||||
* output buffer is beyond the end of the current copy, and this can still be
|
||||
* exploited.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkcopy_safe(
|
||||
unsigned char FAR* out,
|
||||
const unsigned char FAR* Z_RESTRICT from,
|
||||
unsigned len,
|
||||
unsigned char FAR* limit) {
|
||||
Assert(out + len <= limit, "chunk copy exceeds safety limit");
|
||||
return chunkcopy_core_safe(out, from, len, limit);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform chunky copy within the same buffer, where the source and destination
|
||||
* may potentially overlap.
|
||||
*
|
||||
* Assumes that len > 0 on entry, and that it's safe to write at least
|
||||
* CHUNKCOPY_CHUNK_SIZE*3 bytes to the output.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkcopy_lapped_relaxed(
|
||||
unsigned char FAR* out,
|
||||
unsigned dist,
|
||||
unsigned len) {
|
||||
if (dist < len && dist < CHUNKCOPY_CHUNK_SIZE) {
|
||||
return chunkset_core(out, dist, len);
|
||||
}
|
||||
return chunkcopy_core(out, out - dist, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Behave like chunkcopy_lapped_relaxed(), but avoid writing beyond of legal
|
||||
* output.
|
||||
*
|
||||
* Accepts an additional pointer to the end of safe output. A generic safe
|
||||
* copy would use (out + len), but it's normally the case that the end of the
|
||||
* output buffer is beyond the end of the current copy, and this can still be
|
||||
* exploited.
|
||||
*/
|
||||
static inline unsigned char FAR* chunkcopy_lapped_safe(
|
||||
unsigned char FAR* out,
|
||||
unsigned dist,
|
||||
unsigned len,
|
||||
unsigned char FAR* limit) {
|
||||
Assert(out + len <= limit, "chunk copy exceeds safety limit");
|
||||
if ((limit - out) < (ptrdiff_t)(3 * CHUNKCOPY_CHUNK_SIZE)) {
|
||||
/* TODO(cavalcantii): try harder to optimise this */
|
||||
while (len-- > 0) {
|
||||
*out = *(out - dist);
|
||||
out++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return chunkcopy_lapped_relaxed(out, dist, len);
|
||||
}
|
||||
|
||||
/* TODO(cavalcanti): see crbug.com/1110083. */
|
||||
static inline unsigned char FAR* chunkcopy_safe_ugly(unsigned char FAR* out,
|
||||
unsigned dist,
|
||||
unsigned len,
|
||||
unsigned char FAR* limit) {
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
/* Speed is the same as using chunkcopy_safe
|
||||
w/ GCC on ARM (tested gcc 6.3 and 7.5) and avoids
|
||||
undefined behavior.
|
||||
*/
|
||||
return chunkcopy_core_safe(out, out - dist, len, limit);
|
||||
#elif defined(__clang__) && !defined(__aarch64__)
|
||||
/* Seems to perform better on 32bit (i.e. Android). */
|
||||
return chunkcopy_core_safe(out, out - dist, len, limit);
|
||||
#else
|
||||
/* Seems to perform better on 64-bit. */
|
||||
return chunkcopy_lapped_safe(out, dist, len, limit);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* The chunk-copy code above deals with writing the decoded DEFLATE data to
|
||||
* the output with SIMD methods to increase decode speed. Reading the input
|
||||
* to the DEFLATE decoder with a wide, SIMD method can also increase decode
|
||||
* speed. This option is supported on little endian machines, and reads the
|
||||
* input data in 64-bit (8 byte) chunks.
|
||||
*/
|
||||
|
||||
#ifdef INFLATE_CHUNK_READ_64LE
|
||||
/*
|
||||
* Buffer the input in a uint64_t (8 bytes) in the wide input reading case.
|
||||
*/
|
||||
typedef uint64_t inflate_holder_t;
|
||||
|
||||
/*
|
||||
* Ask the compiler to perform a wide, unaligned load of a uint64_t using a
|
||||
* machine instruction appropriate for the uint64_t type.
|
||||
*/
|
||||
static inline inflate_holder_t read64le(const unsigned char FAR *in) {
|
||||
inflate_holder_t input;
|
||||
Z_BUILTIN_MEMCPY(&input, in, sizeof(input));
|
||||
return input;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Otherwise, buffer the input bits using zlib's default input buffer type.
|
||||
*/
|
||||
typedef unsigned long inflate_holder_t;
|
||||
|
||||
#endif /* INFLATE_CHUNK_READ_64LE */
|
||||
|
||||
#undef Z_STATIC_ASSERT
|
||||
#undef Z_RESTRICT
|
||||
#undef Z_BUILTIN_MEMCPY
|
||||
|
||||
#endif /* CHUNKCOPY_H */
|
||||
21
deps/zlib/compress.c
vendored
21
deps/zlib/compress.c
vendored
@ -19,8 +19,13 @@
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong sourceLen, int level) {
|
||||
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
int level;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
const uInt max = (uInt)-1;
|
||||
@ -60,8 +65,12 @@ int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong sourceLen) {
|
||||
int ZEXPORT compress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
@ -69,7 +78,9 @@ int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
If the default memLevel or windowBits for deflateInit() is changed, then
|
||||
this function needs to be updated.
|
||||
*/
|
||||
uLong ZEXPORT compressBound(uLong sourceLen) {
|
||||
uLong ZEXPORT compressBound (sourceLen)
|
||||
uLong sourceLen;
|
||||
{
|
||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||
(sourceLen >> 25) + 13;
|
||||
}
|
||||
|
||||
1411
deps/zlib/crc32.c
vendored
1411
deps/zlib/crc32.c
vendored
File diff suppressed because it is too large
Load Diff
9877
deps/zlib/crc32.h
vendored
9877
deps/zlib/crc32.h
vendored
File diff suppressed because it is too large
Load Diff
244
deps/zlib/crc32_simd.c
vendored
244
deps/zlib/crc32_simd.c
vendored
@ -1,244 +0,0 @@
|
||||
/* crc32_simd.c
|
||||
*
|
||||
* Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the Chromium source repository LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "crc32_simd.h"
|
||||
|
||||
#if defined(CRC32_SIMD_SSE42_PCLMUL)
|
||||
|
||||
/*
|
||||
* crc32_sse42_simd_(): compute the crc32 of the buffer, where the buffer
|
||||
* length must be at least 64, and a multiple of 16. Based on:
|
||||
*
|
||||
* "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction"
|
||||
* V. Gopal, E. Ozturk, et al., 2009, http://intel.ly/2ySEwL0
|
||||
*/
|
||||
|
||||
#include <emmintrin.h>
|
||||
#include <smmintrin.h>
|
||||
#include <wmmintrin.h>
|
||||
|
||||
uint32_t ZLIB_INTERNAL crc32_sse42_simd_( /* SSE4.2+PCLMUL */
|
||||
const unsigned char *buf,
|
||||
z_size_t len,
|
||||
uint32_t crc)
|
||||
{
|
||||
/*
|
||||
* Definitions of the bit-reflected domain constants k1,k2,k3, etc and
|
||||
* the CRC32+Barrett polynomials given at the end of the paper.
|
||||
*/
|
||||
static const uint64_t zalign(16) k1k2[] = { 0x0154442bd4, 0x01c6e41596 };
|
||||
static const uint64_t zalign(16) k3k4[] = { 0x01751997d0, 0x00ccaa009e };
|
||||
static const uint64_t zalign(16) k5k0[] = { 0x0163cd6124, 0x0000000000 };
|
||||
static const uint64_t zalign(16) poly[] = { 0x01db710641, 0x01f7011641 };
|
||||
|
||||
__m128i x0, x1, x2, x3, x4, x5, x6, x7, x8, y5, y6, y7, y8;
|
||||
|
||||
/*
|
||||
* There's at least one block of 64.
|
||||
*/
|
||||
x1 = _mm_loadu_si128((__m128i *)(buf + 0x00));
|
||||
x2 = _mm_loadu_si128((__m128i *)(buf + 0x10));
|
||||
x3 = _mm_loadu_si128((__m128i *)(buf + 0x20));
|
||||
x4 = _mm_loadu_si128((__m128i *)(buf + 0x30));
|
||||
|
||||
x1 = _mm_xor_si128(x1, _mm_cvtsi32_si128(crc));
|
||||
|
||||
x0 = _mm_load_si128((__m128i *)k1k2);
|
||||
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
|
||||
/*
|
||||
* Parallel fold blocks of 64, if any.
|
||||
*/
|
||||
while (len >= 64)
|
||||
{
|
||||
x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
|
||||
x6 = _mm_clmulepi64_si128(x2, x0, 0x00);
|
||||
x7 = _mm_clmulepi64_si128(x3, x0, 0x00);
|
||||
x8 = _mm_clmulepi64_si128(x4, x0, 0x00);
|
||||
|
||||
x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
|
||||
x2 = _mm_clmulepi64_si128(x2, x0, 0x11);
|
||||
x3 = _mm_clmulepi64_si128(x3, x0, 0x11);
|
||||
x4 = _mm_clmulepi64_si128(x4, x0, 0x11);
|
||||
|
||||
y5 = _mm_loadu_si128((__m128i *)(buf + 0x00));
|
||||
y6 = _mm_loadu_si128((__m128i *)(buf + 0x10));
|
||||
y7 = _mm_loadu_si128((__m128i *)(buf + 0x20));
|
||||
y8 = _mm_loadu_si128((__m128i *)(buf + 0x30));
|
||||
|
||||
x1 = _mm_xor_si128(x1, x5);
|
||||
x2 = _mm_xor_si128(x2, x6);
|
||||
x3 = _mm_xor_si128(x3, x7);
|
||||
x4 = _mm_xor_si128(x4, x8);
|
||||
|
||||
x1 = _mm_xor_si128(x1, y5);
|
||||
x2 = _mm_xor_si128(x2, y6);
|
||||
x3 = _mm_xor_si128(x3, y7);
|
||||
x4 = _mm_xor_si128(x4, y8);
|
||||
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fold into 128-bits.
|
||||
*/
|
||||
x0 = _mm_load_si128((__m128i *)k3k4);
|
||||
|
||||
x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
|
||||
x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
x1 = _mm_xor_si128(x1, x5);
|
||||
|
||||
x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
|
||||
x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
|
||||
x1 = _mm_xor_si128(x1, x3);
|
||||
x1 = _mm_xor_si128(x1, x5);
|
||||
|
||||
x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
|
||||
x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
|
||||
x1 = _mm_xor_si128(x1, x4);
|
||||
x1 = _mm_xor_si128(x1, x5);
|
||||
|
||||
/*
|
||||
* Single fold blocks of 16, if any.
|
||||
*/
|
||||
while (len >= 16)
|
||||
{
|
||||
x2 = _mm_loadu_si128((__m128i *)buf);
|
||||
|
||||
x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
|
||||
x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
x1 = _mm_xor_si128(x1, x5);
|
||||
|
||||
buf += 16;
|
||||
len -= 16;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fold 128-bits to 64-bits.
|
||||
*/
|
||||
x2 = _mm_clmulepi64_si128(x1, x0, 0x10);
|
||||
x3 = _mm_setr_epi32(~0, 0, ~0, 0);
|
||||
x1 = _mm_srli_si128(x1, 8);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
|
||||
x0 = _mm_loadl_epi64((__m128i*)k5k0);
|
||||
|
||||
x2 = _mm_srli_si128(x1, 4);
|
||||
x1 = _mm_and_si128(x1, x3);
|
||||
x1 = _mm_clmulepi64_si128(x1, x0, 0x00);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
|
||||
/*
|
||||
* Barret reduce to 32-bits.
|
||||
*/
|
||||
x0 = _mm_load_si128((__m128i*)poly);
|
||||
|
||||
x2 = _mm_and_si128(x1, x3);
|
||||
x2 = _mm_clmulepi64_si128(x2, x0, 0x10);
|
||||
x2 = _mm_and_si128(x2, x3);
|
||||
x2 = _mm_clmulepi64_si128(x2, x0, 0x00);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
|
||||
/*
|
||||
* Return the crc32.
|
||||
*/
|
||||
return _mm_extract_epi32(x1, 1);
|
||||
}
|
||||
|
||||
#elif defined(CRC32_ARMV8_CRC32)
|
||||
|
||||
/* CRC32 checksums using ARMv8-a crypto instructions.
|
||||
*
|
||||
* TODO: implement a version using the PMULL instruction.
|
||||
*/
|
||||
|
||||
#if defined(__clang__)
|
||||
/* CRC32 intrinsics are #ifdef'ed out of arm_acle.h unless we build with an
|
||||
* armv8 target, which is incompatible with ThinLTO optimizations on Android.
|
||||
* (Namely, mixing and matching different module-level targets makes ThinLTO
|
||||
* warn, and Android defaults to armv7-a. This restriction does not apply to
|
||||
* function-level `target`s, however.)
|
||||
*
|
||||
* Since we only need four crc intrinsics, and since clang's implementation of
|
||||
* those are just wrappers around compiler builtins, it's simplest to #define
|
||||
* those builtins directly. If this #define list grows too much (or we depend on
|
||||
* an intrinsic that isn't a trivial wrapper), we may have to find a better way
|
||||
* to go about this.
|
||||
*
|
||||
* NOTE: clang currently complains that "'+soft-float-abi' is not a recognized
|
||||
* feature for this target (ignoring feature)." This appears to be a harmless
|
||||
* bug in clang.
|
||||
*/
|
||||
#define __crc32b __builtin_arm_crc32b
|
||||
#define __crc32d __builtin_arm_crc32d
|
||||
#define __crc32w __builtin_arm_crc32w
|
||||
#define __crc32cw __builtin_arm_crc32cw
|
||||
|
||||
#if defined(__aarch64__)
|
||||
#define TARGET_ARMV8_WITH_CRC __attribute__((target("crc")))
|
||||
#else // !defined(__aarch64__)
|
||||
#define TARGET_ARMV8_WITH_CRC __attribute__((target("armv8-a,crc")))
|
||||
#endif // defined(__aarch64__)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
/* For GCC, we are setting CRC extensions at module level, so ThinLTO is not
|
||||
* allowed. We can just include arm_acle.h.
|
||||
*/
|
||||
#include <arm_acle.h>
|
||||
#define TARGET_ARMV8_WITH_CRC
|
||||
#else // !defined(__GNUC__) && !defined(_aarch64__)
|
||||
#error ARM CRC32 SIMD extensions only supported for Clang and GCC
|
||||
#endif
|
||||
|
||||
TARGET_ARMV8_WITH_CRC
|
||||
uint32_t ZLIB_INTERNAL armv8_crc32_little(unsigned long crc,
|
||||
const unsigned char *buf,
|
||||
z_size_t len)
|
||||
{
|
||||
uint32_t c = (uint32_t) ~crc;
|
||||
|
||||
while (len && ((uintptr_t)buf & 7)) {
|
||||
c = __crc32b(c, *buf++);
|
||||
--len;
|
||||
}
|
||||
|
||||
const uint64_t *buf8 = (const uint64_t *)buf;
|
||||
|
||||
while (len >= 64) {
|
||||
c = __crc32d(c, *buf8++);
|
||||
c = __crc32d(c, *buf8++);
|
||||
c = __crc32d(c, *buf8++);
|
||||
c = __crc32d(c, *buf8++);
|
||||
|
||||
c = __crc32d(c, *buf8++);
|
||||
c = __crc32d(c, *buf8++);
|
||||
c = __crc32d(c, *buf8++);
|
||||
c = __crc32d(c, *buf8++);
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
while (len >= 8) {
|
||||
c = __crc32d(c, *buf8++);
|
||||
len -= 8;
|
||||
}
|
||||
|
||||
buf = (const unsigned char *)buf8;
|
||||
|
||||
while (len--) {
|
||||
c = __crc32b(c, *buf++);
|
||||
}
|
||||
|
||||
return ~c;
|
||||
}
|
||||
|
||||
#endif
|
||||
69
deps/zlib/crc32_simd.h
vendored
69
deps/zlib/crc32_simd.h
vendored
@ -1,69 +0,0 @@
|
||||
//https://cs.chromium.org/chromium/src/third_party/zlib/crc32_simd.c
|
||||
/* crc32_simd.h
|
||||
*
|
||||
* Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the Chromium source repository LICENSE file.
|
||||
*/
|
||||
#ifndef CRC32_SIMD_H
|
||||
#define CRC32_SIMD_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//#include "zconf.h"
|
||||
//#include "zutil.h"
|
||||
#include "deflate.h"
|
||||
|
||||
//#ifndef local
|
||||
// #define local static
|
||||
//#endif
|
||||
|
||||
//#ifndef z_crc_t
|
||||
// #ifdef Z_U4
|
||||
// typedef Z_U4 z_crc_t;
|
||||
// #else
|
||||
// typedef unsigned long z_crc_t;
|
||||
// #endif
|
||||
//#endif
|
||||
#ifdef HAS_PCLMUL
|
||||
#define CRC32_SIMD_SSE42_PCLMUL
|
||||
#endif
|
||||
|
||||
#ifndef z_size_t
|
||||
#define z_size_t size_t
|
||||
#endif
|
||||
#ifndef zalign
|
||||
#ifdef _MSC_VER
|
||||
#define zalign(x) __declspec(align(x))
|
||||
#else
|
||||
#define zalign(x) __attribute__((aligned((x))))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* crc32_sse42_simd_(): compute the crc32 of the buffer, where the buffer
|
||||
* length must be at least 64, and a multiple of 16.
|
||||
*/
|
||||
uint32_t ZLIB_INTERNAL crc32_sse42_simd_(
|
||||
const unsigned char *buf,
|
||||
z_size_t len,
|
||||
uint32_t crc);
|
||||
|
||||
/*
|
||||
* crc32_sse42_simd_ buffer size constraints: see the use in zlib/crc32.c
|
||||
* for computing the crc32 of an arbitrary length buffer.
|
||||
*/
|
||||
#define Z_CRC32_SSE42_MINIMUM_LENGTH 64
|
||||
#define Z_CRC32_SSE42_CHUNKSIZE_MASK 15
|
||||
|
||||
/*
|
||||
* CRC32 checksums using ARMv8-a crypto instructions.
|
||||
*/
|
||||
uint32_t ZLIB_INTERNAL armv8_crc32_little(unsigned long crc,
|
||||
const unsigned char* buf,
|
||||
z_size_t len);
|
||||
|
||||
#endif /* CRC32_SIMD_H */
|
||||
1612
deps/zlib/deflate.c
vendored
1612
deps/zlib/deflate.c
vendored
File diff suppressed because it is too large
Load Diff
202
deps/zlib/deflate.h
vendored
202
deps/zlib/deflate.h
vendored
@ -15,6 +15,14 @@
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip encoding
|
||||
should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GZIP
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Internal compression state.
|
||||
*/
|
||||
@ -40,30 +48,33 @@
|
||||
#define MAX_BITS 15
|
||||
/* All codes must not exceed MAX_BITS bits */
|
||||
|
||||
#define Buf_size 64
|
||||
#define Buf_size 16
|
||||
/* size of bit buffer in bi_buf */
|
||||
|
||||
#define INIT_STATE 42
|
||||
#define EXTRA_STATE 69
|
||||
#define NAME_STATE 73
|
||||
#define COMMENT_STATE 91
|
||||
#define HCRC_STATE 103
|
||||
#define BUSY_STATE 113
|
||||
#define FINISH_STATE 666
|
||||
#define INIT_STATE 42 /* zlib header -> BUSY_STATE */
|
||||
#ifdef GZIP
|
||||
# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
|
||||
#endif
|
||||
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
|
||||
#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
|
||||
#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
|
||||
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
|
||||
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
|
||||
#define FINISH_STATE 666 /* stream complete */
|
||||
/* Stream status */
|
||||
|
||||
|
||||
/* Data structure describing a single value and its code string. */
|
||||
typedef struct ct_data_s {
|
||||
union {
|
||||
uint16_t freq; /* frequency count */
|
||||
uint16_t code; /* bit string */
|
||||
ush freq; /* frequency count */
|
||||
ush code; /* bit string */
|
||||
} fc;
|
||||
union {
|
||||
uint16_t dad; /* father node in Huffman tree */
|
||||
uint16_t len; /* length of bit string */
|
||||
ush dad; /* father node in Huffman tree */
|
||||
ush len; /* length of bit string */
|
||||
} dl;
|
||||
} ct_data;
|
||||
} FAR ct_data;
|
||||
|
||||
#define Freq fc.freq
|
||||
#define Code fc.code
|
||||
@ -75,35 +86,37 @@ typedef struct static_tree_desc_s static_tree_desc;
|
||||
typedef struct tree_desc_s {
|
||||
ct_data *dyn_tree; /* the dynamic tree */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} tree_desc;
|
||||
const static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} FAR tree_desc;
|
||||
|
||||
typedef uint16_t Pos;
|
||||
typedef uint32_t IPos;
|
||||
typedef ush Pos;
|
||||
typedef Pos FAR Posf;
|
||||
typedef unsigned IPos;
|
||||
|
||||
/* A Pos is an index in the character window. We use short instead of int to
|
||||
* save space in the various tables. IPos is used only for parameter passing.
|
||||
*/
|
||||
|
||||
typedef struct internal_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
int status; /* as the name implies */
|
||||
uint8_t *pending_buf; /* output still pending */
|
||||
uint64_t pending_buf_size; /* size of pending_buf */
|
||||
uint8_t *pending_out; /* next pending byte to output to the stream */
|
||||
uint32_t pending; /* nb of bytes in the pending buffer */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
gz_headerp gzhead; /* gzip header information to write */
|
||||
uint32_t gzindex; /* where in extra, name, or comment */
|
||||
uint8_t method; /* can only be DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
int status; /* as the name implies */
|
||||
Bytef *pending_buf; /* output still pending */
|
||||
ulg pending_buf_size; /* size of pending_buf */
|
||||
Bytef *pending_out; /* next pending byte to output to the stream */
|
||||
ulg pending; /* nb of bytes in the pending buffer */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
gz_headerp gzhead; /* gzip header information to write */
|
||||
ulg gzindex; /* where in extra, name, or comment */
|
||||
Byte method; /* can only be DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
|
||||
/* used by deflate.c: */
|
||||
uint32_t w_size; /* LZ77 window size (32K by default) */
|
||||
uint32_t w_bits; /* log2(w_size) (8..16) */
|
||||
uint32_t w_mask; /* w_size - 1 */
|
||||
/* used by deflate.c: */
|
||||
|
||||
uint8_t *window;
|
||||
uInt w_size; /* LZ77 window size (32K by default) */
|
||||
uInt w_bits; /* log2(w_size) (8..16) */
|
||||
uInt w_mask; /* w_size - 1 */
|
||||
|
||||
Bytef *window;
|
||||
/* Sliding window. Input bytes are read into the second half of the window,
|
||||
* and move to the first half later to keep a dictionary of at least wSize
|
||||
* bytes. With this organization, matches are limited to a distance of
|
||||
@ -113,25 +126,25 @@ typedef struct internal_state {
|
||||
* To do: use the user input buffer as sliding window.
|
||||
*/
|
||||
|
||||
uint32_t window_size;
|
||||
ulg window_size;
|
||||
/* Actual size of window: 2*wSize, except when the user input buffer
|
||||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
Pos *prev;
|
||||
Posf *prev;
|
||||
/* Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
Pos *head; /* Heads of the hash chains or NIL. */
|
||||
Posf *head; /* Heads of the hash chains or NIL. */
|
||||
|
||||
uint32_t ins_h; /* hash index of string to be inserted */
|
||||
uint32_t hash_size; /* number of elements in hash table */
|
||||
uint32_t hash_bits; /* log2(hash_size) */
|
||||
uint32_t hash_mask; /* hash_size-1 */
|
||||
uInt ins_h; /* hash index of string to be inserted */
|
||||
uInt hash_size; /* number of elements in hash table */
|
||||
uInt hash_bits; /* log2(hash_size) */
|
||||
uInt hash_mask; /* hash_size-1 */
|
||||
|
||||
uint32_t hash_shift;
|
||||
uInt hash_shift;
|
||||
/* Number of bits by which ins_h must be shifted at each input
|
||||
* step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
@ -143,25 +156,25 @@ typedef struct internal_state {
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
|
||||
uint32_t match_length; /* length of best match */
|
||||
IPos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
uint32_t strstart; /* start of string to insert */
|
||||
uint32_t match_start; /* start of matching string */
|
||||
uint32_t lookahead; /* number of valid bytes ahead in window */
|
||||
uInt match_length; /* length of best match */
|
||||
IPos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
uInt strstart; /* start of string to insert */
|
||||
uInt match_start; /* start of matching string */
|
||||
uInt lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
uint32_t prev_length;
|
||||
uInt prev_length;
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
uint32_t max_chain_length;
|
||||
uInt max_chain_length;
|
||||
/* To speed up deflation, hash chains are never searched beyond this
|
||||
* length. A higher limit improves compression ratio but degrades the
|
||||
* speed.
|
||||
*/
|
||||
|
||||
uint32_t max_lazy_match;
|
||||
uInt max_lazy_match;
|
||||
/* Attempt to find a better match only when the current match is strictly
|
||||
* smaller than this value. This mechanism is used only for compression
|
||||
* levels >= 4.
|
||||
@ -175,12 +188,12 @@ typedef struct internal_state {
|
||||
int level; /* compression level (1..9) */
|
||||
int strategy; /* favor or force Huffman coding*/
|
||||
|
||||
uint32_t good_match;
|
||||
uInt good_match;
|
||||
/* Use a faster search when the previous match is longer than this */
|
||||
|
||||
int nice_match; /* Stop searching when current match exceeds this */
|
||||
|
||||
/* used by trees.c: */
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to suppress compiler warning */
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
||||
@ -190,7 +203,7 @@ typedef struct internal_state {
|
||||
struct tree_desc_s d_desc; /* desc. for distance tree */
|
||||
struct tree_desc_s bl_desc; /* desc. for bit length tree */
|
||||
|
||||
uint16_t bl_count[MAX_BITS+1];
|
||||
ush bl_count[MAX_BITS+1];
|
||||
/* number of codes at each bit length for an optimal tree */
|
||||
|
||||
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
||||
@ -200,13 +213,13 @@ typedef struct internal_state {
|
||||
* The same heap array is used to build all trees.
|
||||
*/
|
||||
|
||||
uint8_t depth[2*L_CODES+1];
|
||||
uch depth[2*L_CODES+1];
|
||||
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
||||
*/
|
||||
|
||||
uint8_t *sym_buf; /* buffer for distances and literals/lengths */
|
||||
uchf *sym_buf; /* buffer for distances and literals/lengths */
|
||||
|
||||
uint32_t lit_bufsize;
|
||||
uInt lit_bufsize;
|
||||
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
||||
* limiting lit_bufsize to 64K:
|
||||
* - frequencies can be kept in 16 bit counters
|
||||
@ -229,17 +242,17 @@ typedef struct internal_state {
|
||||
uInt sym_next; /* running index in sym_buf */
|
||||
uInt sym_end; /* symbol table full when sym_next reaches this */
|
||||
|
||||
uint64_t opt_len; /* bit length of current block with optimal trees */
|
||||
uint64_t static_len; /* bit length of current block with static trees */
|
||||
uint32_t matches; /* number of string matches in current block */
|
||||
uint32_t insert; /* bytes at end of window left to insert */
|
||||
ulg opt_len; /* bit length of current block with optimal trees */
|
||||
ulg static_len; /* bit length of current block with static trees */
|
||||
uInt matches; /* number of string matches in current block */
|
||||
uInt insert; /* bytes at end of window left to insert */
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
uint64_t compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
uint64_t bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
#endif
|
||||
|
||||
uint64_t bi_buf;
|
||||
ush bi_buf;
|
||||
/* Output buffer. bits are inserted starting at the bottom (least
|
||||
* significant bits).
|
||||
*/
|
||||
@ -248,29 +261,20 @@ typedef struct internal_state {
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
uint64_t high_water;
|
||||
ulg high_water;
|
||||
/* High water mark offset in window for initialized bytes -- bytes above
|
||||
* this are set to zero in order to avoid memory check warnings when
|
||||
* longest match routines access bytes past the input. This is then
|
||||
* updated to the new high water mark.
|
||||
*/
|
||||
|
||||
} deflate_state;
|
||||
} FAR deflate_state;
|
||||
|
||||
/* Output a byte on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
|
||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
|
||||
|
||||
/* ===========================================================================
|
||||
* Output a short LSB first on the stream.
|
||||
* IN assertion: there is enough room in pendingBuf.
|
||||
*/
|
||||
|
||||
#define put_short(s, w) { \
|
||||
s->pending += 2; \
|
||||
*(ush*)(&s->pending_buf[s->pending - 2]) = (w) ; \
|
||||
}
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
@ -287,14 +291,14 @@ typedef struct internal_state {
|
||||
memory checker errors from longest match routines */
|
||||
|
||||
/* in trees.c */
|
||||
void ZLIB_INTERNAL _tr_init(deflate_state *s);
|
||||
int ZLIB_INTERNAL _tr_tally(deflate_state *s, uint32_t dist, unsigned lc);
|
||||
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf,
|
||||
uint64_t stored_len, int last);
|
||||
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
|
||||
void ZLIB_INTERNAL _tr_align(deflate_state *s);
|
||||
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, uint8_t *buf,
|
||||
uint64_t stored_len, int last);
|
||||
void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
|
||||
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last));
|
||||
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
|
||||
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
|
||||
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last));
|
||||
|
||||
#define d_code(dist) \
|
||||
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
||||
@ -303,8 +307,16 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, uint8_t *buf,
|
||||
* used.
|
||||
*/
|
||||
|
||||
extern const uint8_t ZLIB_INTERNAL _length_code[];
|
||||
extern const uint8_t ZLIB_INTERNAL _dist_code[];
|
||||
#ifndef ZLIB_DEBUG
|
||||
/* Inline versions of _tr_tally for speed: */
|
||||
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
extern uch ZLIB_INTERNAL _length_code[];
|
||||
extern uch ZLIB_INTERNAL _dist_code[];
|
||||
#else
|
||||
extern const uch ZLIB_INTERNAL _length_code[];
|
||||
extern const uch ZLIB_INTERNAL _dist_code[];
|
||||
#endif
|
||||
|
||||
# define _tr_tally_lit(s, c, flush) \
|
||||
{ uch cc = (c); \
|
||||
@ -325,24 +337,10 @@ extern const uint8_t ZLIB_INTERNAL _dist_code[];
|
||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||
flush = (s->sym_next == s->sym_end); \
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
/* MSC doesn't have __builtin_expect. Just ignore likely/unlikely and
|
||||
hope the compiler optimizes for the best.
|
||||
*/
|
||||
#define likely(x) (x)
|
||||
#define unlikely(x) (x)
|
||||
|
||||
int __inline __builtin_ctzl(unsigned long mask)
|
||||
{
|
||||
unsigned long index ;
|
||||
|
||||
return _BitScanForward(&index, mask) == 0 ? 32 : ((int)index) ;
|
||||
}
|
||||
#else
|
||||
#define likely(x) __builtin_expect((x),1)
|
||||
#define unlikely(x) __builtin_expect((x),0)
|
||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
flush = _tr_tally(s, distance, length)
|
||||
#endif
|
||||
|
||||
#endif /* DEFLATE_H */
|
||||
|
||||
4
deps/zlib/gzclose.c
vendored
4
deps/zlib/gzclose.c
vendored
@ -8,7 +8,9 @@
|
||||
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
||||
That way the other gzclose functions can be used instead to avoid linking in
|
||||
unneeded compression or decompression routines. */
|
||||
int ZEXPORT gzclose(gzFile file) {
|
||||
int ZEXPORT gzclose(file)
|
||||
gzFile file;
|
||||
{
|
||||
#ifndef NO_GZCOMPRESS
|
||||
gz_statep state;
|
||||
|
||||
|
||||
23
deps/zlib/gzguts.h
vendored
23
deps/zlib/gzguts.h
vendored
@ -7,8 +7,9 @@
|
||||
# ifndef _LARGEFILE_SOURCE
|
||||
# define _LARGEFILE_SOURCE 1
|
||||
# endif
|
||||
# undef _FILE_OFFSET_BITS
|
||||
# undef _TIME_BITS
|
||||
# ifdef _FILE_OFFSET_BITS
|
||||
# undef _FILE_OFFSET_BITS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HIDDEN
|
||||
@ -118,8 +119,8 @@
|
||||
|
||||
/* gz* functions always use library allocation functions */
|
||||
#ifndef STDC
|
||||
extern voidp malloc(uInt size);
|
||||
extern void free(voidpf ptr);
|
||||
extern voidp malloc OF((uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
/* get errno and strerror definition */
|
||||
@ -137,10 +138,10 @@
|
||||
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
||||
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
|
||||
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
|
||||
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
|
||||
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
||||
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
||||
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
|
||||
#endif
|
||||
|
||||
/* default memLevel */
|
||||
@ -202,9 +203,9 @@ typedef struct {
|
||||
typedef gz_state FAR *gz_statep;
|
||||
|
||||
/* shared functions */
|
||||
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
|
||||
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
|
||||
#if defined UNDER_CE
|
||||
char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
|
||||
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
|
||||
#endif
|
||||
|
||||
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
||||
@ -213,6 +214,6 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
|
||||
#ifdef INT_MAX
|
||||
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
||||
#else
|
||||
unsigned ZLIB_INTERNAL gz_intmax(void);
|
||||
unsigned ZLIB_INTERNAL gz_intmax OF((void));
|
||||
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
||||
#endif
|
||||
|
||||
108
deps/zlib/gzlib.c
vendored
108
deps/zlib/gzlib.c
vendored
@ -16,8 +16,8 @@
|
||||
#endif
|
||||
|
||||
/* Local functions */
|
||||
local void gz_reset(gz_statep);
|
||||
local gzFile gz_open(const void *, int, const char *);
|
||||
local void gz_reset OF((gz_statep));
|
||||
local gzFile gz_open OF((const void *, int, const char *));
|
||||
|
||||
#if defined UNDER_CE
|
||||
|
||||
@ -30,7 +30,9 @@ local gzFile gz_open(const void *, int, const char *);
|
||||
|
||||
The gz_strwinerror function does not change the current setting of
|
||||
GetLastError. */
|
||||
char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
|
||||
char ZLIB_INTERNAL *gz_strwinerror (error)
|
||||
DWORD error;
|
||||
{
|
||||
static char buf[1024];
|
||||
|
||||
wchar_t *msgbuf;
|
||||
@ -70,7 +72,9 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
|
||||
#endif /* UNDER_CE */
|
||||
|
||||
/* Reset gzip file state */
|
||||
static void gz_reset(gz_statep state) {
|
||||
local void gz_reset(state)
|
||||
gz_statep state;
|
||||
{
|
||||
state->x.have = 0; /* no output data available */
|
||||
if (state->mode == GZ_READ) { /* for reading ... */
|
||||
state->eof = 0; /* not at end of file */
|
||||
@ -86,7 +90,10 @@ static void gz_reset(gz_statep state) {
|
||||
}
|
||||
|
||||
/* Open a gzip file either by name or file descriptor. */
|
||||
static gzFile gz_open(const void *path, int fd, const char *mode)
|
||||
local gzFile gz_open(path, fd, mode)
|
||||
const void *path;
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
gz_statep state;
|
||||
z_size_t len;
|
||||
@ -183,7 +190,7 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
|
||||
}
|
||||
|
||||
/* save the path name for error messages */
|
||||
#ifdef _WIN32
|
||||
#ifdef WIDECHAR
|
||||
if (fd == -2) {
|
||||
len = wcstombs(NULL, path, 0);
|
||||
if (len == (z_size_t)-1)
|
||||
@ -197,7 +204,7 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
|
||||
free(state);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
#ifdef WIDECHAR
|
||||
if (fd == -2)
|
||||
if (len)
|
||||
wcstombs(state->path, path, len + 1);
|
||||
@ -234,7 +241,7 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
|
||||
|
||||
/* open the file with the appropriate flags (or just use fd) */
|
||||
state->fd = fd > -1 ? fd : (
|
||||
#ifdef _WIN32
|
||||
#ifdef WIDECHAR
|
||||
fd == -2 ? _wopen(path, oflag, 0666) :
|
||||
#endif
|
||||
open((const char *)path, oflag, 0666));
|
||||
@ -262,17 +269,26 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzopen(const char *path, const char *mode) {
|
||||
gzFile ZEXPORT gzopen(path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
|
||||
gzFile ZEXPORT gzopen64(path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzdopen(int fd, const char *mode) {
|
||||
gzFile ZEXPORT gzdopen(fd, mode)
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
char *path; /* identifier for error messages */
|
||||
gzFile gz;
|
||||
|
||||
@ -289,15 +305,20 @@ gzFile ZEXPORT gzdopen(int fd, const char *mode) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
#ifdef _WIN32
|
||||
gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode)
|
||||
#ifdef WIDECHAR
|
||||
gzFile ZEXPORT gzopen_w(path, mode)
|
||||
const wchar_t *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -2, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzbuffer(gzFile file, unsigned size) {
|
||||
int ZEXPORT gzbuffer(file, size)
|
||||
gzFile file;
|
||||
unsigned size;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
@ -314,14 +335,16 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size) {
|
||||
/* check and set requested size */
|
||||
if ((size << 1) < size)
|
||||
return -1; /* need to be able to double it */
|
||||
if (size < 8)
|
||||
size = 8; /* needed to behave well with flushing */
|
||||
if (size < 2)
|
||||
size = 2; /* need two bytes to check magic header */
|
||||
state->want = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzrewind(gzFile file) {
|
||||
int ZEXPORT gzrewind(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
@ -342,7 +365,11 @@ int ZEXPORT gzrewind(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||
z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
||||
gzFile file;
|
||||
z_off64_t offset;
|
||||
int whence;
|
||||
{
|
||||
unsigned n;
|
||||
z_off64_t ret;
|
||||
gz_statep state;
|
||||
@ -415,7 +442,11 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
|
||||
z_off_t ZEXPORT gzseek(file, offset, whence)
|
||||
gzFile file;
|
||||
z_off_t offset;
|
||||
int whence;
|
||||
{
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gzseek64(file, (z_off64_t)offset, whence);
|
||||
@ -423,7 +454,9 @@ z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gztell64(gzFile file) {
|
||||
z_off64_t ZEXPORT gztell64(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
@ -438,7 +471,9 @@ z_off64_t ZEXPORT gztell64(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gztell(gzFile file) {
|
||||
z_off_t ZEXPORT gztell(file)
|
||||
gzFile file;
|
||||
{
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gztell64(file);
|
||||
@ -446,7 +481,9 @@ z_off_t ZEXPORT gztell(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gzoffset64(gzFile file) {
|
||||
z_off64_t ZEXPORT gzoffset64(file)
|
||||
gzFile file;
|
||||
{
|
||||
z_off64_t offset;
|
||||
gz_statep state;
|
||||
|
||||
@ -467,7 +504,9 @@ z_off64_t ZEXPORT gzoffset64(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gzoffset(gzFile file) {
|
||||
z_off_t ZEXPORT gzoffset(file)
|
||||
gzFile file;
|
||||
{
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gzoffset64(file);
|
||||
@ -475,7 +514,9 @@ z_off_t ZEXPORT gzoffset(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzeof(gzFile file) {
|
||||
int ZEXPORT gzeof(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
@ -490,7 +531,10 @@ int ZEXPORT gzeof(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
const char * ZEXPORT gzerror(gzFile file, int *errnum) {
|
||||
const char * ZEXPORT gzerror(file, errnum)
|
||||
gzFile file;
|
||||
int *errnum;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
@ -508,7 +552,9 @@ const char * ZEXPORT gzerror(gzFile file, int *errnum) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
void ZEXPORT gzclearerr(gzFile file) {
|
||||
void ZEXPORT gzclearerr(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
@ -532,7 +578,11 @@ void ZEXPORT gzclearerr(gzFile file) {
|
||||
memory). Simply save the error message as a static string. If there is an
|
||||
allocation failure constructing the error message, then convert the error to
|
||||
out of memory. */
|
||||
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
|
||||
void ZLIB_INTERNAL gz_error(state, err, msg)
|
||||
gz_statep state;
|
||||
int err;
|
||||
const char *msg;
|
||||
{
|
||||
/* free previously allocated message and clear */
|
||||
if (state->msg != NULL) {
|
||||
if (state->err != Z_MEM_ERROR)
|
||||
@ -567,7 +617,6 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
|
||||
strcat(state->msg, ": ");
|
||||
strcat(state->msg, msg);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef INT_MAX
|
||||
@ -575,7 +624,8 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
|
||||
available) -- we need to do this to cover cases where 2's complement not
|
||||
used, since C standard permits 1's complement and sign-bit representations,
|
||||
otherwise we could just use ((unsigned)-1) >> 1 */
|
||||
unsigned ZLIB_INTERNAL gz_intmax(void) {
|
||||
unsigned ZLIB_INTERNAL gz_intmax()
|
||||
{
|
||||
unsigned p, q;
|
||||
|
||||
p = 1;
|
||||
|
||||
231
deps/zlib/gzread.c
vendored
231
deps/zlib/gzread.c
vendored
@ -6,27 +6,36 @@
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
local int gz_load(gz_statep, unsigned char *, unsigned, unsigned *);
|
||||
local int gz_avail(gz_statep);
|
||||
local int gz_look(gz_statep);
|
||||
local int gz_decomp(gz_statep);
|
||||
local int gz_fetch(gz_statep);
|
||||
local int gz_skip(gz_statep, z_off64_t);
|
||||
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
|
||||
local int gz_avail OF((gz_statep));
|
||||
local int gz_look OF((gz_statep));
|
||||
local int gz_decomp OF((gz_statep));
|
||||
local int gz_fetch OF((gz_statep));
|
||||
local int gz_skip OF((gz_statep, z_off64_t));
|
||||
local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
|
||||
|
||||
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
||||
state->fd, and update state->eof, state->err, and state->msg as appropriate.
|
||||
This function needs to loop on read(), since read() is not guaranteed to
|
||||
read the number of bytes requested, depending on the type of descriptor. */
|
||||
static int gz_load(gz_statep state, unsigned char *buf, unsigned len,
|
||||
unsigned *have) {
|
||||
z_ssize_t ret;
|
||||
local int gz_load(state, buf, len, have)
|
||||
gz_statep state;
|
||||
unsigned char *buf;
|
||||
unsigned len;
|
||||
unsigned *have;
|
||||
{
|
||||
int ret;
|
||||
unsigned get, max = ((unsigned)-1 >> 2) + 1;
|
||||
|
||||
*have = 0;
|
||||
do {
|
||||
ret = read(state->fd, buf + *have, len - *have);
|
||||
get = len - *have;
|
||||
if (get > max)
|
||||
get = max;
|
||||
ret = read(state->fd, buf + *have, get);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
*have += ret;
|
||||
*have += (unsigned)ret;
|
||||
} while (*have < len);
|
||||
if (ret < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
@ -44,7 +53,9 @@ static int gz_load(gz_statep state, unsigned char *buf, unsigned len,
|
||||
If strm->avail_in != 0, then the current data is moved to the beginning of
|
||||
the input buffer, and then the remainder of the buffer is loaded with the
|
||||
available data from the input file. */
|
||||
static int gz_avail(gz_statep state) {
|
||||
local int gz_avail(state)
|
||||
gz_statep state;
|
||||
{
|
||||
unsigned got;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
@ -77,7 +88,9 @@ static int gz_avail(gz_statep state) {
|
||||
case, all further file reads will be directly to either the output buffer or
|
||||
a user buffer. If decompressing, the inflate state will be initialized.
|
||||
gz_look() will return 0 on success or -1 on failure. */
|
||||
static int gz_look(gz_statep state) {
|
||||
local int gz_look(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* allocate read buffers and inflate memory */
|
||||
@ -144,9 +157,11 @@ static int gz_look(gz_statep state) {
|
||||
the output buffer is larger than the input buffer, which also assures
|
||||
space for gzungetc() */
|
||||
state->x.next = state->out;
|
||||
memcpy(state->x.next, strm->next_in, strm->avail_in);
|
||||
state->x.have = strm->avail_in;
|
||||
strm->avail_in = 0;
|
||||
if (strm->avail_in) {
|
||||
memcpy(state->x.next, strm->next_in, strm->avail_in);
|
||||
state->x.have = strm->avail_in;
|
||||
strm->avail_in = 0;
|
||||
}
|
||||
state->how = COPY;
|
||||
state->direct = 1;
|
||||
return 0;
|
||||
@ -157,7 +172,9 @@ static int gz_look(gz_statep state) {
|
||||
data. If the gzip stream completes, state->how is reset to LOOK to look for
|
||||
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
|
||||
on success, -1 on failure. */
|
||||
static int gz_decomp(gz_statep state) {
|
||||
local int gz_decomp(state)
|
||||
gz_statep state;
|
||||
{
|
||||
int ret = Z_OK;
|
||||
unsigned had;
|
||||
z_streamp strm = &(state->strm);
|
||||
@ -209,7 +226,9 @@ static int gz_decomp(gz_statep state) {
|
||||
looked for to determine whether to copy or decompress. Returns -1 on error,
|
||||
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
|
||||
end of the input file has been reached and all data has been processed. */
|
||||
static int gz_fetch(gz_statep state) {
|
||||
local int gz_fetch(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
do {
|
||||
@ -237,7 +256,10 @@ static int gz_fetch(gz_statep state) {
|
||||
}
|
||||
|
||||
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
|
||||
static int gz_skip(gz_statep state, z_off64_t len) {
|
||||
local int gz_skip(state, len)
|
||||
gz_statep state;
|
||||
z_off64_t len;
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
/* skip over len bytes or reach end-of-file, whichever comes first */
|
||||
@ -265,30 +287,17 @@ static int gz_skip(gz_statep state, z_off64_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
|
||||
{
|
||||
unsigned got, n;
|
||||
/* Read len bytes into buf from file, or less than len up to the end of the
|
||||
input. Return the number of bytes read. If zero is returned, either the
|
||||
end of file was reached, or there was an error. state->err must be
|
||||
consulted in that case to determine which. */
|
||||
local z_size_t gz_read(state, buf, len)
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids the flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
||||
return -1;
|
||||
}
|
||||
voidp buf;
|
||||
z_size_t len;
|
||||
{
|
||||
z_size_t got;
|
||||
unsigned n;
|
||||
|
||||
/* if len is zero, avoid unnecessary operations */
|
||||
if (len == 0)
|
||||
@ -298,32 +307,38 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get len bytes to buf, or less than len if at the end */
|
||||
got = 0;
|
||||
do {
|
||||
/* set n to the maximum amount of len that fits in an unsigned int */
|
||||
n = (unsigned)-1;
|
||||
if (n > len)
|
||||
n = (unsigned)len;
|
||||
|
||||
/* first just try copying data from the output buffer */
|
||||
if (state->x.have) {
|
||||
n = state->x.have > len ? len : state->x.have;
|
||||
if (state->x.have < n)
|
||||
n = state->x.have;
|
||||
memcpy(buf, state->x.next, n);
|
||||
state->x.next += n;
|
||||
state->x.have -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && strm->avail_in == 0) {
|
||||
else if (state->eof && state->strm.avail_in == 0) {
|
||||
state->past = 1; /* tried to read past end */
|
||||
break;
|
||||
}
|
||||
|
||||
/* need output data -- for small len or new stream load up our output
|
||||
buffer */
|
||||
else if (state->how == LOOK || len < (state->size << 1)) {
|
||||
else if (state->how == LOOK || n < (state->size << 1)) {
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_fetch(state) == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
continue; /* no progress yet -- go back to copy above */
|
||||
/* the copy above assures that we will leave with space in the
|
||||
output buffer, allowing at least one gzungetc() to succeed */
|
||||
@ -331,16 +346,16 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
|
||||
|
||||
/* large len -- read directly into user buffer */
|
||||
else if (state->how == COPY) { /* read directly */
|
||||
if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
|
||||
return -1;
|
||||
if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* large len -- decompress directly into user buffer */
|
||||
else { /* state->how == GZIP */
|
||||
strm->avail_out = len;
|
||||
strm->next_out = (unsigned char *)buf;
|
||||
state->strm.avail_out = n;
|
||||
state->strm.next_out = (unsigned char *)buf;
|
||||
if (gz_decomp(state) == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
n = state->x.have;
|
||||
state->x.have = 0;
|
||||
}
|
||||
@ -352,8 +367,75 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
|
||||
state->x.pos += n;
|
||||
} while (len);
|
||||
|
||||
/* return number of bytes read into user buffer (will fit in int) */
|
||||
return (int)got;
|
||||
/* return number of bytes read into user buffer */
|
||||
return got;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzread(file, buf, len)
|
||||
gzFile file;
|
||||
voidp buf;
|
||||
unsigned len;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids a flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* read len or fewer bytes to buf */
|
||||
len = (unsigned)gz_read(state, buf, len);
|
||||
|
||||
/* check for an error */
|
||||
if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
|
||||
return -1;
|
||||
|
||||
/* return the number of bytes read (this is assured to fit in an int) */
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_size_t ZEXPORT gzfread(buf, size, nitems, file)
|
||||
voidp buf;
|
||||
z_size_t size;
|
||||
z_size_t nitems;
|
||||
gzFile file;
|
||||
{
|
||||
z_size_t len;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return 0;
|
||||
|
||||
/* compute bytes to read -- error on overflow */
|
||||
len = nitems * size;
|
||||
if (size && len / size != nitems) {
|
||||
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read len or fewer bytes to buf, return the number of full items read */
|
||||
return len ? gz_read(state, buf, len) / size : 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
@ -362,8 +444,9 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
|
||||
#else
|
||||
# undef gzgetc
|
||||
#endif
|
||||
int ZEXPORT gzgetc(gzFile file) {
|
||||
int ret;
|
||||
int ZEXPORT gzgetc(file)
|
||||
gzFile file;
|
||||
{
|
||||
unsigned char buf[1];
|
||||
gz_statep state;
|
||||
|
||||
@ -384,17 +467,21 @@ int ZEXPORT gzgetc(gzFile file) {
|
||||
return *(state->x.next)++;
|
||||
}
|
||||
|
||||
/* nothing there -- try gzread() */
|
||||
ret = gzread(file, buf, 1);
|
||||
return ret < 1 ? -1 : buf[0];
|
||||
/* nothing there -- try gz_read() */
|
||||
return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
|
||||
}
|
||||
|
||||
int ZEXPORT gzgetc_(gzFile file) {
|
||||
int ZEXPORT gzgetc_(file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzgetc(file);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzungetc(int c, gzFile file) {
|
||||
int ZEXPORT gzungetc(c, file)
|
||||
int c;
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
@ -402,10 +489,6 @@ int ZEXPORT gzungetc(int c, gzFile file) {
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* in case this was just opened, set up the input buffer */
|
||||
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
|
||||
(void)gz_look(state);
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
@ -426,7 +509,7 @@ int ZEXPORT gzungetc(int c, gzFile file) {
|
||||
if (state->x.have == 0) {
|
||||
state->x.have = 1;
|
||||
state->x.next = state->out + (state->size << 1) - 1;
|
||||
state->x.next[0] = c;
|
||||
state->x.next[0] = (unsigned char)c;
|
||||
state->x.pos--;
|
||||
state->past = 0;
|
||||
return c;
|
||||
@ -448,14 +531,18 @@ int ZEXPORT gzungetc(int c, gzFile file) {
|
||||
}
|
||||
state->x.have++;
|
||||
state->x.next--;
|
||||
state->x.next[0] = c;
|
||||
state->x.next[0] = (unsigned char)c;
|
||||
state->x.pos--;
|
||||
state->past = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
|
||||
char * ZEXPORT gzgets(file, buf, len)
|
||||
gzFile file;
|
||||
char *buf;
|
||||
int len;
|
||||
{
|
||||
unsigned left, n;
|
||||
char *str;
|
||||
unsigned char *eol;
|
||||
@ -515,7 +602,9 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzdirect(gzFile file) {
|
||||
int ZEXPORT gzdirect(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
@ -533,7 +622,9 @@ int ZEXPORT gzdirect(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzclose_r(gzFile file) {
|
||||
int ZEXPORT gzclose_r(file)
|
||||
gzFile file;
|
||||
{
|
||||
int ret, err;
|
||||
gz_statep state;
|
||||
|
||||
|
||||
272
deps/zlib/gzwrite.c
vendored
272
deps/zlib/gzwrite.c
vendored
@ -1,18 +1,22 @@
|
||||
/* gzwrite.c -- zlib functions for writing gzip files
|
||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
||||
* Copyright (C) 2004-2019 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
local int gz_init(gz_statep);
|
||||
local int gz_comp(gz_statep, int);
|
||||
local int gz_zero(gz_statep, z_off64_t);
|
||||
local int gz_init OF((gz_statep));
|
||||
local int gz_comp OF((gz_statep, int));
|
||||
local int gz_zero OF((gz_statep, z_off64_t));
|
||||
local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
|
||||
|
||||
/* Initialize state for writing a gzip file. Mark initialization by setting
|
||||
state->size to non-zero. Return -1 on failure or 0 on success. */
|
||||
static int gz_init(gz_statep state) {
|
||||
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
|
||||
success. */
|
||||
local int gz_init(state)
|
||||
gz_statep state;
|
||||
{
|
||||
int ret;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
@ -66,10 +70,12 @@ static int gz_init(gz_statep state) {
|
||||
deflate() flush value. If flush is Z_FINISH, then the deflate() state is
|
||||
reset to start a new gzip stream. If gz->direct is true, then simply write
|
||||
to the output file without compressing, and ignore flush. */
|
||||
static int gz_comp(gz_statep state, int flush) {
|
||||
int ret;
|
||||
z_ssize_t got;
|
||||
unsigned have;
|
||||
local int gz_comp(state, flush)
|
||||
gz_statep state;
|
||||
int flush;
|
||||
{
|
||||
int ret, writ;
|
||||
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* allocate memory if this is the first time through */
|
||||
@ -79,13 +85,14 @@ static int gz_comp(gz_statep state, int flush) {
|
||||
/* write directly if requested */
|
||||
if (state->direct) {
|
||||
while (strm->avail_in) {
|
||||
got = write(state->fd, strm->next_in, strm->avail_in);
|
||||
if (got < 0) {
|
||||
put = strm->avail_in > max ? max : strm->avail_in;
|
||||
writ = write(state->fd, strm->next_in, put);
|
||||
if (writ < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
strm->avail_in -= got;
|
||||
strm->next_in += got;
|
||||
strm->avail_in -= (unsigned)writ;
|
||||
strm->next_in += writ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -107,13 +114,14 @@ static int gz_comp(gz_statep state, int flush) {
|
||||
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
||||
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
||||
while (strm->next_out > state->x.next) {
|
||||
got = write(state->fd, state->x.next,
|
||||
strm->next_out - state->x.next);
|
||||
if (got < 0) {
|
||||
put = strm->next_out - state->x.next > (int)max ? max :
|
||||
(unsigned)(strm->next_out - state->x.next);
|
||||
writ = write(state->fd, state->x.next, put);
|
||||
if (writ < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
state->x.next += got;
|
||||
state->x.next += writ;
|
||||
}
|
||||
if (strm->avail_out == 0) {
|
||||
strm->avail_out = state->size;
|
||||
@ -141,8 +149,12 @@ static int gz_comp(gz_statep state, int flush) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compress len zeros to output. Return -1 on error, 0 on success. */
|
||||
static int gz_zero(gz_statep state, z_off64_t len) {
|
||||
/* Compress len zeros to output. Return -1 on a write error or memory
|
||||
allocation failure by gz_comp(), or 0 on success. */
|
||||
local int gz_zero(state, len)
|
||||
gz_statep state;
|
||||
z_off64_t len;
|
||||
{
|
||||
int first;
|
||||
unsigned n;
|
||||
z_streamp strm = &(state->strm);
|
||||
@ -170,29 +182,14 @@ static int gz_zero(gz_statep state, z_off64_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
|
||||
{
|
||||
unsigned put = len;
|
||||
/* Write len bytes from buf to file. Return the number of bytes written. If
|
||||
the returned value is less than len, then there was an error. */
|
||||
local z_size_t gz_write(state, buf, len)
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids the flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
||||
return 0;
|
||||
}
|
||||
voidpc buf;
|
||||
z_size_t len;
|
||||
{
|
||||
z_size_t put = len;
|
||||
|
||||
/* if len is zero, avoid unnecessary operations */
|
||||
if (len == 0)
|
||||
@ -215,14 +212,15 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
|
||||
do {
|
||||
unsigned have, copy;
|
||||
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
||||
if (state->strm.avail_in == 0)
|
||||
state->strm.next_in = state->in;
|
||||
have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
|
||||
state->in);
|
||||
copy = state->size - have;
|
||||
if (copy > len)
|
||||
copy = len;
|
||||
copy = (unsigned)len;
|
||||
memcpy(state->in + have, buf, copy);
|
||||
strm->avail_in += copy;
|
||||
state->strm.avail_in += copy;
|
||||
state->x.pos += copy;
|
||||
buf = (const char *)buf + copy;
|
||||
len -= copy;
|
||||
@ -232,23 +230,89 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
|
||||
}
|
||||
else {
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
|
||||
/* directly compress user buffer to file */
|
||||
strm->avail_in = len;
|
||||
strm->next_in = (z_const Bytef *)buf;
|
||||
state->x.pos += len;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
state->strm.next_in = (z_const Bytef *)buf;
|
||||
do {
|
||||
unsigned n = (unsigned)-1;
|
||||
if (n > len)
|
||||
n = (unsigned)len;
|
||||
state->strm.avail_in = n;
|
||||
state->x.pos += n;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
len -= n;
|
||||
} while (len);
|
||||
}
|
||||
|
||||
/* input was all buffered or compressed (put will fit in int) */
|
||||
return (int)put;
|
||||
/* input was all buffered or compressed */
|
||||
return put;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputc(gzFile file, int c)
|
||||
int ZEXPORT gzwrite(file, buf, len)
|
||||
gzFile file;
|
||||
voidpc buf;
|
||||
unsigned len;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids a flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* write len bytes from buf (the return value will fit in an int) */
|
||||
return (int)gz_write(state, buf, len);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
|
||||
voidpc buf;
|
||||
z_size_t size;
|
||||
z_size_t nitems;
|
||||
gzFile file;
|
||||
{
|
||||
z_size_t len;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
|
||||
/* compute bytes to read -- error on overflow */
|
||||
len = nitems * size;
|
||||
if (size && len / size != nitems) {
|
||||
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* write len bytes to buf, return the number of full items written */
|
||||
return len ? gz_write(state, buf, len) / size : 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputc(file, c)
|
||||
gzFile file;
|
||||
int c;
|
||||
{
|
||||
unsigned have;
|
||||
unsigned char buf[1];
|
||||
@ -279,7 +343,7 @@ int ZEXPORT gzputc(gzFile file, int c)
|
||||
strm->next_in = state->in;
|
||||
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
||||
if (have < state->size) {
|
||||
state->in[have] = c;
|
||||
state->in[have] = (unsigned char)c;
|
||||
strm->avail_in++;
|
||||
state->x.pos++;
|
||||
return c & 0xff;
|
||||
@ -287,22 +351,37 @@ int ZEXPORT gzputc(gzFile file, int c)
|
||||
}
|
||||
|
||||
/* no room in buffer or not initialized, use gz_write() */
|
||||
buf[0] = c;
|
||||
if (gzwrite(file, buf, 1) != 1)
|
||||
buf[0] = (unsigned char)c;
|
||||
if (gz_write(state, buf, 1) != 1)
|
||||
return -1;
|
||||
return c & 0xff;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputs(gzFile file, const char *str)
|
||||
int ZEXPORT gzputs(file, s)
|
||||
gzFile file;
|
||||
const char *s;
|
||||
{
|
||||
int ret;
|
||||
unsigned len;
|
||||
z_size_t len, put;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* write string */
|
||||
len = (unsigned)strlen(str);
|
||||
ret = gzwrite(file, str, len);
|
||||
return ret == 0 && len != 0 ? -1 : ret;
|
||||
len = strlen(s);
|
||||
if ((int)len < 0 || (unsigned)len != len) {
|
||||
gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
|
||||
return -1;
|
||||
}
|
||||
put = gz_write(state, s, len);
|
||||
return put < len ? -1 : (int)len;
|
||||
}
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
@ -311,30 +390,31 @@ int ZEXPORT gzputs(gzFile file, const char *str)
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
||||
{
|
||||
unsigned len, left;
|
||||
int len;
|
||||
unsigned left;
|
||||
char *next;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* make sure we have some buffer space */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return 0;
|
||||
return state->err;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return 0;
|
||||
return state->err;
|
||||
}
|
||||
|
||||
/* do the printf() into the input buffer, put length in len -- the input
|
||||
@ -342,7 +422,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
||||
be state->size bytes available after the current contents */
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
next = (char *)(strm->next_in + strm->avail_in);
|
||||
next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
|
||||
next[state->size - 1] = 0;
|
||||
#ifdef NO_vsnprintf
|
||||
# ifdef HAS_vsprintf_void
|
||||
@ -362,25 +442,26 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
||||
#endif
|
||||
|
||||
/* check that printf() results fit in buffer */
|
||||
if (len == 0 || len >= state->size || next[state->size - 1] != 0)
|
||||
if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
|
||||
return 0;
|
||||
|
||||
/* update buffer and position, compress first half if past that */
|
||||
strm->avail_in += len;
|
||||
strm->avail_in += (unsigned)len;
|
||||
state->x.pos += len;
|
||||
if (strm->avail_in >= state->size) {
|
||||
left = strm->avail_in - state->size;
|
||||
strm->avail_in = state->size;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
memcpy(state->in, state->in + state->size, left);
|
||||
return state->err;
|
||||
memmove(state->in, state->in + state->size, left);
|
||||
strm->next_in = state->in;
|
||||
strm->avail_in = left;
|
||||
}
|
||||
return (int)len;
|
||||
return len;
|
||||
}
|
||||
|
||||
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
|
||||
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
int ret;
|
||||
|
||||
@ -407,27 +488,27 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that can really pass pointer in ints */
|
||||
if (sizeof(int) != sizeof(void *))
|
||||
return 0;
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* make sure we have some buffer space */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return 0;
|
||||
return state->error;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return 0;
|
||||
return state->error;
|
||||
}
|
||||
|
||||
/* do the printf() into the input buffer, put length in len -- the input
|
||||
@ -470,8 +551,8 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
left = strm->avail_in - state->size;
|
||||
strm->avail_in = state->size;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
memcpy(state->in, state->in + state->size, left);
|
||||
return state->err;
|
||||
memmove(state->in, state->in + state->size, left);
|
||||
strm->next_in = state->in;
|
||||
strm->avail_in = left;
|
||||
}
|
||||
@ -481,12 +562,15 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzflush(gzFile file, int flush) {
|
||||
int ZEXPORT gzflush(file, flush)
|
||||
gzFile file;
|
||||
int flush;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
@ -501,7 +585,7 @@ int ZEXPORT gzflush(gzFile file, int flush) {
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
return state->err;
|
||||
}
|
||||
|
||||
/* compress remaining data with requested flush */
|
||||
@ -510,7 +594,11 @@ int ZEXPORT gzflush(gzFile file, int flush) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
int ZEXPORT gzsetparams(file, level, strategy)
|
||||
gzFile file;
|
||||
int level;
|
||||
int strategy;
|
||||
{
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
@ -521,7 +609,7 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct)
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* if no change is requested, then do nothing */
|
||||
@ -532,7 +620,7 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
return state->err;
|
||||
}
|
||||
|
||||
/* change compression parameters for subsequent input */
|
||||
@ -548,7 +636,9 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzclose_w(gzFile file) {
|
||||
int ZEXPORT gzclose_w(file)
|
||||
gzFile file;
|
||||
{
|
||||
int ret = Z_OK;
|
||||
gz_statep state;
|
||||
|
||||
|
||||
59
deps/zlib/infback.c
vendored
59
deps/zlib/infback.c
vendored
@ -1,5 +1,5 @@
|
||||
/* infback.c -- inflate using a call-back interface
|
||||
* Copyright (C) 1995-2011 Mark Adler
|
||||
* Copyright (C) 1995-2022 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
#include "inffast.h"
|
||||
|
||||
/* function prototypes */
|
||||
local void fixedtables(struct inflate_state FAR *state);
|
||||
local void fixedtables OF((struct inflate_state FAR *state));
|
||||
|
||||
/*
|
||||
strm provides memory allocation functions in zalloc and zfree, or
|
||||
@ -25,9 +25,13 @@ local void fixedtables(struct inflate_state FAR *state);
|
||||
windowBits is in the range 8..15, and window is a user-supplied
|
||||
window and output buffer that is 2**windowBits bytes.
|
||||
*/
|
||||
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
|
||||
unsigned char FAR *window, const char *version,
|
||||
int stream_size) {
|
||||
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
|
||||
z_streamp strm;
|
||||
int windowBits;
|
||||
unsigned char FAR *window;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
@ -57,12 +61,11 @@ int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
strm->state = (struct internal_state FAR *)state;
|
||||
state->dmax = 32768U;
|
||||
state->wbits = windowBits;
|
||||
state->wbits = (uInt)windowBits;
|
||||
state->wsize = 1U << windowBits;
|
||||
state->window = window;
|
||||
state->wnext = 0;
|
||||
state->whave = 0;
|
||||
state->sane = 1;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
@ -76,7 +79,9 @@ int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
|
||||
used for threaded applications, since the rewriting of the tables and virgin
|
||||
may not be thread-safe.
|
||||
*/
|
||||
static void fixedtables(struct inflate_state FAR *state) {
|
||||
local void fixedtables(state)
|
||||
struct inflate_state FAR *state;
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
static int virgin = 1;
|
||||
static code *lenfix, *distfix;
|
||||
@ -242,8 +247,13 @@ static void fixedtables(struct inflate_state FAR *state) {
|
||||
inflateBack() can also return Z_STREAM_ERROR if the input parameters
|
||||
are not correct, i.e. strm is Z_NULL or the state was not initialized.
|
||||
*/
|
||||
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
out_func out, void FAR *out_desc) {
|
||||
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
|
||||
z_streamp strm;
|
||||
in_func in;
|
||||
void FAR *in_desc;
|
||||
out_func out;
|
||||
void FAR *out_desc;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
@ -444,11 +454,11 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (10 and 9) without reading the comments in inftrees.h
|
||||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 10;
|
||||
state->lenbits = 9;
|
||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
@ -457,7 +467,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
break;
|
||||
}
|
||||
state->distcode = (code const FAR *)(state->next);
|
||||
state->distbits = 9;
|
||||
state->distbits = 6;
|
||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
if (ret) {
|
||||
@ -471,8 +481,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
|
||||
case LEN:
|
||||
/* use inflate_fast() if we have enough input and output */
|
||||
if (have >= INFLATE_FAST_MIN_INPUT &&
|
||||
left >= INFLATE_FAST_MIN_OUTPUT) {
|
||||
if (have >= 6 && left >= 258) {
|
||||
RESTORE();
|
||||
if (state->whave < state->wsize)
|
||||
state->whave = state->wsize - left;
|
||||
@ -596,33 +605,33 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
break;
|
||||
|
||||
case DONE:
|
||||
/* inflate stream terminated properly */
|
||||
/* inflate stream terminated properly -- write leftover output */
|
||||
ret = Z_STREAM_END;
|
||||
if (left < state->wsize) {
|
||||
if (out(out_desc, state->window, state->wsize - left))
|
||||
ret = Z_BUF_ERROR;
|
||||
}
|
||||
goto inf_leave;
|
||||
|
||||
case BAD:
|
||||
ret = Z_DATA_ERROR;
|
||||
goto inf_leave;
|
||||
|
||||
default:
|
||||
/* can't happen, but makes compilers happy */
|
||||
default: /* can't happen, but makes compilers happy */
|
||||
ret = Z_STREAM_ERROR;
|
||||
goto inf_leave;
|
||||
}
|
||||
|
||||
/* Write leftover output and return unused input */
|
||||
/* Return unused input */
|
||||
inf_leave:
|
||||
if (left < state->wsize) {
|
||||
if (out(out_desc, state->window, state->wsize - left) &&
|
||||
ret == Z_STREAM_END)
|
||||
ret = Z_BUF_ERROR;
|
||||
}
|
||||
strm->next_in = next;
|
||||
strm->avail_in = have;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateBackEnd(z_streamp strm) {
|
||||
int ZEXPORT inflateBackEnd(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
|
||||
return Z_STREAM_ERROR;
|
||||
ZFREE(strm, strm->state);
|
||||
|
||||
24
deps/zlib/inffast.c
vendored
24
deps/zlib/inffast.c
vendored
@ -8,7 +8,9 @@
|
||||
#include "inflate.h"
|
||||
#include "inffast.h"
|
||||
|
||||
#ifndef ASMINF
|
||||
#ifdef ASMINF
|
||||
# pragma message("Assembler code may have bugs -- use at your own risk")
|
||||
#else
|
||||
|
||||
/*
|
||||
Decode literal, length, and distance codes and write out the resulting
|
||||
@ -21,8 +23,8 @@
|
||||
Entry assumptions:
|
||||
|
||||
state->mode == LEN
|
||||
strm->avail_in >= INFLATE_FAST_MIN_INPUT
|
||||
strm->avail_out >= INFLATE_FAST_MIN_OUTPUT
|
||||
strm->avail_in >= 6
|
||||
strm->avail_out >= 258
|
||||
start >= strm->avail_out
|
||||
state->bits < 8
|
||||
|
||||
@ -45,7 +47,10 @@
|
||||
requires strm->avail_out >= 258 for each loop to avoid checking for
|
||||
output space.
|
||||
*/
|
||||
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
||||
void ZLIB_INTERNAL inflate_fast(strm, start)
|
||||
z_streamp strm;
|
||||
unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
z_const unsigned char FAR *in; /* local strm->next_in */
|
||||
z_const unsigned char FAR *last; /* have enough input while in < last */
|
||||
@ -75,10 +80,10 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
||||
/* copy state to local variables */
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
in = strm->next_in;
|
||||
last = in + (strm->avail_in - (INFLATE_FAST_MIN_INPUT - 1));
|
||||
last = in + (strm->avail_in - 5);
|
||||
out = strm->next_out;
|
||||
beg = out - (start - strm->avail_out);
|
||||
end = out + (strm->avail_out - (INFLATE_FAST_MIN_OUTPUT - 1));
|
||||
end = out + (strm->avail_out - 257);
|
||||
#ifdef INFLATE_STRICT
|
||||
dmax = state->dmax;
|
||||
#endif
|
||||
@ -293,12 +298,9 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
||||
/* update state and return */
|
||||
strm->next_in = in;
|
||||
strm->next_out = out;
|
||||
strm->avail_in = (unsigned)(in < last ?
|
||||
(INFLATE_FAST_MIN_INPUT - 1) + (last - in) :
|
||||
(INFLATE_FAST_MIN_INPUT - 1) - (in - last));
|
||||
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
||||
strm->avail_out = (unsigned)(out < end ?
|
||||
(INFLATE_FAST_MIN_OUTPUT - 1) + (end - out) :
|
||||
(INFLATE_FAST_MIN_OUTPUT - 1) - (out - end));
|
||||
257 + (end - out) : 257 - (out - end));
|
||||
state->hold = hold;
|
||||
state->bits = bits;
|
||||
return;
|
||||
|
||||
17
deps/zlib/inffast.h
vendored
17
deps/zlib/inffast.h
vendored
@ -8,19 +8,4 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* INFLATE_FAST_MIN_INPUT: the minimum number of input bytes needed so that
|
||||
we can safely call inflate_fast() with only one up-front bounds check. One
|
||||
length/distance code pair (15 bits for the length code, 5 bits for length
|
||||
extra, 15 bits for the distance code, 13 bits for distance extra) requires
|
||||
reading up to 48 input bits (6 bytes).
|
||||
*/
|
||||
#define INFLATE_FAST_MIN_INPUT 6
|
||||
|
||||
/* INFLATE_FAST_MIN_OUTPUT: the minimum number of output bytes needed so that
|
||||
we can safely call inflate_fast() with only one up-front bounds check. One
|
||||
length/distance code pair can output up to 258 bytes, which is the maximum
|
||||
length that can be coded.
|
||||
*/
|
||||
#define INFLATE_FAST_MIN_OUTPUT 258
|
||||
|
||||
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);
|
||||
void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
|
||||
|
||||
398
deps/zlib/inffast_chunk.c
vendored
398
deps/zlib/inffast_chunk.c
vendored
@ -1,398 +0,0 @@
|
||||
/* inffast_chunk.c -- fast decoding
|
||||
*
|
||||
* (C) 1995-2013 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Jean-loup Gailly Mark Adler
|
||||
* jloup@gzip.org madler@alumni.caltech.edu
|
||||
*
|
||||
* Copyright (C) 1995-2017 Mark Adler
|
||||
* Copyright 2023 The Chromium Authors
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inffast_chunk.h"
|
||||
#include "chunkcopy.h"
|
||||
|
||||
#ifdef ASMINF
|
||||
# pragma message("Assembler code may have bugs -- use at your own risk")
|
||||
#else
|
||||
|
||||
/*
|
||||
Decode literal, length, and distance codes and write out the resulting
|
||||
literal and match bytes until either not enough input or output is
|
||||
available, an end-of-block is encountered, or a data error is encountered.
|
||||
When large enough input and output buffers are supplied to inflate(), for
|
||||
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
||||
inflate() execution time is spent in this routine.
|
||||
|
||||
Entry assumptions:
|
||||
|
||||
state->mode == LEN
|
||||
strm->avail_in >= INFLATE_FAST_MIN_INPUT (6 or 8 bytes + 7 bytes)
|
||||
strm->avail_out >= INFLATE_FAST_MIN_OUTPUT (258 bytes + 2 bytes)
|
||||
start >= strm->avail_out
|
||||
state->bits < 8
|
||||
strm->next_out[0..strm->avail_out] does not overlap with
|
||||
strm->next_in[0..strm->avail_in]
|
||||
strm->state->window is allocated with an additional
|
||||
CHUNKCOPY_CHUNK_SIZE-1 bytes of padding beyond strm->state->wsize
|
||||
|
||||
On return, state->mode is one of:
|
||||
|
||||
LEN -- ran out of enough output space or enough available input
|
||||
TYPE -- reached end of block code, inflate() to interpret next block
|
||||
BAD -- error in block data
|
||||
|
||||
Notes:
|
||||
|
||||
INFLATE_FAST_MIN_INPUT: 6 or 8 bytes + 7 bytes
|
||||
|
||||
- The maximum input bits used by a length/distance pair is 15 bits for the
|
||||
length code, 5 bits for the length extra, 15 bits for the distance code,
|
||||
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
||||
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
||||
checking for available input while decoding.
|
||||
|
||||
- The wide input data reading option reads 64 input bits at a time. Thus,
|
||||
if strm->avail_in >= 8, then there is enough input to avoid checking for
|
||||
available input while decoding. Reading consumes the input with:
|
||||
|
||||
hold |= read64le(in) << bits;
|
||||
in += 6;
|
||||
bits += 48;
|
||||
|
||||
reporting 6 bytes of new input because |bits| is 0..15 (2 bytes rounded
|
||||
up, worst case) and 6 bytes is enough to decode as noted above. At exit,
|
||||
hold &= (1U << bits) - 1 drops excess input to keep the invariant:
|
||||
|
||||
(state->hold >> state->bits) == 0
|
||||
|
||||
INFLATE_FAST_MIN_OUTPUT: 258 bytes + 2 bytes for literals = 260 bytes
|
||||
|
||||
- The maximum bytes that a single length/distance pair can output is 258
|
||||
bytes, which is the maximum length that can be coded. inflate_fast()
|
||||
requires strm->avail_out >= 260 for each loop to avoid checking for
|
||||
available output space while decoding.
|
||||
*/
|
||||
void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) /* inflate()'s starting value for strm->avail_out */
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
z_const unsigned char FAR *in; /* local strm->next_in */
|
||||
z_const unsigned char FAR *last; /* have enough input while in < last */
|
||||
unsigned char FAR *out; /* local strm->next_out */
|
||||
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
||||
unsigned char FAR *end; /* while out < end, enough space available */
|
||||
unsigned char FAR *limit; /* safety limit for chunky copies */
|
||||
#ifdef INFLATE_STRICT
|
||||
unsigned dmax; /* maximum distance from zlib header */
|
||||
#endif
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
||||
inflate_holder_t hold; /* local strm->hold */
|
||||
unsigned bits; /* local strm->bits */
|
||||
code const FAR *lcode; /* local strm->lencode */
|
||||
code const FAR *dcode; /* local strm->distcode */
|
||||
unsigned lmask; /* mask for first level of length codes */
|
||||
unsigned dmask; /* mask for first level of distance codes */
|
||||
code const *here; /* retrieved table entry */
|
||||
unsigned op; /* code bits, operation, extra bits, or */
|
||||
/* window position, window bytes to copy */
|
||||
unsigned len; /* match length, unused bytes */
|
||||
unsigned dist; /* match distance */
|
||||
unsigned char FAR *from; /* where to copy match from */
|
||||
|
||||
/* copy state to local variables */
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
in = strm->next_in;
|
||||
last = in + (strm->avail_in - (INFLATE_FAST_MIN_INPUT - 1));
|
||||
out = strm->next_out;
|
||||
beg = out - (start - strm->avail_out);
|
||||
end = out + (strm->avail_out - (INFLATE_FAST_MIN_OUTPUT - 1));
|
||||
limit = out + strm->avail_out;
|
||||
#ifdef INFLATE_STRICT
|
||||
dmax = state->dmax;
|
||||
#endif
|
||||
wsize = state->wsize;
|
||||
whave = state->whave;
|
||||
wnext = (state->wnext == 0 && whave >= wsize) ? wsize : state->wnext;
|
||||
window = state->window;
|
||||
hold = state->hold;
|
||||
bits = state->bits;
|
||||
lcode = state->lencode;
|
||||
dcode = state->distcode;
|
||||
lmask = (1U << state->lenbits) - 1;
|
||||
dmask = (1U << state->distbits) - 1;
|
||||
|
||||
#ifdef INFLATE_CHUNK_READ_64LE
|
||||
#define REFILL() do { \
|
||||
Assert(bits < 64, "### Too many bits in inflate_fast."); \
|
||||
hold |= read64le(in) << bits; \
|
||||
in += 7; \
|
||||
in -= bits >> 3; \
|
||||
bits |= 56; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* decode literals and length/distances until end-of-block or not enough
|
||||
input data or output space */
|
||||
do {
|
||||
#ifdef INFLATE_CHUNK_READ_64LE
|
||||
REFILL();
|
||||
#else
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
#endif
|
||||
here = lcode + (hold & lmask);
|
||||
#ifdef INFLATE_CHUNK_READ_64LE
|
||||
if (here->op == 0) { /* literal */
|
||||
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", here->val));
|
||||
*out++ = (unsigned char)(here->val);
|
||||
hold >>= here->bits;
|
||||
bits -= here->bits;
|
||||
here = lcode + (hold & lmask);
|
||||
if (here->op == 0) { /* literal */
|
||||
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
||||
"inflate: 2nd literal '%c'\n" :
|
||||
"inflate: 2nd literal 0x%02x\n", here->val));
|
||||
*out++ = (unsigned char)(here->val);
|
||||
hold >>= here->bits;
|
||||
bits -= here->bits;
|
||||
here = lcode + (hold & lmask);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
dolen:
|
||||
op = (unsigned)(here->bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(here->op);
|
||||
if (op == 0) { /* literal */
|
||||
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", here->val));
|
||||
*out++ = (unsigned char)(here->val);
|
||||
}
|
||||
else if (op & 16) { /* length base */
|
||||
len = (unsigned)(here->val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (op) {
|
||||
#ifndef INFLATE_CHUNK_READ_64LE
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
#endif
|
||||
len += (unsigned)hold & ((1U << op) - 1);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", len));
|
||||
#ifndef INFLATE_CHUNK_READ_64LE
|
||||
if (bits < 15) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
#endif
|
||||
here = dcode + (hold & dmask);
|
||||
dodist:
|
||||
op = (unsigned)(here->bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(here->op);
|
||||
if (op & 16) { /* distance base */
|
||||
dist = (unsigned)(here->val);
|
||||
op &= 15; /* number of extra bits */
|
||||
/* we have two fast-path loads: 10+10 + 15+5 + 15 = 55,
|
||||
but we may need to refill here in the worst case */
|
||||
if (bits < op) {
|
||||
#ifdef INFLATE_CHUNK_READ_64LE
|
||||
REFILL();
|
||||
#else
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(*in++) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
dist += (unsigned)hold & ((1U << op) - 1);
|
||||
#ifdef INFLATE_STRICT
|
||||
if (dist > dmax) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||
op = (unsigned)(out - beg); /* max distance in output */
|
||||
if (dist > op) { /* see if copy from window */
|
||||
op = dist - op; /* distance back in window */
|
||||
if (op > whave) {
|
||||
if (state->sane) {
|
||||
strm->msg =
|
||||
(char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
if (len <= op - whave) {
|
||||
do {
|
||||
*out++ = 0;
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
len -= op - whave;
|
||||
do {
|
||||
*out++ = 0;
|
||||
} while (--op > whave);
|
||||
if (op == 0) {
|
||||
from = out - dist;
|
||||
do {
|
||||
*out++ = *from++;
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
from = window;
|
||||
if (wnext >= op) { /* contiguous in window */
|
||||
from += wnext - op;
|
||||
}
|
||||
else { /* wrap around window */
|
||||
op -= wnext;
|
||||
from += wsize - op;
|
||||
if (op < len) { /* some from end of window */
|
||||
len -= op;
|
||||
out = chunkcopy_safe(out, from, op, limit);
|
||||
from = window; /* more from start of window */
|
||||
op = wnext;
|
||||
/* This (rare) case can create a situation where
|
||||
the first chunkcopy below must be checked.
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (op < len) { /* still need some from output */
|
||||
out = chunkcopy_safe(out, from, op, limit);
|
||||
len -= op;
|
||||
/* When dist is small the amount of data that can be
|
||||
copied from the window is also small, and progress
|
||||
towards the dangerous end of the output buffer is
|
||||
also small. This means that for trivial memsets and
|
||||
for chunkunroll_relaxed() a safety check is
|
||||
unnecessary. However, these conditions may not be
|
||||
entered at all, and in that case it's possible that
|
||||
the main copy is near the end.
|
||||
*/
|
||||
out = chunkunroll_relaxed(out, &dist, &len);
|
||||
out = chunkcopy_safe_ugly(out, dist, len, limit);
|
||||
} else {
|
||||
/* from points to window, so there is no risk of
|
||||
overlapping pointers requiring memset-like behaviour
|
||||
*/
|
||||
out = chunkcopy_safe(out, from, len, limit);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Whole reference is in range of current output. No
|
||||
range checks are necessary because we start with room
|
||||
for at least 258 bytes of output, so unroll and roundoff
|
||||
operations can write beyond `out+len` so long as they
|
||||
stay within 258 bytes of `out`.
|
||||
*/
|
||||
out = chunkcopy_lapped_relaxed(out, dist, len);
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||
here = dcode + here->val + (hold & ((1U << op) - 1));
|
||||
goto dodist;
|
||||
}
|
||||
else {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level length code */
|
||||
here = lcode + here->val + (hold & ((1U << op) - 1));
|
||||
goto dolen;
|
||||
}
|
||||
else if (op & 32) { /* end-of-block */
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
} while (in < last && out < end);
|
||||
|
||||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
||||
len = bits >> 3;
|
||||
in -= len;
|
||||
bits -= len << 3;
|
||||
hold &= (1U << bits) - 1;
|
||||
|
||||
/* update state and return */
|
||||
strm->next_in = in;
|
||||
strm->next_out = out;
|
||||
strm->avail_in = (unsigned)(in < last ?
|
||||
(INFLATE_FAST_MIN_INPUT - 1) + (last - in) :
|
||||
(INFLATE_FAST_MIN_INPUT - 1) - (in - last));
|
||||
strm->avail_out = (unsigned)(out < end ?
|
||||
(INFLATE_FAST_MIN_OUTPUT - 1) + (end - out) :
|
||||
(INFLATE_FAST_MIN_OUTPUT - 1) - (out - end));
|
||||
state->hold = hold;
|
||||
state->bits = bits;
|
||||
|
||||
Assert((state->hold >> state->bits) == 0, "invalid input data state");
|
||||
}
|
||||
|
||||
/*
|
||||
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
||||
- Using bit fields for code structure
|
||||
- Different op definition to avoid & for extra bits (do & for table bits)
|
||||
- Three separate decoding do-loops for direct, window, and wnext == 0
|
||||
- Special case for distance > 1 copies to do overlapped load and store copy
|
||||
- Explicit branch predictions (based on measured branch probabilities)
|
||||
- Deferring match copy and interspersed it with decoding subsequent codes
|
||||
- Swapping literal/length else
|
||||
- Swapping window/direct else
|
||||
- Larger unrolled copy loops (three is about right)
|
||||
- Moving len -= 3 statement into middle of loop
|
||||
*/
|
||||
|
||||
#endif /* !ASMINF */
|
||||
64
deps/zlib/inffast_chunk.h
vendored
64
deps/zlib/inffast_chunk.h
vendored
@ -1,64 +0,0 @@
|
||||
/* inffast_chunk.h -- header to use inffast_chunk.c
|
||||
*
|
||||
* (C) 1995-2013 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Jean-loup Gailly Mark Adler
|
||||
* jloup@gzip.org madler@alumni.caltech.edu
|
||||
*
|
||||
* Copyright (C) 1995-2003, 2010 Mark Adler
|
||||
* Copyright (C) 2017 ARM, Inc.
|
||||
* Copyright 2023 The Chromium Authors
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
#include "inffast.h"
|
||||
|
||||
/* INFLATE_FAST_MIN_INPUT:
|
||||
The minimum number of input bytes needed so that we can safely call
|
||||
inflate_fast() with only one up-front bounds check. One
|
||||
length/distance code pair (15 bits for the length code, 5 bits for length
|
||||
extra, 15 bits for the distance code, 13 bits for distance extra) requires
|
||||
reading up to 48 input bits. Additionally, in the same iteraction, we may
|
||||
decode two literals from the root-table (requiring MIN_OUTPUT = 258 + 2).
|
||||
|
||||
Each root-table entry is up to 10 bits, for a total of 68 input bits each
|
||||
iteraction.
|
||||
|
||||
The refill variant reads 8 bytes from the buffer at a time, and advances
|
||||
the input pointer by up to 7 bytes, ensuring there are at least 56-bits
|
||||
available in the bit-buffer. The technique was documented by Fabian Giesen
|
||||
on his blog as variant 4 in the article 'Reading bits in far too many ways':
|
||||
https://fgiesen.wordpress.com/2018/02/20/
|
||||
|
||||
In the worst case, we may refill twice in the same iteraction, requiring
|
||||
MIN_INPUT = 8 + 7.
|
||||
*/
|
||||
#ifdef INFLATE_CHUNK_READ_64LE
|
||||
#undef INFLATE_FAST_MIN_INPUT
|
||||
#define INFLATE_FAST_MIN_INPUT 15
|
||||
#undef INFLATE_FAST_MIN_OUTPUT
|
||||
#define INFLATE_FAST_MIN_OUTPUT 260
|
||||
#endif
|
||||
|
||||
void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start);
|
||||
238
deps/zlib/inflate.c
vendored
238
deps/zlib/inflate.c
vendored
@ -1,5 +1,5 @@
|
||||
/* inflate.c -- zlib decompression
|
||||
* Copyright (C) 1995-2012 Mark Adler
|
||||
* Copyright (C) 1995-2022 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -83,13 +83,7 @@
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
|
||||
#if defined(INFLATE_CHUNK_SIMD_NEON) || defined(INFLATE_CHUNK_SIMD_SSE2) || defined(INFLATE_CHUNK_GENERIC)
|
||||
#include "inffast_chunk.h"
|
||||
#include "chunkcopy.h"
|
||||
#else
|
||||
#include "inffast.h"
|
||||
#endif
|
||||
|
||||
#ifdef MAKEFIXED
|
||||
# ifndef BUILDFIXED
|
||||
@ -98,17 +92,19 @@
|
||||
#endif
|
||||
|
||||
/* function prototypes */
|
||||
local int inflateStateCheck(z_streamp strm);
|
||||
local void fixedtables(struct inflate_state FAR *state);
|
||||
local int updatewindow(z_streamp strm, const unsigned char FAR *end,
|
||||
unsigned copy);
|
||||
local int inflateStateCheck OF((z_streamp strm));
|
||||
local void fixedtables OF((struct inflate_state FAR *state));
|
||||
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
|
||||
unsigned copy));
|
||||
#ifdef BUILDFIXED
|
||||
void makefixed(void);
|
||||
void makefixed OF((void));
|
||||
#endif
|
||||
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
|
||||
unsigned len);
|
||||
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
|
||||
unsigned len));
|
||||
|
||||
static int inflateStateCheck(z_streamp strm) {
|
||||
local int inflateStateCheck(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
if (strm == Z_NULL ||
|
||||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
|
||||
@ -120,7 +116,9 @@ static int inflateStateCheck(z_streamp strm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateResetKeep(z_streamp strm) {
|
||||
int ZEXPORT inflateResetKeep(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||
@ -144,7 +142,9 @@ int ZEXPORT inflateResetKeep(z_streamp strm) {
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateReset(z_streamp strm) {
|
||||
int ZEXPORT inflateReset(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||
@ -155,7 +155,10 @@ int ZEXPORT inflateReset(z_streamp strm) {
|
||||
return inflateResetKeep(strm);
|
||||
}
|
||||
|
||||
int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
|
||||
int ZEXPORT inflateReset2(strm, windowBits)
|
||||
z_streamp strm;
|
||||
int windowBits;
|
||||
{
|
||||
int wrap;
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
@ -165,8 +168,6 @@ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
|
||||
|
||||
/* extract wrap request from windowBits parameter */
|
||||
if (windowBits < 0) {
|
||||
if (windowBits < -15)
|
||||
return Z_STREAM_ERROR;
|
||||
wrap = 0;
|
||||
windowBits = -windowBits;
|
||||
}
|
||||
@ -192,8 +193,12 @@ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
|
||||
return inflateReset(strm);
|
||||
}
|
||||
|
||||
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size) {
|
||||
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
|
||||
z_streamp strm;
|
||||
int windowBits;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
int ret;
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
@ -232,27 +237,32 @@ int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateInit_(z_streamp strm, const char *version,
|
||||
int stream_size) {
|
||||
int ZEXPORT inflateInit_(strm, version, stream_size)
|
||||
z_streamp strm;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
return inflateInit2_(strm, DEF_WBITS, version, stream_size);
|
||||
}
|
||||
|
||||
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
|
||||
int ZEXPORT inflatePrime(strm, bits, value)
|
||||
z_streamp strm;
|
||||
int bits;
|
||||
int value;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||
if (bits == 0)
|
||||
return Z_OK;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
if (bits < 0) {
|
||||
state->hold = 0;
|
||||
state->bits = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
|
||||
if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
|
||||
value &= (1L << bits) - 1;
|
||||
state->hold += (unsigned)value << state->bits;
|
||||
state->bits += bits;
|
||||
state->bits += (uInt)bits;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
@ -266,7 +276,9 @@ int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
|
||||
used for threaded applications, since the rewriting of the tables and virgin
|
||||
may not be thread-safe.
|
||||
*/
|
||||
static void fixedtables(struct inflate_state FAR *state) {
|
||||
local void fixedtables(state)
|
||||
struct inflate_state FAR *state;
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
static int virgin = 1;
|
||||
static code *lenfix, *distfix;
|
||||
@ -328,7 +340,7 @@ static void fixedtables(struct inflate_state FAR *state) {
|
||||
|
||||
a.out > inffixed.h
|
||||
*/
|
||||
void makefixed(void)
|
||||
void makefixed()
|
||||
{
|
||||
unsigned low, size;
|
||||
struct inflate_state state;
|
||||
@ -382,7 +394,11 @@ void makefixed(void)
|
||||
output will fall in the output data, making match copies simpler and faster.
|
||||
The advantage may be dependent on the size of the processor's data caches.
|
||||
*/
|
||||
static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
|
||||
local int updatewindow(strm, end, copy)
|
||||
z_streamp strm;
|
||||
const Bytef *end;
|
||||
unsigned copy;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned dist;
|
||||
|
||||
@ -390,27 +406,10 @@ static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
|
||||
|
||||
/* if it hasn't been done already, allocate space for the window */
|
||||
if (state->window == Z_NULL) {
|
||||
#if defined(INFLATE_CHUNK_SIMD_NEON) || defined(INFLATE_CHUNK_SIMD_SSE2) || defined(INFLATE_CHUNK_GENERIC)
|
||||
unsigned wsize = 1U << state->wbits;
|
||||
state->window = (unsigned char FAR *)
|
||||
ZALLOC(strm, wsize + CHUNKCOPY_CHUNK_SIZE,
|
||||
sizeof(unsigned char));
|
||||
if (state->window == Z_NULL) return 1;
|
||||
#ifdef INFLATE_CLEAR_UNUSED_UNDEFINED
|
||||
/* Copies from the overflow portion of this buffer are undefined and
|
||||
may cause analysis tools to raise a wraning if we don't initialize
|
||||
it. However, this undefined data overwrites other undefined data
|
||||
and is subsequently either overwritten or left deliberately
|
||||
undefined at the end of decode; so there's really no point.
|
||||
*/
|
||||
zmemzero(state->window + wsize, CHUNKCOPY_CHUNK_SIZE);
|
||||
#endif
|
||||
#else
|
||||
state->window = (unsigned char FAR *)
|
||||
ZALLOC(strm, 1U << state->wbits,
|
||||
sizeof(unsigned char));
|
||||
if (state->window == Z_NULL) return 1;
|
||||
#endif /* INFLATE_CHUNK_SIMD */
|
||||
}
|
||||
|
||||
/* if window not in use yet, initialize */
|
||||
@ -449,10 +448,10 @@ static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
|
||||
|
||||
/* check function to use adler32() for zlib or crc32() for gzip */
|
||||
#ifdef GUNZIP
|
||||
# define UPDATE(check, buf, len) \
|
||||
# define UPDATE_CHECK(check, buf, len) \
|
||||
(state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
|
||||
#else
|
||||
# define UPDATE(check, buf, len) adler32(check, buf, len)
|
||||
# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
|
||||
#endif
|
||||
|
||||
/* check macros for header crc */
|
||||
@ -621,7 +620,10 @@ static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
|
||||
will return Z_BUF_ERROR if it has not reached the end of the stream.
|
||||
*/
|
||||
|
||||
int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
int ZEXPORT inflate(strm, flush)
|
||||
z_streamp strm;
|
||||
int flush;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
@ -762,9 +764,8 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
if (copy > have) copy = have;
|
||||
if (copy) {
|
||||
if (state->head != Z_NULL &&
|
||||
state->head->extra != Z_NULL &&
|
||||
(len = state->head->extra_len - state->length) <
|
||||
state->head->extra_max) {
|
||||
state->head->extra != Z_NULL) {
|
||||
len = state->head->extra_len - state->length;
|
||||
zmemcpy(state->head->extra + len, next,
|
||||
len + copy > state->head->extra_max ?
|
||||
state->head->extra_max - len : copy);
|
||||
@ -789,7 +790,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
if (state->head != Z_NULL &&
|
||||
state->head->name != Z_NULL &&
|
||||
state->length < state->head->name_max)
|
||||
state->head->name[state->length++] = len;
|
||||
state->head->name[state->length++] = (Bytef)len;
|
||||
} while (len && copy < have);
|
||||
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||
state->check = crc32(state->check, next, copy);
|
||||
@ -811,7 +812,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
if (state->head != Z_NULL &&
|
||||
state->head->comment != Z_NULL &&
|
||||
state->length < state->head->comm_max)
|
||||
state->head->comment[state->length++] = len;
|
||||
state->head->comment[state->length++] = (Bytef)len;
|
||||
} while (len && copy < have);
|
||||
if ((state->flags & 0x0200) && (state->wrap & 4))
|
||||
state->check = crc32(state->check, next, copy);
|
||||
@ -1029,11 +1030,11 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (10 and 9) without reading the comments in inftrees.h
|
||||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (const code FAR *)(state->next);
|
||||
state->lenbits = 10;
|
||||
state->lenbits = 9;
|
||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
@ -1042,7 +1043,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
break;
|
||||
}
|
||||
state->distcode = (const code FAR *)(state->next);
|
||||
state->distbits = 9;
|
||||
state->distbits = 6;
|
||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
if (ret) {
|
||||
@ -1058,14 +1059,9 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
state->mode = LEN;
|
||||
/* fallthrough */
|
||||
case LEN:
|
||||
if (have >= INFLATE_FAST_MIN_INPUT &&
|
||||
left >= INFLATE_FAST_MIN_OUTPUT) {
|
||||
if (have >= 6 && left >= 258) {
|
||||
RESTORE();
|
||||
#if defined(INFLATE_CHUNK_SIMD_NEON) || defined(INFLATE_CHUNK_SIMD_SSE2) || defined(INFLATE_CHUNK_GENERIC)
|
||||
inflate_fast_chunk_(strm, out);
|
||||
#else
|
||||
inflate_fast(strm, out);
|
||||
#endif
|
||||
LOAD();
|
||||
if (state->mode == TYPE)
|
||||
state->back = -1;
|
||||
@ -1200,18 +1196,6 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
else
|
||||
from = state->window + (state->wnext - copy);
|
||||
if (copy > state->length) copy = state->length;
|
||||
#if defined(INFLATE_CHUNK_SIMD_NEON) || defined(INFLATE_CHUNK_SIMD_SSE2) || defined(INFLATE_CHUNK_GENERIC)
|
||||
if (copy > left) copy = left;
|
||||
put = chunkcopy_safe(put, from, copy, put + left);
|
||||
}
|
||||
else { /* copy from output */
|
||||
copy = state->length;
|
||||
if (copy > left) copy = left;
|
||||
put = chunkcopy_lapped_safe(put, state->offset, copy, put + left);
|
||||
}
|
||||
left -= copy;
|
||||
state->length -= copy;
|
||||
#else
|
||||
}
|
||||
else { /* copy from output */
|
||||
from = put - state->offset;
|
||||
@ -1223,7 +1207,6 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
do {
|
||||
*put++ = *from++;
|
||||
} while (--copy);
|
||||
#endif
|
||||
if (state->length == 0) state->mode = LEN;
|
||||
break;
|
||||
case LIT:
|
||||
@ -1240,7 +1223,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
state->total += out;
|
||||
if ((state->wrap & 4) && out)
|
||||
strm->adler = state->check =
|
||||
UPDATE(state->check, put - out, out);
|
||||
UPDATE_CHECK(state->check, put - out, out);
|
||||
out = left;
|
||||
if ((state->wrap & 4) && (
|
||||
#ifdef GUNZIP
|
||||
@ -1292,29 +1275,6 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
Note: a memory error from inflate() is non-recoverable.
|
||||
*/
|
||||
inf_leave:
|
||||
#if defined(ZLIB_DEBUG) && (defined(INFLATE_CHUNK_SIMD_NEON) || defined(INFLATE_CHUNK_SIMD_SSE2) || defined(INFLATE_CHUNK_GENERIC))
|
||||
/* XXX(cavalcantii): I put this in place back in 2017 to help debug faulty
|
||||
* client code relying on undefined behavior when chunk_copy first landed.
|
||||
*
|
||||
* It is save to say after all these years that Chromium code is well
|
||||
* behaved and works fine with the optimization, therefore we can enable
|
||||
* this only for ZLIB_DEBUG builds.
|
||||
*
|
||||
* We write a defined value in the unused space to help mark
|
||||
* where the stream has ended. We don't use zeros as that can
|
||||
* mislead clients relying on undefined behavior (i.e. assuming
|
||||
* that the data is over when the buffer has a zero/null value).
|
||||
*
|
||||
* The basic idea is that if client code is not relying on the zlib context
|
||||
* to inform the amount of decompressed data, but instead reads the output
|
||||
* buffer until a zero/null is found, it will fail faster and harder
|
||||
* when the remaining of the buffer is marked with a symbol (e.g. 0x55).
|
||||
*/
|
||||
if (left >= CHUNKCOPY_CHUNK_SIZE)
|
||||
memset(put, 0x55, CHUNKCOPY_CHUNK_SIZE);
|
||||
else
|
||||
memset(put, 0x55, left);
|
||||
#endif
|
||||
RESTORE();
|
||||
if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
|
||||
(state->mode < CHECK || flush != Z_FINISH)))
|
||||
@ -1329,8 +1289,8 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
state->total += out;
|
||||
if ((state->wrap & 4) && out)
|
||||
strm->adler = state->check =
|
||||
UPDATE(state->check, strm->next_out - out, out);
|
||||
strm->data_type = state->bits + (state->last ? 64 : 0) +
|
||||
UPDATE_CHECK(state->check, strm->next_out - out, out);
|
||||
strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
|
||||
(state->mode == TYPE ? 128 : 0) +
|
||||
(state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
|
||||
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
|
||||
@ -1338,7 +1298,8 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateEnd(z_streamp strm)
|
||||
int ZEXPORT inflateEnd(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
if (inflateStateCheck(strm))
|
||||
@ -1351,8 +1312,11 @@ int ZEXPORT inflateEnd(z_streamp strm)
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
|
||||
uInt *dictLength) {
|
||||
int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
|
||||
z_streamp strm;
|
||||
Bytef *dictionary;
|
||||
uInt *dictLength;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
/* check state */
|
||||
@ -1371,8 +1335,11 @@ int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
|
||||
uInt dictLength) {
|
||||
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
|
||||
z_streamp strm;
|
||||
const Bytef *dictionary;
|
||||
uInt dictLength;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
unsigned long dictid;
|
||||
int ret;
|
||||
@ -1403,7 +1370,10 @@ int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
|
||||
int ZEXPORT inflateGetHeader(strm, head)
|
||||
z_streamp strm;
|
||||
gz_headerp head;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
/* check state */
|
||||
@ -1428,8 +1398,11 @@ int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
|
||||
called again with more data and the *have state. *have is initialized to
|
||||
zero for the first call.
|
||||
*/
|
||||
static unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
|
||||
unsigned len) {
|
||||
local unsigned syncsearch(have, buf, len)
|
||||
unsigned FAR *have;
|
||||
const unsigned char FAR *buf;
|
||||
unsigned len;
|
||||
{
|
||||
unsigned got;
|
||||
unsigned next;
|
||||
|
||||
@ -1448,7 +1421,9 @@ static unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
|
||||
return next;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateSync(z_streamp strm) {
|
||||
int ZEXPORT inflateSync(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
unsigned len; /* number of bytes to look at or looked at */
|
||||
int flags; /* temporary to save header status */
|
||||
unsigned long in, out; /* temporary to save total_in and total_out */
|
||||
@ -1504,7 +1479,9 @@ int ZEXPORT inflateSync(z_streamp strm) {
|
||||
block. When decompressing, PPP checks that at the end of input packet,
|
||||
inflate is waiting for these length bytes.
|
||||
*/
|
||||
int ZEXPORT inflateSyncPoint(z_streamp strm) {
|
||||
int ZEXPORT inflateSyncPoint(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||
@ -1512,7 +1489,10 @@ int ZEXPORT inflateSyncPoint(z_streamp strm) {
|
||||
return state->mode == STORED && state->bits == 0;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
|
||||
int ZEXPORT inflateCopy(dest, source)
|
||||
z_streamp dest;
|
||||
z_streamp source;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
struct inflate_state FAR *copy;
|
||||
unsigned char FAR *window;
|
||||
@ -1556,7 +1536,10 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
|
||||
int ZEXPORT inflateUndermine(strm, subvert)
|
||||
z_streamp strm;
|
||||
int subvert;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||
@ -1565,12 +1548,16 @@ int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
|
||||
state->sane = !subvert;
|
||||
return Z_OK;
|
||||
#else
|
||||
(void)subvert;
|
||||
state->sane = 1;
|
||||
return Z_DATA_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
int ZEXPORT inflateValidate(z_streamp strm, int check) {
|
||||
int ZEXPORT inflateValidate(strm, check)
|
||||
z_streamp strm;
|
||||
int check;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
|
||||
@ -1582,13 +1569,24 @@ int ZEXPORT inflateValidate(z_streamp strm, int check) {
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
long ZEXPORT inflateMark(z_streamp strm) {
|
||||
long ZEXPORT inflateMark(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (inflateStateCheck(strm))
|
||||
return (long)(((unsigned long)0 - 1) << 16);
|
||||
return -(1L << 16);
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
return (long)(((unsigned long)((long)state->back)) << 16) +
|
||||
(state->mode == COPY ? state->length :
|
||||
(state->mode == MATCH ? state->was - state->length : 0));
|
||||
}
|
||||
|
||||
unsigned long ZEXPORT inflateCodesUsed(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
if (inflateStateCheck(strm)) return (unsigned long)-1;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
return (unsigned long)(state->next - state->codes);
|
||||
}
|
||||
|
||||
21
deps/zlib/inftrees.c
vendored
21
deps/zlib/inftrees.c
vendored
@ -1,5 +1,5 @@
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2023 Mark Adler
|
||||
* Copyright (C) 1995-2022 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#define MAXBITS 15
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
|
||||
" inflate 1.2.12 Copyright 1995-2022 Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
@ -29,9 +29,14 @@ const char inflate_copyright[] =
|
||||
table index bits. It will differ if the request is greater than the
|
||||
longest code or if it is less than the shortest code.
|
||||
*/
|
||||
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work) {
|
||||
int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
|
||||
codetype type;
|
||||
unsigned short FAR *lens;
|
||||
unsigned codes;
|
||||
code FAR * FAR *table;
|
||||
unsigned FAR *bits;
|
||||
unsigned short FAR *work;
|
||||
{
|
||||
unsigned len; /* a code's length in bits */
|
||||
unsigned sym; /* index of code symbols */
|
||||
unsigned min, max; /* minimum and maximum code lengths */
|
||||
@ -57,7 +62,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
|
||||
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, 199, 202};
|
||||
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
@ -183,7 +188,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
extra = lext;
|
||||
match = 257;
|
||||
break;
|
||||
case DISTS:
|
||||
default: /* DISTS */
|
||||
base = dbase;
|
||||
extra = dext;
|
||||
match = 0;
|
||||
@ -209,7 +214,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
for (;;) {
|
||||
/* create table entry */
|
||||
here.bits = (unsigned char)(len - drop);
|
||||
if (work[sym] + 1 < match) {
|
||||
if (work[sym] + 1U < match) {
|
||||
here.op = (unsigned char)0;
|
||||
here.val = work[sym];
|
||||
}
|
||||
|
||||
18
deps/zlib/inftrees.h
vendored
18
deps/zlib/inftrees.h
vendored
@ -36,17 +36,17 @@ typedef struct {
|
||||
*/
|
||||
|
||||
/* Maximum size of the dynamic table. The maximum number of code structures is
|
||||
1924, which is the sum of 1332 for literal/length codes and 592 for distance
|
||||
1444, which is the sum of 852 for literal/length codes and 592 for distance
|
||||
codes. These values were found by exhaustive searches using the program
|
||||
examples/enough.c found in the zlib distribution. The arguments to that
|
||||
examples/enough.c found in the zlib distribtution. The arguments to that
|
||||
program are the number of symbols, the initial root table size, and the
|
||||
maximum bit length of a code. "enough 286 10 15" for literal/length codes
|
||||
returns returns 1332, and "enough 30 9 15" for distance codes returns 592.
|
||||
The initial root table size (10 or 9) is found in the fifth argument of the
|
||||
maximum bit length of a code. "enough 286 9 15" for literal/length codes
|
||||
returns returns 852, and "enough 30 6 15" for distance codes returns 592.
|
||||
The initial root table size (9 or 6) is found in the fifth argument of the
|
||||
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
||||
changed, then these maximum sizes would be need to be recalculated and
|
||||
updated. */
|
||||
#define ENOUGH_LENS 1332
|
||||
#define ENOUGH_LENS 852
|
||||
#define ENOUGH_DISTS 592
|
||||
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
|
||||
|
||||
@ -57,6 +57,6 @@ typedef enum {
|
||||
DISTS
|
||||
} codetype;
|
||||
|
||||
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work);
|
||||
int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work));
|
||||
|
||||
505
deps/zlib/trees.c
vendored
505
deps/zlib/trees.c
vendored
@ -38,7 +38,6 @@
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
# include <ctype.h>
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
@ -60,16 +59,16 @@
|
||||
#define REPZ_11_138 18
|
||||
/* repeat a zero length 11-138 times (7 bits of repeat count) */
|
||||
|
||||
static const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
|
||||
local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
|
||||
= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
|
||||
|
||||
static const int extra_dbits[D_CODES] /* extra bits for each distance code */
|
||||
local const int extra_dbits[D_CODES] /* extra bits for each distance code */
|
||||
= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
|
||||
|
||||
static const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
|
||||
local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
|
||||
= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
|
||||
|
||||
static const uint8_t bl_order[BL_CODES]
|
||||
local const uch bl_order[BL_CODES]
|
||||
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
|
||||
/* The lengths of the bit length codes are sent in order of decreasing
|
||||
* probability, to avoid transmitting the lengths for unused bit length codes.
|
||||
@ -84,31 +83,31 @@ static const uint8_t bl_order[BL_CODES]
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
/* non ANSI compilers may not accept trees.h */
|
||||
|
||||
static ct_data static_ltree[L_CODES+2];
|
||||
local ct_data static_ltree[L_CODES+2];
|
||||
/* The static literal tree. Since the bit lengths are imposed, there is no
|
||||
* need for the L_CODES extra codes used during heap construction. However
|
||||
* The codes 286 and 287 are needed to build a canonical tree (see _tr_init
|
||||
* below).
|
||||
*/
|
||||
|
||||
static ct_data static_dtree[D_CODES];
|
||||
local ct_data static_dtree[D_CODES];
|
||||
/* The static distance tree. (Actually a trivial tree since all codes use
|
||||
* 5 bits.)
|
||||
*/
|
||||
|
||||
uint8_t _dist_code[DIST_CODE_LEN];
|
||||
uch _dist_code[DIST_CODE_LEN];
|
||||
/* Distance codes. The first 256 values correspond to the distances
|
||||
* 3 .. 258, the last 256 values correspond to the top 8 bits of
|
||||
* the 15 bit distances.
|
||||
*/
|
||||
|
||||
uint8_t _length_code[MAX_MATCH-MIN_MATCH+1];
|
||||
uch _length_code[MAX_MATCH-MIN_MATCH+1];
|
||||
/* length code for each normalized match length (0 == MIN_MATCH) */
|
||||
|
||||
static int base_length[LENGTH_CODES];
|
||||
local int base_length[LENGTH_CODES];
|
||||
/* First normalized length for each code (0 = MIN_MATCH) */
|
||||
|
||||
static int base_dist[D_CODES];
|
||||
local int base_dist[D_CODES];
|
||||
/* First normalized distance for each code (0 = distance of 1) */
|
||||
|
||||
#else
|
||||
@ -117,47 +116,45 @@ static int base_dist[D_CODES];
|
||||
|
||||
struct static_tree_desc_s {
|
||||
const ct_data *static_tree; /* static tree or NULL */
|
||||
const int *extra_bits; /* extra bits for each code or NULL */
|
||||
const intf *extra_bits; /* extra bits for each code or NULL */
|
||||
int extra_base; /* base index for extra_bits */
|
||||
int elems; /* max number of elements in the tree */
|
||||
int max_length; /* max bit length for the codes */
|
||||
};
|
||||
|
||||
static static_tree_desc static_l_desc =
|
||||
local const static_tree_desc static_l_desc =
|
||||
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
|
||||
|
||||
static static_tree_desc static_d_desc =
|
||||
local const static_tree_desc static_d_desc =
|
||||
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
|
||||
|
||||
static static_tree_desc static_bl_desc =
|
||||
local const static_tree_desc static_bl_desc =
|
||||
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
|
||||
|
||||
/* ===========================================================================
|
||||
* Local (static) routines in this file.
|
||||
*/
|
||||
|
||||
static void tr_static_init (void);
|
||||
static void init_block (deflate_state *s);
|
||||
static void pqdownheap (deflate_state *s, ct_data *tree, int k);
|
||||
static void gen_bitlen (deflate_state *s, tree_desc *desc);
|
||||
static void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count);
|
||||
static void build_tree (deflate_state *s, tree_desc *desc);
|
||||
static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
|
||||
static void send_tree (deflate_state *s, ct_data *tree, int max_code);
|
||||
static int build_bl_tree (deflate_state *s);
|
||||
static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
|
||||
int blcodes);
|
||||
static void compress_block (deflate_state *s, const ct_data *ltree,
|
||||
const ct_data *dtree);
|
||||
static int detect_data_type (deflate_state *s);
|
||||
static unsigned bi_reverse (unsigned value, int length);
|
||||
static void bi_windup (deflate_state *s);
|
||||
static void bi_flush (deflate_state *s);
|
||||
static void copy_block (deflate_state *s, uint8_t *buf, unsigned len,
|
||||
int header);
|
||||
local void tr_static_init OF((void));
|
||||
local void init_block OF((deflate_state *s));
|
||||
local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
|
||||
local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
|
||||
local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
|
||||
local void build_tree OF((deflate_state *s, tree_desc *desc));
|
||||
local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
|
||||
local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
|
||||
local int build_bl_tree OF((deflate_state *s));
|
||||
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
|
||||
int blcodes));
|
||||
local void compress_block OF((deflate_state *s, const ct_data *ltree,
|
||||
const ct_data *dtree));
|
||||
local int detect_data_type OF((deflate_state *s));
|
||||
local unsigned bi_reverse OF((unsigned code, int len));
|
||||
local void bi_windup OF((deflate_state *s));
|
||||
local void bi_flush OF((deflate_state *s));
|
||||
|
||||
#ifdef GEN_TREES_H
|
||||
static void gen_trees_header OF(void);
|
||||
local void gen_trees_header OF((void));
|
||||
#endif
|
||||
|
||||
#ifndef ZLIB_DEBUG
|
||||
@ -171,35 +168,69 @@ static void gen_trees_header OF(void);
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Send a value on a given number of bits.
|
||||
* IN assertion: length <= 64 and value fits in length bits.
|
||||
* Output a short LSB first on the stream.
|
||||
* IN assertion: there is enough room in pendingBuf.
|
||||
*/
|
||||
#define put_short(s, w) { \
|
||||
put_byte(s, (uch)((w) & 0xff)); \
|
||||
put_byte(s, (uch)((ush)(w) >> 8)); \
|
||||
}
|
||||
|
||||
|
||||
static void send_bits(deflate_state* s, uint64_t val, int len)
|
||||
{
|
||||
/* ===========================================================================
|
||||
* Send a value on a given number of bits.
|
||||
* IN assertion: length <= 16 and value fits in length bits.
|
||||
*/
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
local void send_bits OF((deflate_state *s, int value, int length));
|
||||
|
||||
s->bi_buf ^= (val<<s->bi_valid);
|
||||
s->bi_valid += len;
|
||||
if (s->bi_valid >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = s->bi_buf;
|
||||
s->pending += 8;
|
||||
s->bi_valid -= 64;
|
||||
s->bi_buf = val >> (len - s->bi_valid);
|
||||
local void send_bits(s, value, length)
|
||||
deflate_state *s;
|
||||
int value; /* value to send */
|
||||
int length; /* number of bits */
|
||||
{
|
||||
Tracevv((stderr," l %2d v %4x ", length, value));
|
||||
Assert(length > 0 && length <= 15, "invalid length");
|
||||
s->bits_sent += (ulg)length;
|
||||
|
||||
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
|
||||
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
|
||||
* unused bits in value.
|
||||
*/
|
||||
if (s->bi_valid > (int)Buf_size - length) {
|
||||
s->bi_buf |= (ush)value << s->bi_valid;
|
||||
put_short(s, s->bi_buf);
|
||||
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
|
||||
s->bi_valid += length - Buf_size;
|
||||
} else {
|
||||
s->bi_buf |= (ush)value << s->bi_valid;
|
||||
s->bi_valid += length;
|
||||
}
|
||||
}
|
||||
#else /* !ZLIB_DEBUG */
|
||||
|
||||
#define send_bits(s, value, length) \
|
||||
{ int len = length;\
|
||||
if (s->bi_valid > (int)Buf_size - len) {\
|
||||
int val = (int)value;\
|
||||
s->bi_buf |= (ush)val << s->bi_valid;\
|
||||
put_short(s, s->bi_buf);\
|
||||
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
|
||||
s->bi_valid += len - Buf_size;\
|
||||
} else {\
|
||||
s->bi_buf |= (ush)(value) << s->bi_valid;\
|
||||
s->bi_valid += len;\
|
||||
}\
|
||||
}
|
||||
#endif /* ZLIB_DEBUG */
|
||||
|
||||
|
||||
/* the arguments must not have side effects */
|
||||
|
||||
/* ===========================================================================
|
||||
* Initialize the various 'constant' tables.
|
||||
*/
|
||||
static void tr_static_init(void) {
|
||||
local void tr_static_init()
|
||||
{
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
static int static_init_done = 0;
|
||||
int n; /* iterates over tree elements */
|
||||
@ -207,7 +238,7 @@ static void tr_static_init(void) {
|
||||
int length; /* length value */
|
||||
int code; /* code value */
|
||||
int dist; /* distance index */
|
||||
uint16_t bl_count[MAX_BITS+1];
|
||||
ush bl_count[MAX_BITS+1];
|
||||
/* number of codes at each bit length for an optimal tree */
|
||||
|
||||
if (static_init_done) return;
|
||||
@ -226,7 +257,7 @@ static void tr_static_init(void) {
|
||||
for (code = 0; code < LENGTH_CODES-1; code++) {
|
||||
base_length[code] = length;
|
||||
for (n = 0; n < (1<<extra_lbits[code]); n++) {
|
||||
_length_code[length++] = (uint8_t)code;
|
||||
_length_code[length++] = (uch)code;
|
||||
}
|
||||
}
|
||||
Assert (length == 256, "tr_static_init: length != 256");
|
||||
@ -234,14 +265,14 @@ static void tr_static_init(void) {
|
||||
* in two different ways: code 284 + 5 bits or code 285, so we
|
||||
* overwrite length_code[255] to use the best encoding:
|
||||
*/
|
||||
_length_code[length-1] = (uint8_t)code;
|
||||
_length_code[length-1] = (uch)code;
|
||||
|
||||
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
|
||||
dist = 0;
|
||||
for (code = 0 ; code < 16; code++) {
|
||||
base_dist[code] = dist;
|
||||
for (n = 0; n < (1<<extra_dbits[code]); n++) {
|
||||
_dist_code[dist++] = (uint8_t)code;
|
||||
_dist_code[dist++] = (uch)code;
|
||||
}
|
||||
}
|
||||
Assert (dist == 256, "tr_static_init: dist != 256");
|
||||
@ -249,7 +280,7 @@ static void tr_static_init(void) {
|
||||
for ( ; code < D_CODES; code++) {
|
||||
base_dist[code] = dist << 7;
|
||||
for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
|
||||
_dist_code[256 + dist++] = (uint8_t)code;
|
||||
_dist_code[256 + dist++] = (uch)code;
|
||||
}
|
||||
}
|
||||
Assert (dist == 256, "tr_static_init: 256+dist != 512");
|
||||
@ -292,7 +323,8 @@ static void tr_static_init(void) {
|
||||
((i) == (last)? "\n};\n\n" : \
|
||||
((i) % (width) == (width)-1 ? ",\n" : ", "))
|
||||
|
||||
void gen_trees_header(void) {
|
||||
void gen_trees_header()
|
||||
{
|
||||
FILE *header = fopen("trees.h", "w");
|
||||
int i;
|
||||
|
||||
@ -300,38 +332,38 @@ void gen_trees_header(void) {
|
||||
fprintf(header,
|
||||
"/* header created automatically with -DGEN_TREES_H */\n\n");
|
||||
|
||||
fprintf(header, "static const ct_data static_ltree[L_CODES+2] = {\n");
|
||||
fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
|
||||
for (i = 0; i < L_CODES+2; i++) {
|
||||
fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
|
||||
static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
|
||||
}
|
||||
|
||||
fprintf(header, "static const ct_data static_dtree[D_CODES] = {\n");
|
||||
fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
|
||||
for (i = 0; i < D_CODES; i++) {
|
||||
fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
|
||||
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
|
||||
}
|
||||
|
||||
fprintf(header, "const uint8_t ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
|
||||
fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
|
||||
for (i = 0; i < DIST_CODE_LEN; i++) {
|
||||
fprintf(header, "%2u%s", _dist_code[i],
|
||||
SEPARATOR(i, DIST_CODE_LEN-1, 20));
|
||||
}
|
||||
|
||||
fprintf(header,
|
||||
"const uint8_t ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
|
||||
"const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
|
||||
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
|
||||
fprintf(header, "%2u%s", _length_code[i],
|
||||
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
|
||||
}
|
||||
|
||||
fprintf(header, "static const int base_length[LENGTH_CODES] = {\n");
|
||||
fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
|
||||
for (i = 0; i < LENGTH_CODES; i++) {
|
||||
fprintf(header, "%1u%s", base_length[i],
|
||||
SEPARATOR(i, LENGTH_CODES-1, 20));
|
||||
}
|
||||
|
||||
fprintf(header, "static const int base_dist[D_CODES] = {\n");
|
||||
fprintf(header, "local const int base_dist[D_CODES] = {\n");
|
||||
for (i = 0; i < D_CODES; i++) {
|
||||
fprintf(header, "%5u%s", base_dist[i],
|
||||
SEPARATOR(i, D_CODES-1, 10));
|
||||
@ -344,7 +376,9 @@ void gen_trees_header(void) {
|
||||
/* ===========================================================================
|
||||
* Initialize the tree data structures for a new zlib stream.
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_init(deflate_state *s) {
|
||||
void ZLIB_INTERNAL _tr_init(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
tr_static_init();
|
||||
|
||||
s->l_desc.dyn_tree = s->dyn_ltree;
|
||||
@ -370,7 +404,8 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
|
||||
/* ===========================================================================
|
||||
* Initialize a new block.
|
||||
*/
|
||||
static void init_block(deflate_state *s)
|
||||
local void init_block(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
int n; /* iterates over tree elements */
|
||||
|
||||
@ -413,7 +448,11 @@ static void init_block(deflate_state *s)
|
||||
* when the heap property is re-established (each father smaller than its
|
||||
* two sons).
|
||||
*/
|
||||
static void pqdownheap(deflate_state *s, ct_data *tree, int k) {
|
||||
local void pqdownheap(s, tree, k)
|
||||
deflate_state *s;
|
||||
ct_data *tree; /* the tree to restore */
|
||||
int k; /* node to move down */
|
||||
{
|
||||
int v = s->heap[k];
|
||||
int j = k << 1; /* left son of k */
|
||||
while (j <= s->heap_len) {
|
||||
@ -444,7 +483,10 @@ static void pqdownheap(deflate_state *s, ct_data *tree, int k) {
|
||||
* The length opt_len is updated; static_len is also updated if stree is
|
||||
* not null.
|
||||
*/
|
||||
static void gen_bitlen(deflate_state *s, tree_desc *desc) {
|
||||
local void gen_bitlen(s, desc)
|
||||
deflate_state *s;
|
||||
tree_desc *desc; /* the tree descriptor */
|
||||
{
|
||||
ct_data *tree = desc->dyn_tree;
|
||||
int max_code = desc->max_code;
|
||||
const ct_data *stree = desc->stat_desc->static_tree;
|
||||
@ -455,7 +497,7 @@ static void gen_bitlen(deflate_state *s, tree_desc *desc) {
|
||||
int n, m; /* iterate over the tree elements */
|
||||
int bits; /* bit length */
|
||||
int xbits; /* extra bits */
|
||||
uint16_t f; /* frequency */
|
||||
ush f; /* frequency */
|
||||
int overflow = 0; /* number of elements with bit length too large */
|
||||
|
||||
for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
|
||||
@ -469,7 +511,7 @@ static void gen_bitlen(deflate_state *s, tree_desc *desc) {
|
||||
n = s->heap[h];
|
||||
bits = tree[tree[n].Dad].Len + 1;
|
||||
if (bits > max_length) bits = max_length, overflow++;
|
||||
tree[n].Len = (uint16_t)bits;
|
||||
tree[n].Len = (ush)bits;
|
||||
/* We overwrite tree[n].Dad which is no longer needed */
|
||||
|
||||
if (n > max_code) continue; /* not a leaf node */
|
||||
@ -478,12 +520,12 @@ static void gen_bitlen(deflate_state *s, tree_desc *desc) {
|
||||
xbits = 0;
|
||||
if (n >= base) xbits = extra[n-base];
|
||||
f = tree[n].Freq;
|
||||
s->opt_len += (ulg)f * (bits + xbits);
|
||||
if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
|
||||
s->opt_len += (ulg)f * (unsigned)(bits + xbits);
|
||||
if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits);
|
||||
}
|
||||
if (overflow == 0) return;
|
||||
|
||||
Trace((stderr,"\nbit length overflow\n"));
|
||||
Tracev((stderr,"\nbit length overflow\n"));
|
||||
/* This happens for example on obj2 and pic of the Calgary corpus */
|
||||
|
||||
/* Find the first bit length which could increase: */
|
||||
@ -510,10 +552,9 @@ static void gen_bitlen(deflate_state *s, tree_desc *desc) {
|
||||
m = s->heap[--h];
|
||||
if (m > max_code) continue;
|
||||
if ((unsigned) tree[m].Len != (unsigned) bits) {
|
||||
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
|
||||
s->opt_len += ((long)bits - (long)tree[m].Len)
|
||||
*(long)tree[m].Freq;
|
||||
tree[m].Len = (uint16_t)bits;
|
||||
Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
|
||||
s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
|
||||
tree[m].Len = (ush)bits;
|
||||
}
|
||||
n--;
|
||||
}
|
||||
@ -528,10 +569,13 @@ static void gen_bitlen(deflate_state *s, tree_desc *desc) {
|
||||
* OUT assertion: the field code is set for all tree elements of non
|
||||
* zero code length.
|
||||
*/
|
||||
static void gen_codes (ct_data *tree, /* the tree to decorate */ int max_code, /* largest code with non zero frequency */ uint16_t *bl_count) /* number of codes at each bit length */
|
||||
local void gen_codes (tree, max_code, bl_count)
|
||||
ct_data *tree; /* the tree to decorate */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
ushf *bl_count; /* number of codes at each bit length */
|
||||
{
|
||||
uint16_t next_code[MAX_BITS+1]; /* next code value for each bit length */
|
||||
uint16_t code = 0; /* running code value */
|
||||
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
|
||||
unsigned code = 0; /* running code value */
|
||||
int bits; /* bit index */
|
||||
int n; /* code index */
|
||||
|
||||
@ -539,7 +583,8 @@ static void gen_codes (ct_data *tree, /* the tree to decorate */ int max_code, /
|
||||
* without bit reversal.
|
||||
*/
|
||||
for (bits = 1; bits <= MAX_BITS; bits++) {
|
||||
next_code[bits] = code = (code + bl_count[bits-1]) << 1;
|
||||
code = (code + bl_count[bits-1]) << 1;
|
||||
next_code[bits] = (ush)code;
|
||||
}
|
||||
/* Check that the bit counts in bl_count are consistent. The last code
|
||||
* must be all ones.
|
||||
@ -552,7 +597,7 @@ static void gen_codes (ct_data *tree, /* the tree to decorate */ int max_code, /
|
||||
int len = tree[n].Len;
|
||||
if (len == 0) continue;
|
||||
/* Now reverse the bits */
|
||||
tree[n].Code = bi_reverse(next_code[len]++, len);
|
||||
tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
|
||||
|
||||
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
|
||||
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
|
||||
@ -567,7 +612,10 @@ static void gen_codes (ct_data *tree, /* the tree to decorate */ int max_code, /
|
||||
* and corresponding code. The length opt_len is updated; static_len is
|
||||
* also updated if stree is not null. The field max_code is set.
|
||||
*/
|
||||
static void build_tree(deflate_state *s, tree_desc *desc) {
|
||||
local void build_tree(s, desc)
|
||||
deflate_state *s;
|
||||
tree_desc *desc; /* the tree descriptor */
|
||||
{
|
||||
ct_data *tree = desc->dyn_tree;
|
||||
const ct_data *stree = desc->stat_desc->static_tree;
|
||||
int elems = desc->stat_desc->elems;
|
||||
@ -622,9 +670,9 @@ static void build_tree(deflate_state *s, tree_desc *desc) {
|
||||
|
||||
/* Create a new node father of n and m */
|
||||
tree[node].Freq = tree[n].Freq + tree[m].Freq;
|
||||
s->depth[node] = (uint8_t)((s->depth[n] >= s->depth[m] ?
|
||||
s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
|
||||
s->depth[n] : s->depth[m]) + 1);
|
||||
tree[n].Dad = tree[m].Dad = (uint16_t)node;
|
||||
tree[n].Dad = tree[m].Dad = (ush)node;
|
||||
#ifdef DUMP_BL_TREE
|
||||
if (tree == s->bl_tree) {
|
||||
fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
|
||||
@ -652,7 +700,11 @@ static void build_tree(deflate_state *s, tree_desc *desc) {
|
||||
* Scan a literal or distance tree to determine the frequencies of the codes
|
||||
* in the bit length tree.
|
||||
*/
|
||||
static void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
|
||||
local void scan_tree (s, tree, max_code)
|
||||
deflate_state *s;
|
||||
ct_data *tree; /* the tree to be scanned */
|
||||
int max_code; /* and its largest code of non zero frequency */
|
||||
{
|
||||
int n; /* iterates over all tree elements */
|
||||
int prevlen = -1; /* last emitted length */
|
||||
int curlen; /* length of current code */
|
||||
@ -662,7 +714,7 @@ static void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
|
||||
int min_count = 4; /* min repeat count */
|
||||
|
||||
if (nextlen == 0) max_count = 138, min_count = 3;
|
||||
tree[max_code+1].Len = (uint16_t)0xffff; /* guard */
|
||||
tree[max_code+1].Len = (ush)0xffff; /* guard */
|
||||
|
||||
for (n = 0; n <= max_code; n++) {
|
||||
curlen = nextlen; nextlen = tree[n+1].Len;
|
||||
@ -693,7 +745,11 @@ static void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
|
||||
* Send a literal or distance tree in compressed form, using the codes in
|
||||
* bl_tree.
|
||||
*/
|
||||
static void send_tree(deflate_state *s, ct_data *tree, int max_code) {
|
||||
local void send_tree (s, tree, max_code)
|
||||
deflate_state *s;
|
||||
ct_data *tree; /* the tree to be scanned */
|
||||
int max_code; /* and its largest code of non zero frequency */
|
||||
{
|
||||
int n; /* iterates over all tree elements */
|
||||
int prevlen = -1; /* last emitted length */
|
||||
int curlen; /* length of current code */
|
||||
@ -740,7 +796,9 @@ static void send_tree(deflate_state *s, ct_data *tree, int max_code) {
|
||||
* Construct the Huffman tree for the bit lengths and return the index in
|
||||
* bl_order of the last bit length code to send.
|
||||
*/
|
||||
static int build_bl_tree(deflate_state *s) {
|
||||
local int build_bl_tree(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
int max_blindex; /* index of last bit length code of non zero freq */
|
||||
|
||||
/* Determine the bit length frequencies for literal and distance trees */
|
||||
@ -761,8 +819,8 @@ static int build_bl_tree(deflate_state *s) {
|
||||
if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
|
||||
}
|
||||
/* Update opt_len to include the bit length tree and counts */
|
||||
s->opt_len += 3*(max_blindex+1) + 5+5+4;
|
||||
Tracev((stderr, "\ndyn trees: dyn %" PRId64 ", stat %" PRId64,
|
||||
s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4;
|
||||
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
|
||||
s->opt_len, s->static_len));
|
||||
|
||||
return max_blindex;
|
||||
@ -773,8 +831,10 @@ static int build_bl_tree(deflate_state *s) {
|
||||
* lengths of the bit length codes, the literal tree and the distance tree.
|
||||
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
|
||||
*/
|
||||
static void send_all_trees(deflate_state *s, int lcodes, int dcodes,
|
||||
int blcodes) {
|
||||
local void send_all_trees(s, lcodes, dcodes, blcodes)
|
||||
deflate_state *s;
|
||||
int lcodes, dcodes, blcodes; /* number of codes for each tree */
|
||||
{
|
||||
int rank; /* index in bl_order */
|
||||
|
||||
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
|
||||
@ -788,32 +848,45 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes,
|
||||
Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
|
||||
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
|
||||
}
|
||||
Tracev((stderr, "\nbl tree: sent %" PRId64, s->bits_sent));
|
||||
Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
|
||||
|
||||
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
|
||||
Tracev((stderr, "\nlit tree: sent %" PRId64, s->bits_sent));
|
||||
Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
|
||||
|
||||
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
|
||||
Tracev((stderr, "\ndist tree: sent %" PRId64, s->bits_sent));
|
||||
Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Send a stored block
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, uint8_t *buf, /* input block */ uint64_t stored_len, /* length of input block */ int last) /* one if this is the last block for a file */
|
||||
void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
|
||||
deflate_state *s;
|
||||
charf *buf; /* input block */
|
||||
ulg stored_len; /* length of input block */
|
||||
int last; /* one if this is the last block for a file */
|
||||
{
|
||||
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
|
||||
bi_windup(s); /* align on byte boundary */
|
||||
put_short(s, (ush)stored_len);
|
||||
put_short(s, (ush)~stored_len);
|
||||
if (stored_len)
|
||||
zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
|
||||
s->pending += stored_len;
|
||||
#ifdef ZLIB_DEBUG
|
||||
s->compressed_len = (s->compressed_len + 3 + 7) & (uint64_t)~7L;
|
||||
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
|
||||
s->compressed_len += (stored_len + 4) << 3;
|
||||
s->bits_sent += 2*16;
|
||||
s->bits_sent += stored_len<<3;
|
||||
#endif
|
||||
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
|
||||
void ZLIB_INTERNAL _tr_flush_bits(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
bi_flush(s);
|
||||
}
|
||||
|
||||
@ -821,7 +894,8 @@ void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
|
||||
* Send one empty static block to give enough lookahead for inflate.
|
||||
* This takes 10 bits, of which 7 may remain in the bit buffer.
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_align(deflate_state *s)
|
||||
void ZLIB_INTERNAL _tr_align(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
send_bits(s, STATIC_TREES<<1, 3);
|
||||
send_code(s, END_BLOCK, static_ltree);
|
||||
@ -833,11 +907,15 @@ void ZLIB_INTERNAL _tr_align(deflate_state *s)
|
||||
|
||||
/* ===========================================================================
|
||||
* Determine the best encoding for the current block: dynamic trees, static
|
||||
* trees or store, and output the encoded block to the zip file.
|
||||
* trees or store, and write out the encoded block.
|
||||
*/
|
||||
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input block, or NULL if too old */ uint64_t stored_len, /* length of input block */ int last) /* one if this is the last block for a file */
|
||||
void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
||||
deflate_state *s;
|
||||
charf *buf; /* input block, or NULL if too old */
|
||||
ulg stored_len; /* length of input block */
|
||||
int last; /* one if this is the last block for a file */
|
||||
{
|
||||
uint64_t opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||
int max_blindex = 0; /* index of last bit length code of non zero freq */
|
||||
|
||||
/* Build the Huffman trees unless a stored block is forced */
|
||||
@ -849,11 +927,11 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input bloc
|
||||
|
||||
/* Construct the literal and distance trees */
|
||||
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
||||
Tracev((stderr, "\nlit data: dyn %" PRId64 ", stat %" PRId64, s->opt_len,
|
||||
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
|
||||
s->static_len));
|
||||
|
||||
build_tree(s, (tree_desc *)(&(s->d_desc)));
|
||||
Tracev((stderr, "\ndist data: dyn %" PRId64 ", stat %" PRId64, s->opt_len,
|
||||
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
|
||||
s->static_len));
|
||||
/* At this point, opt_len and static_len are the total bit lengths of
|
||||
* the compressed block data, excluding the tree representations.
|
||||
@ -868,24 +946,21 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input bloc
|
||||
opt_lenb = (s->opt_len+3+7)>>3;
|
||||
static_lenb = (s->static_len+3+7)>>3;
|
||||
|
||||
Tracev((stderr, "\nopt %" PRIu64 "(%" PRIu64 ") stat %" PRIu64 "(%" PRIu64 ") stored %" PRIu64 " lit %u ",
|
||||
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
|
||||
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
|
||||
s->sym_next / 3));
|
||||
|
||||
#ifndef FORCE_STATIC
|
||||
if (static_lenb <= opt_lenb || s->strategy == Z_FIXED)
|
||||
#endif
|
||||
opt_lenb = static_lenb;
|
||||
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
|
||||
|
||||
} else {
|
||||
Assert(buf != (uint8_t*)0, "lost buf");
|
||||
Assert(buf != (char*)0, "lost buf");
|
||||
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
|
||||
}
|
||||
|
||||
#ifdef FORCE_STORED
|
||||
if (buf != NULL) { /* force stored block */
|
||||
if (buf != (char*)0) { /* force stored block */
|
||||
#else
|
||||
if (stored_len+4 <= opt_lenb && buf != NULL) {
|
||||
if (stored_len+4 <= opt_lenb && buf != (char*)0) {
|
||||
/* 4: two words for the lengths */
|
||||
#endif
|
||||
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
|
||||
@ -896,7 +971,11 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input bloc
|
||||
*/
|
||||
_tr_stored_block(s, buf, stored_len, last);
|
||||
|
||||
} else if (static_lenb == opt_lenb) {
|
||||
#ifdef FORCE_STATIC
|
||||
} else if (static_lenb >= 0) { /* force static trees */
|
||||
#else
|
||||
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
|
||||
#endif
|
||||
send_bits(s, (STATIC_TREES<<1)+last, 3);
|
||||
compress_block(s, (const ct_data *)static_ltree,
|
||||
(const ct_data *)static_dtree);
|
||||
@ -914,6 +993,9 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input bloc
|
||||
#endif
|
||||
}
|
||||
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
|
||||
/* The above check is made mod 2^32, for files larger than 512 MB
|
||||
* and uLong implemented on 32 bits.
|
||||
*/
|
||||
init_block(s);
|
||||
|
||||
if (last) {
|
||||
@ -922,7 +1004,7 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input bloc
|
||||
s->compressed_len += 7; /* align on byte boundary */
|
||||
#endif
|
||||
}
|
||||
Tracev((stderr,"\ncomprlen %" PRIu64 "(%" PRIu64 ") ", s->compressed_len>>3,
|
||||
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
|
||||
s->compressed_len-7*last));
|
||||
}
|
||||
|
||||
@ -930,11 +1012,14 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf, /* input bloc
|
||||
* Save the match info and tally the frequency counts. Return true if
|
||||
* the current block must be flushed.
|
||||
*/
|
||||
int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, /* distance of matched string */ unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
|
||||
int ZLIB_INTERNAL _tr_tally (s, dist, lc)
|
||||
deflate_state *s;
|
||||
unsigned dist; /* distance of matched string */
|
||||
unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
|
||||
{
|
||||
s->sym_buf[s->sym_next++] = (uint16_t)dist;
|
||||
s->sym_buf[s->sym_next++] = (uint16_t)dist >> 8;
|
||||
s->sym_buf[s->sym_next++] = (uint8_t)lc;
|
||||
s->sym_buf[s->sym_next++] = dist;
|
||||
s->sym_buf[s->sym_next++] = dist >> 8;
|
||||
s->sym_buf[s->sym_next++] = lc;
|
||||
if (dist == 0) {
|
||||
/* lc is the unmatched char */
|
||||
s->dyn_ltree[lc].Freq++;
|
||||
@ -942,9 +1027,9 @@ int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, /* distance of mat
|
||||
s->matches++;
|
||||
/* Here, lc is the match length - MIN_MATCH */
|
||||
dist--; /* dist = match distance - 1 */
|
||||
Assert((uint16_t)dist < (ush)MAX_DIST(s) &&
|
||||
(uint16_t)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
|
||||
(uint16_t)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
|
||||
Assert((ush)dist < (ush)MAX_DIST(s) &&
|
||||
(ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
|
||||
(ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
|
||||
|
||||
s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
|
||||
s->dyn_dtree[d_code(dist)].Freq++;
|
||||
@ -955,7 +1040,10 @@ int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, /* distance of mat
|
||||
/* ===========================================================================
|
||||
* Send the block data compressed using the given Huffman trees
|
||||
*/
|
||||
static void compress_block(deflate_state *s, const ct_data *ltree, /* literal tree */ const ct_data *dtree) /* distance tree */
|
||||
local void compress_block(s, ltree, dtree)
|
||||
deflate_state *s;
|
||||
const ct_data *ltree; /* literal tree */
|
||||
const ct_data *dtree; /* distance tree */
|
||||
{
|
||||
unsigned dist; /* distance of matched string */
|
||||
int lc; /* match length or unmatched char (if dist == 0) */
|
||||
@ -963,115 +1051,31 @@ static void compress_block(deflate_state *s, const ct_data *ltree, /* literal tr
|
||||
unsigned code; /* the code to send */
|
||||
int extra; /* number of extra bits to send */
|
||||
|
||||
uint64_t bit_buf = s->bi_buf;
|
||||
int filled = s->bi_valid;
|
||||
|
||||
uint64_t val;
|
||||
int len;
|
||||
|
||||
if (s->sym_next != 0) do {
|
||||
dist = s->sym_buf[sx++] & 0xff;
|
||||
dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
|
||||
lc = s->sym_buf[sx++];
|
||||
if (dist == 0) {
|
||||
uint64_t val = ltree[lc].Code;
|
||||
int len = ltree[lc].Len;
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
bit_buf ^= (val << filled);
|
||||
filled += len;
|
||||
|
||||
if(filled >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = bit_buf;
|
||||
s->pending += 8;
|
||||
filled -= 64;
|
||||
bit_buf = val >> (len - filled);
|
||||
}
|
||||
|
||||
send_code(s, lc, ltree); /* send a literal byte */
|
||||
Tracecv(isgraph(lc), (stderr," '%c' ", lc));
|
||||
} else {
|
||||
uint64_t val ;
|
||||
int len ;
|
||||
/* Here, lc is the match length - MIN_MATCH */
|
||||
code = _length_code[lc];
|
||||
|
||||
val = ltree[code+LITERALS+1].Code;
|
||||
len = ltree[code+LITERALS+1].Len;
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
bit_buf ^= (val << filled);
|
||||
filled += len;
|
||||
if(filled >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = bit_buf;
|
||||
s->pending += 8;
|
||||
filled -= 64;
|
||||
bit_buf = val >> (len - filled);
|
||||
}
|
||||
|
||||
send_code(s, code+LITERALS+1, ltree); /* send the length code */
|
||||
extra = extra_lbits[code];
|
||||
if (extra != 0) {
|
||||
lc -= base_length[code];
|
||||
val = lc;
|
||||
len = extra;
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
bit_buf ^= (val << filled);
|
||||
filled += len;
|
||||
|
||||
if(filled >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = bit_buf;
|
||||
s->pending += 8;
|
||||
filled -= 64;
|
||||
bit_buf = val >> (len - filled);
|
||||
}
|
||||
send_bits(s, lc, extra); /* send the extra length bits */
|
||||
}
|
||||
dist--; /* dist is now the match distance - 1 */
|
||||
code = d_code(dist);
|
||||
Assert (code < D_CODES, "bad d_code");
|
||||
val = dtree[code].Code;
|
||||
len = dtree[code].Len;
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
bit_buf ^= (val << filled);
|
||||
filled += len;
|
||||
if(filled >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = bit_buf;
|
||||
s->pending += 8;
|
||||
filled -= 64;
|
||||
bit_buf = val >> (len - filled);
|
||||
}
|
||||
|
||||
send_code(s, code, dtree); /* send the distance code */
|
||||
extra = extra_dbits[code];
|
||||
if (extra != 0) {
|
||||
dist -= base_dist[code];
|
||||
|
||||
val = dist;
|
||||
len = extra;
|
||||
bit_buf ^= (val << filled);
|
||||
filled += len;
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
if(filled >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = bit_buf;
|
||||
s->pending += 8;
|
||||
filled -= 64;
|
||||
bit_buf = val >> (len - filled);
|
||||
}
|
||||
dist -= (unsigned)base_dist[code];
|
||||
send_bits(s, dist, extra); /* send the extra distance bits */
|
||||
}
|
||||
} /* literal or match pair ? */
|
||||
|
||||
@ -1080,26 +1084,7 @@ static void compress_block(deflate_state *s, const ct_data *ltree, /* literal tr
|
||||
|
||||
} while (sx < s->sym_next);
|
||||
|
||||
val = ltree[END_BLOCK].Code;
|
||||
len = ltree[END_BLOCK].Len;
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
|
||||
Assert(len > 0 && len <= 64, "invalid length");
|
||||
s->bits_sent += len;
|
||||
#endif
|
||||
bit_buf ^= (val << filled);
|
||||
filled += len;
|
||||
|
||||
if(filled >= 64) {
|
||||
*(uint64_t*)(&s->pending_buf[s->pending]) = bit_buf;
|
||||
s->pending += 8;
|
||||
filled -= 64;
|
||||
bit_buf = val >> (len - filled);
|
||||
}
|
||||
|
||||
s->bi_buf = bit_buf;
|
||||
s->bi_valid = filled;
|
||||
send_code(s, END_BLOCK, ltree);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@ -1115,7 +1100,8 @@ static void compress_block(deflate_state *s, const ct_data *ltree, /* literal tr
|
||||
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
|
||||
* IN assertion: the fields Freq of dyn_ltree are set.
|
||||
*/
|
||||
static int detect_data_type(deflate_state *s)
|
||||
local int detect_data_type(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
/* block_mask is the bit mask of block-listed bytes
|
||||
* set bits 0..6, 14..25, and 28..31
|
||||
@ -1148,9 +1134,9 @@ static int detect_data_type(deflate_state *s)
|
||||
* method would use a table)
|
||||
* IN assertion: 1 <= len <= 15
|
||||
*/
|
||||
static unsigned bi_reverse(unsigned code, /* the value to invert */
|
||||
int len) /* its bit length */
|
||||
|
||||
local unsigned bi_reverse(code, len)
|
||||
unsigned code; /* the value to invert */
|
||||
int len; /* its bit length */
|
||||
{
|
||||
register unsigned res = 0;
|
||||
do {
|
||||
@ -1163,14 +1149,14 @@ static unsigned bi_reverse(unsigned code, /* the value to invert */
|
||||
/* ===========================================================================
|
||||
* Flush the bit buffer, keeping at most 7 bits in it.
|
||||
*/
|
||||
static void bi_flush(deflate_state *s)
|
||||
local void bi_flush(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
while (s->bi_valid >= 16) {
|
||||
if (s->bi_valid == 16) {
|
||||
put_short(s, s->bi_buf);
|
||||
s->bi_buf >>= 16;
|
||||
s->bi_valid -= 16;
|
||||
}
|
||||
if (s->bi_valid >= 8) {
|
||||
s->bi_buf = 0;
|
||||
s->bi_valid = 0;
|
||||
} else if (s->bi_valid >= 8) {
|
||||
put_byte(s, (Byte)s->bi_buf);
|
||||
s->bi_buf >>= 8;
|
||||
s->bi_valid -= 8;
|
||||
@ -1180,13 +1166,9 @@ static void bi_flush(deflate_state *s)
|
||||
/* ===========================================================================
|
||||
* Flush the bit buffer and align the output on a byte boundary
|
||||
*/
|
||||
static void bi_windup(deflate_state *s)
|
||||
local void bi_windup(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
while (s->bi_valid >= 16) {
|
||||
put_short(s, s->bi_buf);
|
||||
s->bi_buf >>= 16;
|
||||
s->bi_valid -= 16;
|
||||
}
|
||||
if (s->bi_valid > 8) {
|
||||
put_short(s, s->bi_buf);
|
||||
} else if (s->bi_valid > 0) {
|
||||
@ -1198,26 +1180,3 @@ static void bi_windup(deflate_state *s)
|
||||
s->bits_sent = (s->bits_sent+7) & ~7;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Copy a stored block, storing first the length and its
|
||||
* one's complement if requested.
|
||||
*/
|
||||
static void copy_block(deflate_state *s, uint8_t *buf, /* the input data */ unsigned len, /* its length */ int header) /* true if block header must be written */
|
||||
{
|
||||
bi_windup(s); /* align on byte boundary */
|
||||
|
||||
if (header) {
|
||||
put_short(s, (uint16_t)len);
|
||||
put_short(s, (uint16_t)~len);
|
||||
#ifdef ZLIB_DEBUG
|
||||
s->bits_sent += 2*16;
|
||||
#endif
|
||||
}
|
||||
#ifdef ZLIB_DEBUG
|
||||
s->bits_sent += (ulg)len<<3;
|
||||
#endif
|
||||
while (len--) {
|
||||
put_byte(s, *buf++);
|
||||
}
|
||||
}
|
||||
|
||||
16
deps/zlib/uncompr.c
vendored
16
deps/zlib/uncompr.c
vendored
@ -24,8 +24,12 @@
|
||||
Z_DATA_ERROR if the input data was corrupted, including if the input data is
|
||||
an incomplete zlib stream.
|
||||
*/
|
||||
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong *sourceLen) {
|
||||
int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong *sourceLen;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
const uInt max = (uInt)-1;
|
||||
@ -79,7 +83,11 @@ int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
err;
|
||||
}
|
||||
|
||||
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong sourceLen) {
|
||||
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
return uncompress2(dest, destLen, source, &sourceLen);
|
||||
}
|
||||
|
||||
79
deps/zlib/zconf.h
vendored
79
deps/zlib/zconf.h
vendored
@ -7,7 +7,7 @@
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
@ -29,6 +29,7 @@
|
||||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# define adler32_z z_adler32_z
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
@ -37,10 +38,14 @@
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
# define crc32_z z_crc32_z
|
||||
# define deflate z_deflate
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define deflateGetDictionary z_deflateGetDictionary
|
||||
# define deflateInit z_deflateInit
|
||||
# define deflateInit2 z_deflateInit2
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
@ -67,6 +72,8 @@
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzfread z_gzfread
|
||||
# define gzfwrite z_gzfwrite
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
@ -78,7 +85,6 @@
|
||||
# define gzopen_w z_gzopen_w
|
||||
# endif
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzvprintf z_gzvprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
@ -89,32 +95,39 @@
|
||||
# define gztell z_gztell
|
||||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzvprintf z_gzvprintf
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define inflateBackInit z_inflateBackInit
|
||||
# define inflateBackInit_ z_inflateBackInit_
|
||||
# define inflateCodesUsed z_inflateCodesUsed
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define inflateGetDictionary z_inflateGetDictionary
|
||||
# define inflateGetHeader z_inflateGetHeader
|
||||
# define inflateInit z_inflateInit
|
||||
# define inflateInit2 z_inflateInit2
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflateMark z_inflateMark
|
||||
# define inflatePrime z_inflatePrime
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# define inflateResetKeep z_inflateResetKeep
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateGetDictionary z_inflateGetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateUndermine z_inflateUndermine
|
||||
# define inflateResetKeep z_inflateResetKeep
|
||||
# define inflateValidate z_inflateValidate
|
||||
# define inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# define uncompress2 z_uncompress2
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# ifndef Z_SOLO
|
||||
@ -224,24 +237,19 @@
|
||||
# define z_const
|
||||
#endif
|
||||
|
||||
#ifndef Z_SOLO
|
||||
# ifdef NO_SIZE_T
|
||||
#ifdef Z_SOLO
|
||||
typedef unsigned long z_size_t;
|
||||
#else
|
||||
# define z_longlong long long
|
||||
# if defined(NO_SIZE_T)
|
||||
typedef unsigned NO_SIZE_T z_size_t;
|
||||
# else
|
||||
# elif defined(STDC)
|
||||
# include <stddef.h>
|
||||
typedef size_t z_size_t;
|
||||
# endif
|
||||
# ifdef NO_SSIZE_T
|
||||
typedef NO_SSIZE_T z_ssize_t;
|
||||
# else
|
||||
# include <stddef.h>
|
||||
# include <sys/types.h>
|
||||
# ifdef _MSC_VER
|
||||
typedef intptr_t z_ssize_t;
|
||||
# else
|
||||
typedef ssize_t z_ssize_t;
|
||||
# endif
|
||||
typedef unsigned long z_size_t;
|
||||
# endif
|
||||
# undef z_longlong
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
@ -271,10 +279,28 @@
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_ARG /* function prototypes for stdarg */
|
||||
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# define Z_ARG(args) args
|
||||
# else
|
||||
# define Z_ARG(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
@ -323,9 +349,6 @@
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
@ -365,10 +388,10 @@
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef uint8_t Byte; /* 8 bits */
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef uint32_t uInt; /* 32 bits */
|
||||
typedef uint64_t uLong; /* 64 bits */
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
@ -449,11 +472,7 @@ typedef uLong FAR uLongf;
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# ifdef _WIN32 /* _MSC_VER doesn't work for some reason when building dll*/
|
||||
# include <io.h>
|
||||
# else
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# endif
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
@ -488,7 +507,7 @@ typedef uLong FAR uLongf;
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(_WIN32) && !defined(__GNUC__)
|
||||
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
|
||||
513
deps/zlib/zlib.h
vendored
513
deps/zlib/zlib.h
vendored
File diff suppressed because it is too large
Load Diff
94
deps/zlib/zutil.c
vendored
94
deps/zlib/zutil.c
vendored
@ -11,23 +11,26 @@
|
||||
#endif
|
||||
|
||||
z_const char * const z_errmsg[10] = {
|
||||
"need dictionary", /* Z_NEED_DICT 2 */
|
||||
"stream end", /* Z_STREAM_END 1 */
|
||||
"", /* Z_OK 0 */
|
||||
"file error", /* Z_ERRNO (-1) */
|
||||
"stream error", /* Z_STREAM_ERROR (-2) */
|
||||
"data error", /* Z_DATA_ERROR (-3) */
|
||||
"insufficient memory", /* Z_MEM_ERROR (-4) */
|
||||
"buffer error", /* Z_BUF_ERROR (-5) */
|
||||
"incompatible version",/* Z_VERSION_ERROR (-6) */
|
||||
""};
|
||||
(z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
|
||||
(z_const char *)"stream end", /* Z_STREAM_END 1 */
|
||||
(z_const char *)"", /* Z_OK 0 */
|
||||
(z_const char *)"file error", /* Z_ERRNO (-1) */
|
||||
(z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
|
||||
(z_const char *)"data error", /* Z_DATA_ERROR (-3) */
|
||||
(z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
|
||||
(z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
|
||||
(z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
|
||||
(z_const char *)""
|
||||
};
|
||||
|
||||
|
||||
const char * ZEXPORT zlibVersion(void) {
|
||||
const char * ZEXPORT zlibVersion()
|
||||
{
|
||||
return ZLIB_VERSION;
|
||||
}
|
||||
|
||||
uLong ZEXPORT zlibCompileFlags(void) {
|
||||
uLong ZEXPORT zlibCompileFlags()
|
||||
{
|
||||
uLong flags;
|
||||
|
||||
flags = 0;
|
||||
@ -116,7 +119,9 @@ uLong ZEXPORT zlibCompileFlags(void) {
|
||||
# endif
|
||||
int ZLIB_INTERNAL z_verbose = verbose;
|
||||
|
||||
void ZLIB_INTERNAL z_error(char *m) {
|
||||
void ZLIB_INTERNAL z_error (m)
|
||||
char *m;
|
||||
{
|
||||
fprintf(stderr, "%s\n", m);
|
||||
exit(1);
|
||||
}
|
||||
@ -125,7 +130,9 @@ void ZLIB_INTERNAL z_error(char *m) {
|
||||
/* exported to allow conversion of error code to string for compress() and
|
||||
* uncompress()
|
||||
*/
|
||||
const char * ZEXPORT zError(int err) {
|
||||
const char * ZEXPORT zError(err)
|
||||
int err;
|
||||
{
|
||||
return ERR_MSG(err);
|
||||
}
|
||||
|
||||
@ -139,14 +146,22 @@ const char * ZEXPORT zError(int err) {
|
||||
|
||||
#ifndef HAVE_MEMCPY
|
||||
|
||||
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
|
||||
void ZLIB_INTERNAL zmemcpy(dest, source, len)
|
||||
Bytef* dest;
|
||||
const Bytef* source;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = *source++; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
|
||||
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
|
||||
int ZLIB_INTERNAL zmemcmp(s1, s2, len)
|
||||
const Bytef* s1;
|
||||
const Bytef* s2;
|
||||
uInt len;
|
||||
{
|
||||
uInt j;
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
@ -155,7 +170,10 @@ int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
|
||||
void ZLIB_INTERNAL zmemzero(dest, len)
|
||||
Bytef* dest;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = 0; /* ??? to be unrolled */
|
||||
@ -198,9 +216,11 @@ local ptr_table table[MAX_PTR];
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
voidpf buf = opaque; /* just to make some compilers happy */
|
||||
voidpf buf;
|
||||
ulg bsize = (ulg)items*size;
|
||||
|
||||
(void)opaque;
|
||||
|
||||
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||
* will return a usable pointer which doesn't have to be normalized.
|
||||
*/
|
||||
@ -220,8 +240,12 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
return buf;
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
int n;
|
||||
|
||||
(void)opaque;
|
||||
|
||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||
farfree(ptr);
|
||||
return;
|
||||
@ -237,7 +261,6 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
next_ptr--;
|
||||
return;
|
||||
}
|
||||
ptr = opaque; /* just to make some compilers happy */
|
||||
Assert(0, "zcfree: ptr not found");
|
||||
}
|
||||
|
||||
@ -254,13 +277,15 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
# define _hfree hfree
|
||||
#endif
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
|
||||
{
|
||||
(void)opaque;
|
||||
return _halloc((long)items, size);
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
(void)opaque;
|
||||
_hfree(ptr);
|
||||
}
|
||||
|
||||
@ -272,20 +297,27 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||
|
||||
#ifndef STDC
|
||||
extern voidp malloc(uInt size);
|
||||
extern voidp calloc(uInt items, uInt size);
|
||||
extern void free(voidpf ptr);
|
||||
extern voidp malloc OF((uInt size));
|
||||
extern voidp calloc OF((uInt items, uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
|
||||
if (opaque) items += size - size; /* make compiler happy */
|
||||
voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
|
||||
voidpf opaque;
|
||||
unsigned items;
|
||||
unsigned size;
|
||||
{
|
||||
(void)opaque;
|
||||
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
|
||||
(voidpf)calloc(items, size);
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
void ZLIB_INTERNAL zcfree (opaque, ptr)
|
||||
voidpf opaque;
|
||||
voidpf ptr;
|
||||
{
|
||||
(void)opaque;
|
||||
free(ptr);
|
||||
if (opaque) return; /* make compiler happy */
|
||||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
||||
|
||||
30
deps/zlib/zutil.h
vendored
30
deps/zlib/zutil.h
vendored
@ -20,7 +20,6 @@
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(STDC) && !defined(Z_SOLO)
|
||||
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
|
||||
@ -43,6 +42,17 @@ typedef unsigned short ush;
|
||||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (ULONG_MAX == 0xffffffffffffffff)
|
||||
# define Z_U8 unsigned long
|
||||
# elif (ULLONG_MAX == 0xffffffffffffffff)
|
||||
# define Z_U8 unsigned long long
|
||||
# elif (UINT_MAX == 0xffffffffffffffff)
|
||||
# define Z_U8 unsigned
|
||||
# endif
|
||||
#endif
|
||||
|
||||
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
@ -181,8 +191,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if !defined(_WIN32) && \
|
||||
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
|
||||
#endif
|
||||
|
||||
/* common defaults */
|
||||
@ -221,16 +231,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
#else
|
||||
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
|
||||
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
|
||||
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
|
||||
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
|
||||
#endif
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# include <stdio.h>
|
||||
extern int ZLIB_INTERNAL z_verbose;
|
||||
extern void ZLIB_INTERNAL z_error(char *m);
|
||||
extern void ZLIB_INTERNAL z_error OF((char *m));
|
||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||
@ -247,9 +257,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
#endif
|
||||
|
||||
#ifndef Z_SOLO
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
|
||||
unsigned size);
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
|
||||
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
|
||||
unsigned size));
|
||||
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
|
||||
#endif
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user