chore(Deps/Zlib): move to Cloudflare fork (#21028)

Co-authored-by: Andrew <47818697+Nyeriah@users.noreply.github.com>
This commit is contained in:
Grimdhex
2025-02-06 14:41:31 +01:00
committed by GitHub
parent 1cdc7ce56e
commit 994eccebdf
33 changed files with 4313 additions and 12888 deletions

View File

@@ -44,9 +44,9 @@ utf8-cpp (UTF-8 with C++ in a Portable Way)
http://utfcpp.sourceforge.net/ http://utfcpp.sourceforge.net/
Version: 2.3.4 Version: 2.3.4
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library) zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library - fork of Cloudflare)
http://www.zlib.net/ https://github.com/cloudflare/zlib (based on http://www.zlib.net/)
Version: 1.2.12 Version: 23-12-2024
gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings) gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings)
http://gsoap2.sourceforge.net/ http://gsoap2.sourceforge.net/

View File

@@ -89,7 +89,7 @@ BinaryInput::BinaryInput(
debugAssert(m_freeBuffer); debugAssert(m_freeBuffer);
m_buffer = (uint8*)System::alignedMalloc(m_length, 16); m_buffer = (uint8*)System::alignedMalloc(m_length, 16);
unsigned long L = (unsigned long)m_length; uint64_t L = (uint64_t)m_length;
// Decompress with zlib // Decompress with zlib
int64 result = uncompress(m_buffer, &L, data + 4, (uLong)dataLen - 4); int64 result = uncompress(m_buffer, &L, data + 4, (uLong)dataLen - 4);
m_length = L; m_length = L;
@@ -257,7 +257,7 @@ void BinaryInput::decompress() {
debugAssert(isValidHeapPointer(tempBuffer)); debugAssert(isValidHeapPointer(tempBuffer));
debugAssert(isValidHeapPointer(m_buffer)); debugAssert(isValidHeapPointer(m_buffer));
unsigned long L = (unsigned long)m_length; uint64_t L = (uint64_t)m_length;
int64 result = (int64)uncompress(m_buffer, &L, tempBuffer + 4, (uLong)tempLength - 4); int64 result = (int64)uncompress(m_buffer, &L, tempBuffer + 4, (uLong)tempLength - 4);
m_length = L; m_length = L;
m_bufferLength = m_length; m_bufferLength = m_length;

View File

@@ -281,7 +281,7 @@ void BinaryOutput::compress(int level) {
alwaysAssertM(m_bufferLen < 0xFFFFFFFF, "Compress only works for 32-bit files."); alwaysAssertM(m_bufferLen < 0xFFFFFFFF, "Compress only works for 32-bit files.");
// This is the worst-case size, as mandated by zlib // This is the worst-case size, as mandated by zlib
unsigned long compressedSize = iCeil(m_bufferLen * 1.001) + 12; uint64_t compressedSize = iCeil(m_bufferLen * 1.001) + 12;
// Save the old buffer and reallocate to the worst-case size // Save the old buffer and reallocate to the worst-case size
const uint8* src = m_buffer; const uint8* src = m_buffer;

41
deps/zlib/adler32.c vendored
View File

@@ -7,8 +7,6 @@
#include "zutil.h" #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 BASE 65521U /* largest prime smaller than 65536 */
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@@ -59,15 +57,20 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
# define MOD63(a) a %= BASE # define MOD63(a) a %= BASE
#endif #endif
#if defined(ADLER32_SIMD_NEON) || defined (ADLER32_SIMD_SSSE3)
#include "adler32_simd.h"
#endif
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_z(adler, buf, len) uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
uLong adler;
const Bytef *buf;
z_size_t len;
{
unsigned long sum2; unsigned long sum2;
unsigned n; 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 */ /* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff; sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff; adler &= 0xffff;
@@ -131,20 +134,12 @@ uLong ZEXPORT adler32_z(adler, buf, len)
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len) uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
uLong adler;
const Bytef *buf;
uInt len;
{
return adler32_z(adler, buf, len); return adler32_z(adler, buf, len);
} }
/* ========================================================================= */ /* ========================================================================= */
local uLong adler32_combine_(adler1, adler2, len2) local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
uLong adler1;
uLong adler2;
z_off64_t len2;
{
unsigned long sum1; unsigned long sum1;
unsigned long sum2; unsigned long sum2;
unsigned rem; unsigned rem;
@@ -169,18 +164,10 @@ local uLong adler32_combine_(adler1, adler2, len2)
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2) uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
uLong adler1;
uLong adler2;
z_off_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
uLong ZEXPORT adler32_combine64(adler1, adler2, len2) uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
uLong adler1;
uLong adler2;
z_off64_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }

387
deps/zlib/adler32_simd.c vendored Normal file
View File

@@ -0,0 +1,387 @@
/* 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 Normal file
View File

@@ -0,0 +1,37 @@
/* 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 Normal file
View File

@@ -0,0 +1,558 @@
/* 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
View File

@@ -19,13 +19,8 @@
memory, Z_BUF_ERROR if there was not enough room in the output buffer, memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong sourceLen, int level) {
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1; const uInt max = (uInt)-1;
@@ -65,12 +60,8 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
/* =========================================================================== /* ===========================================================================
*/ */
int ZEXPORT compress (dest, destLen, source, sourceLen) int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong sourceLen) {
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
} }
@@ -78,9 +69,7 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
If the default memLevel or windowBits for deflateInit() is changed, then If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated. this function needs to be updated.
*/ */
uLong ZEXPORT compressBound (sourceLen) uLong ZEXPORT compressBound(uLong sourceLen) {
uLong sourceLen;
{
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13; (sourceLen >> 25) + 13;
} }

1413
deps/zlib/crc32.c vendored

File diff suppressed because it is too large Load Diff

9877
deps/zlib/crc32.h vendored

File diff suppressed because it is too large Load Diff

244
deps/zlib/crc32_simd.c vendored Normal file
View File

@@ -0,0 +1,244 @@
/* 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 Normal file
View File

@@ -0,0 +1,69 @@
//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 */

1626
deps/zlib/deflate.c vendored

File diff suppressed because it is too large Load Diff

202
deps/zlib/deflate.h vendored
View File

@@ -15,14 +15,6 @@
#include "zutil.h" #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. * Internal compression state.
*/ */
@@ -48,33 +40,30 @@
#define MAX_BITS 15 #define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */ /* All codes must not exceed MAX_BITS bits */
#define Buf_size 16 #define Buf_size 64
/* size of bit buffer in bi_buf */ /* size of bit buffer in bi_buf */
#define INIT_STATE 42 /* zlib header -> BUSY_STATE */ #define INIT_STATE 42
#ifdef GZIP #define EXTRA_STATE 69
# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */ #define NAME_STATE 73
#endif #define COMMENT_STATE 91
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */ #define HCRC_STATE 103
#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */ #define BUSY_STATE 113
#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */ #define FINISH_STATE 666
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
#define FINISH_STATE 666 /* stream complete */
/* Stream status */ /* Stream status */
/* Data structure describing a single value and its code string. */ /* Data structure describing a single value and its code string. */
typedef struct ct_data_s { typedef struct ct_data_s {
union { union {
ush freq; /* frequency count */ uint16_t freq; /* frequency count */
ush code; /* bit string */ uint16_t code; /* bit string */
} fc; } fc;
union { union {
ush dad; /* father node in Huffman tree */ uint16_t dad; /* father node in Huffman tree */
ush len; /* length of bit string */ uint16_t len; /* length of bit string */
} dl; } dl;
} FAR ct_data; } ct_data;
#define Freq fc.freq #define Freq fc.freq
#define Code fc.code #define Code fc.code
@@ -86,37 +75,35 @@ typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s { typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */ ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */ int max_code; /* largest code with non zero frequency */
const static_tree_desc *stat_desc; /* the corresponding static tree */ static_tree_desc *stat_desc; /* the corresponding static tree */
} FAR tree_desc; } tree_desc;
typedef ush Pos; typedef uint16_t Pos;
typedef Pos FAR Posf; typedef uint32_t IPos;
typedef unsigned IPos;
/* A Pos is an index in the character window. We use short instead of int to /* 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. * save space in the various tables. IPos is used only for parameter passing.
*/ */
typedef struct internal_state { typedef struct internal_state {
z_streamp strm; /* pointer back to this zlib stream */ z_streamp strm; /* pointer back to this zlib stream */
int status; /* as the name implies */ int status; /* as the name implies */
Bytef *pending_buf; /* output still pending */ uint8_t *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */ uint64_t pending_buf_size; /* size of pending_buf */
Bytef *pending_out; /* next pending byte to output to the stream */ uint8_t *pending_out; /* next pending byte to output to the stream */
ulg pending; /* nb of bytes in the pending buffer */ uint32_t pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */ gz_headerp gzhead; /* gzip header information to write */
ulg gzindex; /* where in extra, name, or comment */ uint32_t gzindex; /* where in extra, name, or comment */
Byte method; /* can only be DEFLATED */ uint8_t method; /* can only be DEFLATED */
int last_flush; /* value of flush param for previous deflate call */ int last_flush; /* value of flush param for previous deflate call */
/* used by deflate.c: */ /* 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 */
uInt w_size; /* LZ77 window size (32K by default) */ uint8_t *window;
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, /* 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 * 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 * bytes. With this organization, matches are limited to a distance of
@@ -126,25 +113,25 @@ typedef struct internal_state {
* To do: use the user input buffer as sliding window. * To do: use the user input buffer as sliding window.
*/ */
ulg window_size; uint32_t window_size;
/* Actual size of window: 2*wSize, except when the user input buffer /* Actual size of window: 2*wSize, except when the user input buffer
* is directly used as sliding window. * is directly used as sliding window.
*/ */
Posf *prev; Pos *prev;
/* Link to older string with same hash index. To limit the size of this /* 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. * 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. * An index in this array is thus a window index modulo 32K.
*/ */
Posf *head; /* Heads of the hash chains or NIL. */ Pos *head; /* Heads of the hash chains or NIL. */
uInt ins_h; /* hash index of string to be inserted */ uint32_t ins_h; /* hash index of string to be inserted */
uInt hash_size; /* number of elements in hash table */ uint32_t hash_size; /* number of elements in hash table */
uInt hash_bits; /* log2(hash_size) */ uint32_t hash_bits; /* log2(hash_size) */
uInt hash_mask; /* hash_size-1 */ uint32_t hash_mask; /* hash_size-1 */
uInt hash_shift; uint32_t hash_shift;
/* Number of bits by which ins_h must be shifted at each input /* 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 * step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is: * byte no longer takes part in the hash key, that is:
@@ -156,25 +143,25 @@ typedef struct internal_state {
* negative when the window is moved backwards. * negative when the window is moved backwards.
*/ */
uInt match_length; /* length of best match */ uint32_t match_length; /* length of best match */
IPos prev_match; /* previous match */ IPos prev_match; /* previous match */
int match_available; /* set if previous match exists */ int match_available; /* set if previous match exists */
uInt strstart; /* start of string to insert */ uint32_t strstart; /* start of string to insert */
uInt match_start; /* start of matching string */ uint32_t match_start; /* start of matching string */
uInt lookahead; /* number of valid bytes ahead in window */ uint32_t lookahead; /* number of valid bytes ahead in window */
uInt prev_length; uint32_t prev_length;
/* Length of the best match at previous step. Matches not greater than this /* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation. * are discarded. This is used in the lazy match evaluation.
*/ */
uInt max_chain_length; uint32_t max_chain_length;
/* To speed up deflation, hash chains are never searched beyond this /* To speed up deflation, hash chains are never searched beyond this
* length. A higher limit improves compression ratio but degrades the * length. A higher limit improves compression ratio but degrades the
* speed. * speed.
*/ */
uInt max_lazy_match; uint32_t max_lazy_match;
/* Attempt to find a better match only when the current match is strictly /* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression * smaller than this value. This mechanism is used only for compression
* levels >= 4. * levels >= 4.
@@ -188,12 +175,12 @@ typedef struct internal_state {
int level; /* compression level (1..9) */ int level; /* compression level (1..9) */
int strategy; /* favor or force Huffman coding*/ int strategy; /* favor or force Huffman coding*/
uInt good_match; uint32_t good_match;
/* Use a faster search when the previous match is longer than this */ /* Use a faster search when the previous match is longer than this */
int nice_match; /* Stop searching when current match exceeds 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 */ /* 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_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
@@ -203,7 +190,7 @@ typedef struct internal_state {
struct tree_desc_s d_desc; /* desc. for distance tree */ struct tree_desc_s d_desc; /* desc. for distance tree */
struct tree_desc_s bl_desc; /* desc. for bit length tree */ struct tree_desc_s bl_desc; /* desc. for bit length tree */
ush bl_count[MAX_BITS+1]; uint16_t bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */ /* number of codes at each bit length for an optimal tree */
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
@@ -213,13 +200,13 @@ typedef struct internal_state {
* The same heap array is used to build all trees. * The same heap array is used to build all trees.
*/ */
uch depth[2*L_CODES+1]; uint8_t depth[2*L_CODES+1];
/* Depth of each subtree used as tie breaker for trees of equal frequency /* Depth of each subtree used as tie breaker for trees of equal frequency
*/ */
uchf *sym_buf; /* buffer for distances and literals/lengths */ uint8_t *sym_buf; /* buffer for distances and literals/lengths */
uInt lit_bufsize; uint32_t lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for /* Size of match buffer for literals/lengths. There are 4 reasons for
* limiting lit_bufsize to 64K: * limiting lit_bufsize to 64K:
* - frequencies can be kept in 16 bit counters * - frequencies can be kept in 16 bit counters
@@ -242,17 +229,17 @@ typedef struct internal_state {
uInt sym_next; /* running index in sym_buf */ uInt sym_next; /* running index in sym_buf */
uInt sym_end; /* symbol table full when sym_next reaches this */ uInt sym_end; /* symbol table full when sym_next reaches this */
ulg opt_len; /* bit length of current block with optimal trees */ uint64_t opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */ uint64_t static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */ uint32_t matches; /* number of string matches in current block */
uInt insert; /* bytes at end of window left to insert */ uint32_t insert; /* bytes at end of window left to insert */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */ uint64_t compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ uint64_t bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif #endif
ush bi_buf; uint64_t bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least /* Output buffer. bits are inserted starting at the bottom (least
* significant bits). * significant bits).
*/ */
@@ -261,20 +248,29 @@ typedef struct internal_state {
* are always zero. * are always zero.
*/ */
ulg high_water; uint64_t high_water;
/* High water mark offset in window for initialized bytes -- bytes above /* High water mark offset in window for initialized bytes -- bytes above
* this are set to zero in order to avoid memory check warnings when * this are set to zero in order to avoid memory check warnings when
* longest match routines access bytes past the input. This is then * longest match routines access bytes past the input. This is then
* updated to the new high water mark. * updated to the new high water mark.
*/ */
} FAR deflate_state; } deflate_state;
/* Output a byte on the stream. /* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf. * IN assertion: there is enough room in pending_buf.
*/ */
#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);} #define put_byte(s, c) {s->pending_buf[s->pending++] = (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) #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file. /* Minimum amount of lookahead, except at the end of the input file.
@@ -291,14 +287,14 @@ typedef struct internal_state {
memory checker errors from longest match routines */ memory checker errors from longest match routines */
/* in trees.c */ /* in trees.c */
void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); void ZLIB_INTERNAL _tr_init(deflate_state *s);
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); int ZLIB_INTERNAL _tr_tally(deflate_state *s, uint32_t dist, unsigned lc);
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, uint8_t *buf,
ulg stored_len, int last)); uint64_t stored_len, int last);
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); void ZLIB_INTERNAL _tr_align(deflate_state *s);
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, uint8_t *buf,
ulg stored_len, int last)); uint64_t stored_len, int last);
#define d_code(dist) \ #define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
@@ -307,16 +303,8 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
* used. * used.
*/ */
#ifndef ZLIB_DEBUG extern const uint8_t ZLIB_INTERNAL _length_code[];
/* Inline versions of _tr_tally for speed: */ extern const uint8_t ZLIB_INTERNAL _dist_code[];
#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) \ # define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \ { uch cc = (c); \
@@ -337,10 +325,24 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
s->dyn_dtree[d_code(dist)].Freq++; \ s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->sym_next == s->sym_end); \ 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 #else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) #define likely(x) __builtin_expect((x),1)
# define _tr_tally_dist(s, distance, length, flush) \ #define unlikely(x) __builtin_expect((x),0)
flush = _tr_tally(s, distance, length)
#endif #endif
#endif /* DEFLATE_H */ #endif /* DEFLATE_H */

4
deps/zlib/gzclose.c vendored
View File

@@ -8,9 +8,7 @@
/* gzclose() is in a separate file so that it is linked in only if it is used. /* 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 That way the other gzclose functions can be used instead to avoid linking in
unneeded compression or decompression routines. */ unneeded compression or decompression routines. */
int ZEXPORT gzclose(file) int ZEXPORT gzclose(gzFile file) {
gzFile file;
{
#ifndef NO_GZCOMPRESS #ifndef NO_GZCOMPRESS
gz_statep state; gz_statep state;

23
deps/zlib/gzguts.h vendored
View File

@@ -7,9 +7,8 @@
# ifndef _LARGEFILE_SOURCE # ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1 # define _LARGEFILE_SOURCE 1
# endif # endif
# ifdef _FILE_OFFSET_BITS # undef _FILE_OFFSET_BITS
# undef _FILE_OFFSET_BITS # undef _TIME_BITS
# endif
#endif #endif
#ifdef HAVE_HIDDEN #ifdef HAVE_HIDDEN
@@ -119,8 +118,8 @@
/* gz* functions always use library allocation functions */ /* gz* functions always use library allocation functions */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
/* get errno and strerror definition */ /* get errno and strerror definition */
@@ -138,10 +137,10 @@
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
#endif #endif
/* default memLevel */ /* default memLevel */
@@ -203,9 +202,9 @@ typedef struct {
typedef gz_state FAR *gz_statep; typedef gz_state FAR *gz_statep;
/* shared functions */ /* shared functions */
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
#if defined UNDER_CE #if defined UNDER_CE
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
#endif #endif
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
@@ -214,6 +213,6 @@ char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
#ifdef INT_MAX #ifdef INT_MAX
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
#else #else
unsigned ZLIB_INTERNAL gz_intmax OF((void)); unsigned ZLIB_INTERNAL gz_intmax(void);
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif #endif

108
deps/zlib/gzlib.c vendored
View File

@@ -16,8 +16,8 @@
#endif #endif
/* Local functions */ /* Local functions */
local void gz_reset OF((gz_statep)); local void gz_reset(gz_statep);
local gzFile gz_open OF((const void *, int, const char *)); local gzFile gz_open(const void *, int, const char *);
#if defined UNDER_CE #if defined UNDER_CE
@@ -30,9 +30,7 @@ local gzFile gz_open OF((const void *, int, const char *));
The gz_strwinerror function does not change the current setting of The gz_strwinerror function does not change the current setting of
GetLastError. */ GetLastError. */
char ZLIB_INTERNAL *gz_strwinerror (error) char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
DWORD error;
{
static char buf[1024]; static char buf[1024];
wchar_t *msgbuf; wchar_t *msgbuf;
@@ -72,9 +70,7 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
#endif /* UNDER_CE */ #endif /* UNDER_CE */
/* Reset gzip file state */ /* Reset gzip file state */
local void gz_reset(state) static void gz_reset(gz_statep state) {
gz_statep state;
{
state->x.have = 0; /* no output data available */ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */ if (state->mode == GZ_READ) { /* for reading ... */
state->eof = 0; /* not at end of file */ state->eof = 0; /* not at end of file */
@@ -90,10 +86,7 @@ local void gz_reset(state)
} }
/* Open a gzip file either by name or file descriptor. */ /* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(path, fd, mode) static gzFile gz_open(const void *path, int fd, const char *mode)
const void *path;
int fd;
const char *mode;
{ {
gz_statep state; gz_statep state;
z_size_t len; z_size_t len;
@@ -190,7 +183,7 @@ local gzFile gz_open(path, fd, mode)
} }
/* save the path name for error messages */ /* save the path name for error messages */
#ifdef WIDECHAR #ifdef _WIN32
if (fd == -2) { if (fd == -2) {
len = wcstombs(NULL, path, 0); len = wcstombs(NULL, path, 0);
if (len == (z_size_t)-1) if (len == (z_size_t)-1)
@@ -204,7 +197,7 @@ local gzFile gz_open(path, fd, mode)
free(state); free(state);
return NULL; return NULL;
} }
#ifdef WIDECHAR #ifdef _WIN32
if (fd == -2) if (fd == -2)
if (len) if (len)
wcstombs(state->path, path, len + 1); wcstombs(state->path, path, len + 1);
@@ -241,7 +234,7 @@ local gzFile gz_open(path, fd, mode)
/* open the file with the appropriate flags (or just use fd) */ /* open the file with the appropriate flags (or just use fd) */
state->fd = fd > -1 ? fd : ( state->fd = fd > -1 ? fd : (
#ifdef WIDECHAR #ifdef _WIN32
fd == -2 ? _wopen(path, oflag, 0666) : fd == -2 ? _wopen(path, oflag, 0666) :
#endif #endif
open((const char *)path, oflag, 0666)); open((const char *)path, oflag, 0666));
@@ -269,26 +262,17 @@ local gzFile gz_open(path, fd, mode)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen(path, mode) gzFile ZEXPORT gzopen(const char *path, const char *mode) {
const char *path;
const char *mode;
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen64(path, mode) gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
const char *path;
const char *mode;
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzdopen(fd, mode) gzFile ZEXPORT gzdopen(int fd, const char *mode) {
int fd;
const char *mode;
{
char *path; /* identifier for error messages */ char *path; /* identifier for error messages */
gzFile gz; gzFile gz;
@@ -305,20 +289,15 @@ gzFile ZEXPORT gzdopen(fd, mode)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
#ifdef WIDECHAR #ifdef _WIN32
gzFile ZEXPORT gzopen_w(path, mode) gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode)
const wchar_t *path;
const char *mode;
{ {
return gz_open(path, -2, mode); return gz_open(path, -2, mode);
} }
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzbuffer(file, size) int ZEXPORT gzbuffer(gzFile file, unsigned size) {
gzFile file;
unsigned size;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -335,16 +314,14 @@ int ZEXPORT gzbuffer(file, size)
/* check and set requested size */ /* check and set requested size */
if ((size << 1) < size) if ((size << 1) < size)
return -1; /* need to be able to double it */ return -1; /* need to be able to double it */
if (size < 2) if (size < 8)
size = 2; /* need two bytes to check magic header */ size = 8; /* needed to behave well with flushing */
state->want = size; state->want = size;
return 0; return 0;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzrewind(file) int ZEXPORT gzrewind(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -365,11 +342,7 @@ int ZEXPORT gzrewind(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzseek64(file, offset, whence) z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
gzFile file;
z_off64_t offset;
int whence;
{
unsigned n; unsigned n;
z_off64_t ret; z_off64_t ret;
gz_statep state; gz_statep state;
@@ -442,11 +415,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzseek(file, offset, whence) z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
gzFile file;
z_off_t offset;
int whence;
{
z_off64_t ret; z_off64_t ret;
ret = gzseek64(file, (z_off64_t)offset, whence); ret = gzseek64(file, (z_off64_t)offset, whence);
@@ -454,9 +423,7 @@ z_off_t ZEXPORT gzseek(file, offset, whence)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gztell64(file) z_off64_t ZEXPORT gztell64(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -471,9 +438,7 @@ z_off64_t ZEXPORT gztell64(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gztell(file) z_off_t ZEXPORT gztell(gzFile file) {
gzFile file;
{
z_off64_t ret; z_off64_t ret;
ret = gztell64(file); ret = gztell64(file);
@@ -481,9 +446,7 @@ z_off_t ZEXPORT gztell(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzoffset64(file) z_off64_t ZEXPORT gzoffset64(gzFile file) {
gzFile file;
{
z_off64_t offset; z_off64_t offset;
gz_statep state; gz_statep state;
@@ -504,9 +467,7 @@ z_off64_t ZEXPORT gzoffset64(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzoffset(file) z_off_t ZEXPORT gzoffset(gzFile file) {
gzFile file;
{
z_off64_t ret; z_off64_t ret;
ret = gzoffset64(file); ret = gzoffset64(file);
@@ -514,9 +475,7 @@ z_off_t ZEXPORT gzoffset(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzeof(file) int ZEXPORT gzeof(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -531,10 +490,7 @@ int ZEXPORT gzeof(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
const char * ZEXPORT gzerror(file, errnum) const char * ZEXPORT gzerror(gzFile file, int *errnum) {
gzFile file;
int *errnum;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -552,9 +508,7 @@ const char * ZEXPORT gzerror(file, errnum)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
void ZEXPORT gzclearerr(file) void ZEXPORT gzclearerr(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@@ -578,11 +532,7 @@ void ZEXPORT gzclearerr(file)
memory). Simply save the error message as a static string. If there is an 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 allocation failure constructing the error message, then convert the error to
out of memory. */ out of memory. */
void ZLIB_INTERNAL gz_error(state, err, msg) void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
gz_statep state;
int err;
const char *msg;
{
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL) {
if (state->err != Z_MEM_ERROR) if (state->err != Z_MEM_ERROR)
@@ -617,6 +567,7 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
strcat(state->msg, ": "); strcat(state->msg, ": ");
strcat(state->msg, msg); strcat(state->msg, msg);
#endif #endif
return;
} }
#ifndef INT_MAX #ifndef INT_MAX
@@ -624,8 +575,7 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
available) -- we need to do this to cover cases where 2's complement not 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, used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */ otherwise we could just use ((unsigned)-1) >> 1 */
unsigned ZLIB_INTERNAL gz_intmax() unsigned ZLIB_INTERNAL gz_intmax(void) {
{
unsigned p, q; unsigned p, q;
p = 1; p = 1;

231
deps/zlib/gzread.c vendored
View File

@@ -6,36 +6,27 @@
#include "gzguts.h" #include "gzguts.h"
/* Local functions */ /* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); local int gz_load(gz_statep, unsigned char *, unsigned, unsigned *);
local int gz_avail OF((gz_statep)); local int gz_avail(gz_statep);
local int gz_look OF((gz_statep)); local int gz_look(gz_statep);
local int gz_decomp OF((gz_statep)); local int gz_decomp(gz_statep);
local int gz_fetch OF((gz_statep)); local int gz_fetch(gz_statep);
local int gz_skip OF((gz_statep, z_off64_t)); local int gz_skip(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 /* 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. 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 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. */ read the number of bytes requested, depending on the type of descriptor. */
local int gz_load(state, buf, len, have) static int gz_load(gz_statep state, unsigned char *buf, unsigned len,
gz_statep state; unsigned *have) {
unsigned char *buf; z_ssize_t ret;
unsigned len;
unsigned *have;
{
int ret;
unsigned get, max = ((unsigned)-1 >> 2) + 1;
*have = 0; *have = 0;
do { do {
get = len - *have; ret = read(state->fd, buf + *have, len - *have);
if (get > max)
get = max;
ret = read(state->fd, buf + *have, get);
if (ret <= 0) if (ret <= 0)
break; break;
*have += (unsigned)ret; *have += ret;
} while (*have < len); } while (*have < len);
if (ret < 0) { if (ret < 0) {
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
@@ -53,9 +44,7 @@ local int gz_load(state, buf, len, have)
If strm->avail_in != 0, then the current data is moved to the beginning of 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 the input buffer, and then the remainder of the buffer is loaded with the
available data from the input file. */ available data from the input file. */
local int gz_avail(state) static int gz_avail(gz_statep state) {
gz_statep state;
{
unsigned got; unsigned got;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -88,9 +77,7 @@ local int gz_avail(state)
case, all further file reads will be directly to either the output buffer or 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. a user buffer. If decompressing, the inflate state will be initialized.
gz_look() will return 0 on success or -1 on failure. */ gz_look() will return 0 on success or -1 on failure. */
local int gz_look(state) static int gz_look(gz_statep state) {
gz_statep state;
{
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate read buffers and inflate memory */ /* allocate read buffers and inflate memory */
@@ -157,11 +144,9 @@ local int gz_look(state)
the output buffer is larger than the input buffer, which also assures the output buffer is larger than the input buffer, which also assures
space for gzungetc() */ space for gzungetc() */
state->x.next = state->out; state->x.next = state->out;
if (strm->avail_in) { memcpy(state->x.next, strm->next_in, strm->avail_in);
memcpy(state->x.next, strm->next_in, strm->avail_in); state->x.have = strm->avail_in;
state->x.have = strm->avail_in; strm->avail_in = 0;
strm->avail_in = 0;
}
state->how = COPY; state->how = COPY;
state->direct = 1; state->direct = 1;
return 0; return 0;
@@ -172,9 +157,7 @@ local int gz_look(state)
data. If the gzip stream completes, state->how is reset to LOOK to look for 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 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
on success, -1 on failure. */ on success, -1 on failure. */
local int gz_decomp(state) static int gz_decomp(gz_statep state) {
gz_statep state;
{
int ret = Z_OK; int ret = Z_OK;
unsigned had; unsigned had;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -226,9 +209,7 @@ local int gz_decomp(state)
looked for to determine whether to copy or decompress. Returns -1 on error, 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 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. */ end of the input file has been reached and all data has been processed. */
local int gz_fetch(state) static int gz_fetch(gz_statep state) {
gz_statep state;
{
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
do { do {
@@ -256,10 +237,7 @@ local int gz_fetch(state)
} }
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
local int gz_skip(state, len) static int gz_skip(gz_statep state, z_off64_t len) {
gz_statep state;
z_off64_t len;
{
unsigned n; unsigned n;
/* skip over len bytes or reach end-of-file, whichever comes first */ /* skip over len bytes or reach end-of-file, whichever comes first */
@@ -287,17 +265,30 @@ local int gz_skip(state, len)
return 0; return 0;
} }
/* Read len bytes into buf from file, or less than len up to the end of the /* -- see zlib.h -- */
input. Return the number of bytes read. If zero is returned, either the int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
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;
voidp buf;
z_size_t len;
{ {
z_size_t got; unsigned got, n;
unsigned n; 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;
}
/* if len is zero, avoid unnecessary operations */ /* if len is zero, avoid unnecessary operations */
if (len == 0) if (len == 0)
@@ -307,38 +298,32 @@ local z_size_t gz_read(state, buf, len)
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_skip(state, state->skip) == -1) if (gz_skip(state, state->skip) == -1)
return 0; return -1;
} }
/* get len bytes to buf, or less than len if at the end */ /* get len bytes to buf, or less than len if at the end */
got = 0; got = 0;
do { 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 */ /* first just try copying data from the output buffer */
if (state->x.have) { if (state->x.have) {
if (state->x.have < n) n = state->x.have > len ? len : state->x.have;
n = state->x.have;
memcpy(buf, state->x.next, n); memcpy(buf, state->x.next, n);
state->x.next += n; state->x.next += n;
state->x.have -= n; state->x.have -= n;
} }
/* output buffer empty -- return if we're at the end of the input */ /* output buffer empty -- return if we're at the end of the input */
else if (state->eof && state->strm.avail_in == 0) { else if (state->eof && strm->avail_in == 0) {
state->past = 1; /* tried to read past end */ state->past = 1; /* tried to read past end */
break; break;
} }
/* need output data -- for small len or new stream load up our output /* need output data -- for small len or new stream load up our output
buffer */ buffer */
else if (state->how == LOOK || n < (state->size << 1)) { else if (state->how == LOOK || len < (state->size << 1)) {
/* get more output, looking for header if required */ /* get more output, looking for header if required */
if (gz_fetch(state) == -1) if (gz_fetch(state) == -1)
return 0; return -1;
continue; /* no progress yet -- go back to copy above */ continue; /* no progress yet -- go back to copy above */
/* the copy above assures that we will leave with space in the /* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */ output buffer, allowing at least one gzungetc() to succeed */
@@ -346,16 +331,16 @@ local z_size_t gz_read(state, buf, len)
/* large len -- read directly into user buffer */ /* large len -- read directly into user buffer */
else if (state->how == COPY) { /* read directly */ else if (state->how == COPY) { /* read directly */
if (gz_load(state, (unsigned char *)buf, n, &n) == -1) if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
return 0; return -1;
} }
/* large len -- decompress directly into user buffer */ /* large len -- decompress directly into user buffer */
else { /* state->how == GZIP */ else { /* state->how == GZIP */
state->strm.avail_out = n; strm->avail_out = len;
state->strm.next_out = (unsigned char *)buf; strm->next_out = (unsigned char *)buf;
if (gz_decomp(state) == -1) if (gz_decomp(state) == -1)
return 0; return -1;
n = state->x.have; n = state->x.have;
state->x.have = 0; state->x.have = 0;
} }
@@ -367,75 +352,8 @@ local z_size_t gz_read(state, buf, len)
state->x.pos += n; state->x.pos += n;
} while (len); } while (len);
/* return number of bytes read into user buffer */ /* return number of bytes read into user buffer (will fit in int) */
return got; return (int)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 -- */ /* -- see zlib.h -- */
@@ -444,9 +362,8 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
#else #else
# undef gzgetc # undef gzgetc
#endif #endif
int ZEXPORT gzgetc(file) int ZEXPORT gzgetc(gzFile file) {
gzFile file; int ret;
{
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
@@ -467,21 +384,17 @@ int ZEXPORT gzgetc(file)
return *(state->x.next)++; return *(state->x.next)++;
} }
/* nothing there -- try gz_read() */ /* nothing there -- try gzread() */
return gz_read(state, buf, 1) < 1 ? -1 : buf[0]; ret = gzread(file, buf, 1);
return ret < 1 ? -1 : buf[0];
} }
int ZEXPORT gzgetc_(file) int ZEXPORT gzgetc_(gzFile file) {
gzFile file;
{
return gzgetc(file); return gzgetc(file);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzungetc(c, file) int ZEXPORT gzungetc(int c, gzFile file) {
int c;
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -489,6 +402,10 @@ int ZEXPORT gzungetc(c, file)
return -1; return -1;
state = (gz_statep)file; 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 */ /* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ || if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR)) (state->err != Z_OK && state->err != Z_BUF_ERROR))
@@ -509,7 +426,7 @@ int ZEXPORT gzungetc(c, file)
if (state->x.have == 0) { if (state->x.have == 0) {
state->x.have = 1; state->x.have = 1;
state->x.next = state->out + (state->size << 1) - 1; state->x.next = state->out + (state->size << 1) - 1;
state->x.next[0] = (unsigned char)c; state->x.next[0] = c;
state->x.pos--; state->x.pos--;
state->past = 0; state->past = 0;
return c; return c;
@@ -531,18 +448,14 @@ int ZEXPORT gzungetc(c, file)
} }
state->x.have++; state->x.have++;
state->x.next--; state->x.next--;
state->x.next[0] = (unsigned char)c; state->x.next[0] = c;
state->x.pos--; state->x.pos--;
state->past = 0; state->past = 0;
return c; return c;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
char * ZEXPORT gzgets(file, buf, len) char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
gzFile file;
char *buf;
int len;
{
unsigned left, n; unsigned left, n;
char *str; char *str;
unsigned char *eol; unsigned char *eol;
@@ -602,9 +515,7 @@ char * ZEXPORT gzgets(file, buf, len)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzdirect(file) int ZEXPORT gzdirect(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@@ -622,9 +533,7 @@ int ZEXPORT gzdirect(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_r(file) int ZEXPORT gzclose_r(gzFile file) {
gzFile file;
{
int ret, err; int ret, err;
gz_statep state; gz_statep state;

272
deps/zlib/gzwrite.c vendored
View File

@@ -1,22 +1,18 @@
/* gzwrite.c -- zlib functions for writing gzip files /* gzwrite.c -- zlib functions for writing gzip files
* Copyright (C) 2004-2019 Mark Adler * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "gzguts.h" #include "gzguts.h"
/* Local functions */ /* Local functions */
local int gz_init OF((gz_statep)); local int gz_init(gz_statep);
local int gz_comp OF((gz_statep, int)); local int gz_comp(gz_statep, int);
local int gz_zero OF((gz_statep, z_off64_t)); local int gz_zero(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 /* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on state->size to non-zero. Return -1 on failure or 0 on success. */
success. */ static int gz_init(gz_statep state) {
local int gz_init(state)
gz_statep state;
{
int ret; int ret;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -70,12 +66,10 @@ local int gz_init(state)
deflate() flush value. If flush is Z_FINISH, then the deflate() state is 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 reset to start a new gzip stream. If gz->direct is true, then simply write
to the output file without compressing, and ignore flush. */ to the output file without compressing, and ignore flush. */
local int gz_comp(state, flush) static int gz_comp(gz_statep state, int flush) {
gz_statep state; int ret;
int flush; z_ssize_t got;
{ unsigned have;
int ret, writ;
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate memory if this is the first time through */ /* allocate memory if this is the first time through */
@@ -85,14 +79,13 @@ local int gz_comp(state, flush)
/* write directly if requested */ /* write directly if requested */
if (state->direct) { if (state->direct) {
while (strm->avail_in) { while (strm->avail_in) {
put = strm->avail_in > max ? max : strm->avail_in; got = write(state->fd, strm->next_in, strm->avail_in);
writ = write(state->fd, strm->next_in, put); if (got < 0) {
if (writ < 0) {
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
return -1; return -1;
} }
strm->avail_in -= (unsigned)writ; strm->avail_in -= got;
strm->next_in += writ; strm->next_in += got;
} }
return 0; return 0;
} }
@@ -114,14 +107,13 @@ local int gz_comp(state, flush)
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) { (flush != Z_FINISH || ret == Z_STREAM_END))) {
while (strm->next_out > state->x.next) { while (strm->next_out > state->x.next) {
put = strm->next_out - state->x.next > (int)max ? max : got = write(state->fd, state->x.next,
(unsigned)(strm->next_out - state->x.next); strm->next_out - state->x.next);
writ = write(state->fd, state->x.next, put); if (got < 0) {
if (writ < 0) {
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
return -1; return -1;
} }
state->x.next += writ; state->x.next += got;
} }
if (strm->avail_out == 0) { if (strm->avail_out == 0) {
strm->avail_out = state->size; strm->avail_out = state->size;
@@ -149,12 +141,8 @@ local int gz_comp(state, flush)
return 0; return 0;
} }
/* Compress len zeros to output. Return -1 on a write error or memory /* Compress len zeros to output. Return -1 on error, 0 on success. */
allocation failure by gz_comp(), or 0 on success. */ static int gz_zero(gz_statep state, z_off64_t len) {
local int gz_zero(state, len)
gz_statep state;
z_off64_t len;
{
int first; int first;
unsigned n; unsigned n;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@@ -182,14 +170,29 @@ local int gz_zero(state, len)
return 0; return 0;
} }
/* Write len bytes from buf to file. Return the number of bytes written. If /* -- see zlib.h -- */
the returned value is less than len, then there was an error. */ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
local z_size_t gz_write(state, buf, len)
gz_statep state;
voidpc buf;
z_size_t len;
{ {
z_size_t put = len; unsigned put = 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;
}
/* if len is zero, avoid unnecessary operations */ /* if len is zero, avoid unnecessary operations */
if (len == 0) if (len == 0)
@@ -212,15 +215,14 @@ local z_size_t gz_write(state, buf, len)
do { do {
unsigned have, copy; unsigned have, copy;
if (state->strm.avail_in == 0) if (strm->avail_in == 0)
state->strm.next_in = state->in; strm->next_in = state->in;
have = (unsigned)((state->strm.next_in + state->strm.avail_in) - have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
state->in);
copy = state->size - have; copy = state->size - have;
if (copy > len) if (copy > len)
copy = (unsigned)len; copy = len;
memcpy(state->in + have, buf, copy); memcpy(state->in + have, buf, copy);
state->strm.avail_in += copy; strm->avail_in += copy;
state->x.pos += copy; state->x.pos += copy;
buf = (const char *)buf + copy; buf = (const char *)buf + copy;
len -= copy; len -= copy;
@@ -230,89 +232,23 @@ local z_size_t gz_write(state, buf, len)
} }
else { else {
/* consume whatever's left in the input buffer */ /* consume whatever's left in the input buffer */
if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
/* directly compress user buffer to file */ /* directly compress user buffer to file */
state->strm.next_in = (z_const Bytef *)buf; strm->avail_in = len;
do { strm->next_in = (z_const Bytef *)buf;
unsigned n = (unsigned)-1; state->x.pos += len;
if (n > len) if (gz_comp(state, Z_NO_FLUSH) == -1)
n = (unsigned)len; return 0;
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 */ /* input was all buffered or compressed (put will fit in int) */
return put; return (int)put;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzwrite(file, buf, len) int ZEXPORT gzputc(gzFile file, int c)
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 have;
unsigned char buf[1]; unsigned char buf[1];
@@ -343,7 +279,7 @@ int ZEXPORT gzputc(file, c)
strm->next_in = state->in; strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in); have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
if (have < state->size) { if (have < state->size) {
state->in[have] = (unsigned char)c; state->in[have] = c;
strm->avail_in++; strm->avail_in++;
state->x.pos++; state->x.pos++;
return c & 0xff; return c & 0xff;
@@ -351,37 +287,22 @@ int ZEXPORT gzputc(file, c)
} }
/* no room in buffer or not initialized, use gz_write() */ /* no room in buffer or not initialized, use gz_write() */
buf[0] = (unsigned char)c; buf[0] = c;
if (gz_write(state, buf, 1) != 1) if (gzwrite(file, buf, 1) != 1)
return -1; return -1;
return c & 0xff; return c & 0xff;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputs(file, s) int ZEXPORT gzputs(gzFile file, const char *str)
gzFile file;
const char *s;
{ {
z_size_t len, put; int ret;
gz_statep state; unsigned len;
/* 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 */ /* write string */
len = strlen(s); len = (unsigned)strlen(str);
if ((int)len < 0 || (unsigned)len != len) { ret = gzwrite(file, str, len);
gz_error(state, Z_STREAM_ERROR, "string length does not fit in int"); return ret == 0 && len != 0 ? -1 : ret;
return -1;
}
put = gz_write(state, s, len);
return put < len ? -1 : (int)len;
} }
#if defined(STDC) || defined(Z_HAVE_STDARG_H) #if defined(STDC) || defined(Z_HAVE_STDARG_H)
@@ -390,31 +311,30 @@ int ZEXPORT gzputs(file, s)
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
{ {
int len; unsigned len, left;
unsigned left;
char *next; char *next;
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return -1;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK)
return Z_STREAM_ERROR; return 0;
/* make sure we have some buffer space */ /* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return state->err; return 0;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return state->err; return 0;
} }
/* do the printf() into the input buffer, put length in len -- the input /* do the printf() into the input buffer, put length in len -- the input
@@ -422,7 +342,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
be state->size bytes available after the current contents */ be state->size bytes available after the current contents */
if (strm->avail_in == 0) if (strm->avail_in == 0)
strm->next_in = state->in; strm->next_in = state->in;
next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in); next = (char *)(strm->next_in + strm->avail_in);
next[state->size - 1] = 0; next[state->size - 1] = 0;
#ifdef NO_vsnprintf #ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void # ifdef HAS_vsprintf_void
@@ -442,26 +362,25 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
#endif #endif
/* check that printf() results fit in buffer */ /* check that printf() results fit in buffer */
if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0) if (len == 0 || len >= state->size || next[state->size - 1] != 0)
return 0; return 0;
/* update buffer and position, compress first half if past that */ /* update buffer and position, compress first half if past that */
strm->avail_in += (unsigned)len; strm->avail_in += len;
state->x.pos += len; state->x.pos += len;
if (strm->avail_in >= state->size) { if (strm->avail_in >= state->size) {
left = strm->avail_in - state->size; left = strm->avail_in - state->size;
strm->avail_in = state->size; strm->avail_in = state->size;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->err; return 0;
memmove(state->in, state->in + state->size, left); memcpy(state->in, state->in + state->size, left);
strm->next_in = state->in; strm->next_in = state->in;
strm->avail_in = left; strm->avail_in = left;
} }
return len; return (int)len;
} }
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
{
va_list va; va_list va;
int ret; int ret;
@@ -488,27 +407,27 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return -1;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that can really pass pointer in ints */ /* check that can really pass pointer in ints */
if (sizeof(int) != sizeof(void *)) if (sizeof(int) != sizeof(void *))
return Z_STREAM_ERROR; return 0;
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK)
return Z_STREAM_ERROR; return 0;
/* make sure we have some buffer space */ /* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return state->error; return 0;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return state->error; return 0;
} }
/* do the printf() into the input buffer, put length in len -- the input /* do the printf() into the input buffer, put length in len -- the input
@@ -551,8 +470,8 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
left = strm->avail_in - state->size; left = strm->avail_in - state->size;
strm->avail_in = state->size; strm->avail_in = state->size;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->err; return 0;
memmove(state->in, state->in + state->size, left); memcpy(state->in, state->in + state->size, left);
strm->next_in = state->in; strm->next_in = state->in;
strm->avail_in = left; strm->avail_in = left;
} }
@@ -562,15 +481,12 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzflush(file, flush) int ZEXPORT gzflush(gzFile file, int flush) {
gzFile file;
int flush;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return Z_STREAM_ERROR; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
@@ -585,7 +501,7 @@ int ZEXPORT gzflush(file, flush)
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return state->err; return -1;
} }
/* compress remaining data with requested flush */ /* compress remaining data with requested flush */
@@ -594,11 +510,7 @@ int ZEXPORT gzflush(file, flush)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzsetparams(file, level, strategy) int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
gzFile file;
int level;
int strategy;
{
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
@@ -609,7 +521,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* if no change is requested, then do nothing */ /* if no change is requested, then do nothing */
@@ -620,7 +532,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return state->err; return -1;
} }
/* change compression parameters for subsequent input */ /* change compression parameters for subsequent input */
@@ -636,9 +548,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_w(file) int ZEXPORT gzclose_w(gzFile file) {
gzFile file;
{
int ret = Z_OK; int ret = Z_OK;
gz_statep state; gz_statep state;

59
deps/zlib/infback.c vendored
View File

@@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface /* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2022 Mark Adler * Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@@ -16,7 +16,7 @@
#include "inffast.h" #include "inffast.h"
/* function prototypes */ /* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state)); local void fixedtables(struct inflate_state FAR *state);
/* /*
strm provides memory allocation functions in zalloc and zfree, or strm provides memory allocation functions in zalloc and zfree, or
@@ -25,13 +25,9 @@ local void fixedtables OF((struct inflate_state FAR *state));
windowBits is in the range 8..15, and window is a user-supplied windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes. window and output buffer that is 2**windowBits bytes.
*/ */
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
z_streamp strm; unsigned char FAR *window, const char *version,
int windowBits; int stream_size) {
unsigned char FAR *window;
const char *version;
int stream_size;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
@@ -61,11 +57,12 @@ int stream_size;
Tracev((stderr, "inflate: allocated\n")); Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state; strm->state = (struct internal_state FAR *)state;
state->dmax = 32768U; state->dmax = 32768U;
state->wbits = (uInt)windowBits; state->wbits = windowBits;
state->wsize = 1U << windowBits; state->wsize = 1U << windowBits;
state->window = window; state->window = window;
state->wnext = 0; state->wnext = 0;
state->whave = 0; state->whave = 0;
state->sane = 1;
return Z_OK; return Z_OK;
} }
@@ -79,9 +76,7 @@ int stream_size;
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(state) static void fixedtables(struct inflate_state FAR *state) {
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
@@ -247,13 +242,8 @@ struct inflate_state FAR *state;
inflateBack() can also return Z_STREAM_ERROR if the input parameters 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. are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/ */
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
z_streamp strm; out_func out, void FAR *out_desc) {
in_func in;
void FAR *in_desc;
out_func out;
void FAR *out_desc;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
@@ -454,11 +444,11 @@ void FAR *out_desc;
} }
/* build code tables -- note: do not change the lenbits or distbits /* build code tables -- note: do not change the lenbits or distbits
values here (9 and 6) without reading the comments in inftrees.h values here (10 and 9) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */ concerning the ENOUGH constants, which depend on those values */
state->next = state->codes; state->next = state->codes;
state->lencode = (code const FAR *)(state->next); state->lencode = (code const FAR *)(state->next);
state->lenbits = 9; state->lenbits = 10;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
if (ret) { if (ret) {
@@ -467,7 +457,7 @@ void FAR *out_desc;
break; break;
} }
state->distcode = (code const FAR *)(state->next); state->distcode = (code const FAR *)(state->next);
state->distbits = 6; state->distbits = 9;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work); &(state->next), &(state->distbits), state->work);
if (ret) { if (ret) {
@@ -481,7 +471,8 @@ void FAR *out_desc;
case LEN: case LEN:
/* use inflate_fast() if we have enough input and output */ /* use inflate_fast() if we have enough input and output */
if (have >= 6 && left >= 258) { if (have >= INFLATE_FAST_MIN_INPUT &&
left >= INFLATE_FAST_MIN_OUTPUT) {
RESTORE(); RESTORE();
if (state->whave < state->wsize) if (state->whave < state->wsize)
state->whave = state->wsize - left; state->whave = state->wsize - left;
@@ -605,33 +596,33 @@ void FAR *out_desc;
break; break;
case DONE: case DONE:
/* inflate stream terminated properly -- write leftover output */ /* inflate stream terminated properly */
ret = Z_STREAM_END; ret = Z_STREAM_END;
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR;
}
goto inf_leave; goto inf_leave;
case BAD: case BAD:
ret = Z_DATA_ERROR; ret = Z_DATA_ERROR;
goto inf_leave; goto inf_leave;
default: /* can't happen, but makes compilers happy */ default:
/* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR; ret = Z_STREAM_ERROR;
goto inf_leave; goto inf_leave;
} }
/* Return unused input */ /* Write leftover output and return unused input */
inf_leave: 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->next_in = next;
strm->avail_in = have; strm->avail_in = have;
return ret; return ret;
} }
int ZEXPORT inflateBackEnd(strm) int ZEXPORT inflateBackEnd(z_streamp strm) {
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
ZFREE(strm, strm->state); ZFREE(strm, strm->state);

24
deps/zlib/inffast.c vendored
View File

@@ -8,9 +8,7 @@
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
#ifdef ASMINF #ifndef 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 Decode literal, length, and distance codes and write out the resulting
@@ -23,8 +21,8 @@
Entry assumptions: Entry assumptions:
state->mode == LEN state->mode == LEN
strm->avail_in >= 6 strm->avail_in >= INFLATE_FAST_MIN_INPUT
strm->avail_out >= 258 strm->avail_out >= INFLATE_FAST_MIN_OUTPUT
start >= strm->avail_out start >= strm->avail_out
state->bits < 8 state->bits < 8
@@ -47,10 +45,7 @@
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void ZLIB_INTERNAL inflate_fast(strm, start) void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *in; /* local strm->next_in */
z_const unsigned char FAR *last; /* have enough input while in < last */ z_const unsigned char FAR *last; /* have enough input while in < last */
@@ -80,10 +75,10 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
/* copy state to local variables */ /* copy state to local variables */
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
in = strm->next_in; in = strm->next_in;
last = in + (strm->avail_in - 5); last = in + (strm->avail_in - (INFLATE_FAST_MIN_INPUT - 1));
out = strm->next_out; out = strm->next_out;
beg = out - (start - strm->avail_out); beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257); end = out + (strm->avail_out - (INFLATE_FAST_MIN_OUTPUT - 1));
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
dmax = state->dmax; dmax = state->dmax;
#endif #endif
@@ -298,9 +293,12 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
/* update state and return */ /* update state and return */
strm->next_in = in; strm->next_in = in;
strm->next_out = out; strm->next_out = out;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); 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 ? strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end)); (INFLATE_FAST_MIN_OUTPUT - 1) + (end - out) :
(INFLATE_FAST_MIN_OUTPUT - 1) - (out - end));
state->hold = hold; state->hold = hold;
state->bits = bits; state->bits = bits;
return; return;

17
deps/zlib/inffast.h vendored
View File

@@ -8,4 +8,19 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); /* 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);

398
deps/zlib/inffast_chunk.c vendored Normal file
View File

@@ -0,0 +1,398 @@
/* 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 Normal file
View File

@@ -0,0 +1,64 @@
/* 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
View File

@@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression /* inflate.c -- zlib decompression
* Copyright (C) 1995-2022 Mark Adler * Copyright (C) 1995-2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@@ -83,7 +83,13 @@
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#include "inflate.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" #include "inffast.h"
#endif
#ifdef MAKEFIXED #ifdef MAKEFIXED
# ifndef BUILDFIXED # ifndef BUILDFIXED
@@ -92,19 +98,17 @@
#endif #endif
/* function prototypes */ /* function prototypes */
local int inflateStateCheck OF((z_streamp strm)); local int inflateStateCheck(z_streamp strm);
local void fixedtables OF((struct inflate_state FAR *state)); local void fixedtables(struct inflate_state FAR *state);
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, local int updatewindow(z_streamp strm, const unsigned char FAR *end,
unsigned copy)); unsigned copy);
#ifdef BUILDFIXED #ifdef BUILDFIXED
void makefixed OF((void)); void makefixed(void);
#endif #endif
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
unsigned len)); unsigned len);
local int inflateStateCheck(strm) static int inflateStateCheck(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || if (strm == Z_NULL ||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
@@ -116,9 +120,7 @@ z_streamp strm;
return 0; return 0;
} }
int ZEXPORT inflateResetKeep(strm) int ZEXPORT inflateResetKeep(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -142,9 +144,7 @@ z_streamp strm;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateReset(strm) int ZEXPORT inflateReset(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -155,10 +155,7 @@ z_streamp strm;
return inflateResetKeep(strm); return inflateResetKeep(strm);
} }
int ZEXPORT inflateReset2(strm, windowBits) int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
z_streamp strm;
int windowBits;
{
int wrap; int wrap;
struct inflate_state FAR *state; struct inflate_state FAR *state;
@@ -168,6 +165,8 @@ int windowBits;
/* extract wrap request from windowBits parameter */ /* extract wrap request from windowBits parameter */
if (windowBits < 0) { if (windowBits < 0) {
if (windowBits < -15)
return Z_STREAM_ERROR;
wrap = 0; wrap = 0;
windowBits = -windowBits; windowBits = -windowBits;
} }
@@ -193,12 +192,8 @@ int windowBits;
return inflateReset(strm); return inflateReset(strm);
} }
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
z_streamp strm; const char *version, int stream_size) {
int windowBits;
const char *version;
int stream_size;
{
int ret; int ret;
struct inflate_state FAR *state; struct inflate_state FAR *state;
@@ -237,32 +232,27 @@ int stream_size;
return ret; return ret;
} }
int ZEXPORT inflateInit_(strm, version, stream_size) int ZEXPORT inflateInit_(z_streamp strm, const char *version,
z_streamp strm; int stream_size) {
const char *version;
int stream_size;
{
return inflateInit2_(strm, DEF_WBITS, version, stream_size); return inflateInit2_(strm, DEF_WBITS, version, stream_size);
} }
int ZEXPORT inflatePrime(strm, bits, value) int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
z_streamp strm;
int bits;
int value;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
if (bits == 0)
return Z_OK;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (bits < 0) { if (bits < 0) {
state->hold = 0; state->hold = 0;
state->bits = 0; state->bits = 0;
return Z_OK; return Z_OK;
} }
if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR; if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
value &= (1L << bits) - 1; value &= (1L << bits) - 1;
state->hold += (unsigned)value << state->bits; state->hold += (unsigned)value << state->bits;
state->bits += (uInt)bits; state->bits += bits;
return Z_OK; return Z_OK;
} }
@@ -276,9 +266,7 @@ int value;
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(state) static void fixedtables(struct inflate_state FAR *state) {
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
@@ -340,7 +328,7 @@ struct inflate_state FAR *state;
a.out > inffixed.h a.out > inffixed.h
*/ */
void makefixed() void makefixed(void)
{ {
unsigned low, size; unsigned low, size;
struct inflate_state state; struct inflate_state state;
@@ -394,11 +382,7 @@ void makefixed()
output will fall in the output data, making match copies simpler and faster. 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. The advantage may be dependent on the size of the processor's data caches.
*/ */
local int updatewindow(strm, end, copy) static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
z_streamp strm;
const Bytef *end;
unsigned copy;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned dist; unsigned dist;
@@ -406,10 +390,27 @@ unsigned copy;
/* if it hasn't been done already, allocate space for the window */ /* if it hasn't been done already, allocate space for the window */
if (state->window == Z_NULL) { 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 *) state->window = (unsigned char FAR *)
ZALLOC(strm, 1U << state->wbits, ZALLOC(strm, 1U << state->wbits,
sizeof(unsigned char)); sizeof(unsigned char));
if (state->window == Z_NULL) return 1; if (state->window == Z_NULL) return 1;
#endif /* INFLATE_CHUNK_SIMD */
} }
/* if window not in use yet, initialize */ /* if window not in use yet, initialize */
@@ -448,10 +449,10 @@ unsigned copy;
/* check function to use adler32() for zlib or crc32() for gzip */ /* check function to use adler32() for zlib or crc32() for gzip */
#ifdef GUNZIP #ifdef GUNZIP
# define UPDATE_CHECK(check, buf, len) \ # define UPDATE(check, buf, len) \
(state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
#else #else
# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len) # define UPDATE(check, buf, len) adler32(check, buf, len)
#endif #endif
/* check macros for header crc */ /* check macros for header crc */
@@ -620,10 +621,7 @@ unsigned copy;
will return Z_BUF_ERROR if it has not reached the end of the stream. will return Z_BUF_ERROR if it has not reached the end of the stream.
*/ */
int ZEXPORT inflate(strm, flush) int ZEXPORT inflate(z_streamp strm, int flush) {
z_streamp strm;
int flush;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
@@ -764,8 +762,9 @@ int flush;
if (copy > have) copy = have; if (copy > have) copy = have;
if (copy) { if (copy) {
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->extra != Z_NULL) { state->head->extra != Z_NULL &&
len = state->head->extra_len - state->length; (len = state->head->extra_len - state->length) <
state->head->extra_max) {
zmemcpy(state->head->extra + len, next, zmemcpy(state->head->extra + len, next,
len + copy > state->head->extra_max ? len + copy > state->head->extra_max ?
state->head->extra_max - len : copy); state->head->extra_max - len : copy);
@@ -790,7 +789,7 @@ int flush;
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->name != Z_NULL && state->head->name != Z_NULL &&
state->length < state->head->name_max) state->length < state->head->name_max)
state->head->name[state->length++] = (Bytef)len; state->head->name[state->length++] = len;
} while (len && copy < have); } while (len && copy < have);
if ((state->flags & 0x0200) && (state->wrap & 4)) if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy); state->check = crc32(state->check, next, copy);
@@ -812,7 +811,7 @@ int flush;
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->comment != Z_NULL && state->head->comment != Z_NULL &&
state->length < state->head->comm_max) state->length < state->head->comm_max)
state->head->comment[state->length++] = (Bytef)len; state->head->comment[state->length++] = len;
} while (len && copy < have); } while (len && copy < have);
if ((state->flags & 0x0200) && (state->wrap & 4)) if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy); state->check = crc32(state->check, next, copy);
@@ -1030,11 +1029,11 @@ int flush;
} }
/* build code tables -- note: do not change the lenbits or distbits /* build code tables -- note: do not change the lenbits or distbits
values here (9 and 6) without reading the comments in inftrees.h values here (10 and 9) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */ concerning the ENOUGH constants, which depend on those values */
state->next = state->codes; state->next = state->codes;
state->lencode = (const code FAR *)(state->next); state->lencode = (const code FAR *)(state->next);
state->lenbits = 9; state->lenbits = 10;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
if (ret) { if (ret) {
@@ -1043,7 +1042,7 @@ int flush;
break; break;
} }
state->distcode = (const code FAR *)(state->next); state->distcode = (const code FAR *)(state->next);
state->distbits = 6; state->distbits = 9;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work); &(state->next), &(state->distbits), state->work);
if (ret) { if (ret) {
@@ -1059,9 +1058,14 @@ int flush;
state->mode = LEN; state->mode = LEN;
/* fallthrough */ /* fallthrough */
case LEN: case LEN:
if (have >= 6 && left >= 258) { if (have >= INFLATE_FAST_MIN_INPUT &&
left >= INFLATE_FAST_MIN_OUTPUT) {
RESTORE(); 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); inflate_fast(strm, out);
#endif
LOAD(); LOAD();
if (state->mode == TYPE) if (state->mode == TYPE)
state->back = -1; state->back = -1;
@@ -1196,6 +1200,18 @@ int flush;
else else
from = state->window + (state->wnext - copy); from = state->window + (state->wnext - copy);
if (copy > state->length) copy = state->length; 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 */ else { /* copy from output */
from = put - state->offset; from = put - state->offset;
@@ -1207,6 +1223,7 @@ int flush;
do { do {
*put++ = *from++; *put++ = *from++;
} while (--copy); } while (--copy);
#endif
if (state->length == 0) state->mode = LEN; if (state->length == 0) state->mode = LEN;
break; break;
case LIT: case LIT:
@@ -1223,7 +1240,7 @@ int flush;
state->total += out; state->total += out;
if ((state->wrap & 4) && out) if ((state->wrap & 4) && out)
strm->adler = state->check = strm->adler = state->check =
UPDATE_CHECK(state->check, put - out, out); UPDATE(state->check, put - out, out);
out = left; out = left;
if ((state->wrap & 4) && ( if ((state->wrap & 4) && (
#ifdef GUNZIP #ifdef GUNZIP
@@ -1275,6 +1292,29 @@ int flush;
Note: a memory error from inflate() is non-recoverable. Note: a memory error from inflate() is non-recoverable.
*/ */
inf_leave: 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(); RESTORE();
if (state->wsize || (out != strm->avail_out && state->mode < BAD && if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
(state->mode < CHECK || flush != Z_FINISH))) (state->mode < CHECK || flush != Z_FINISH)))
@@ -1289,8 +1329,8 @@ int flush;
state->total += out; state->total += out;
if ((state->wrap & 4) && out) if ((state->wrap & 4) && out)
strm->adler = state->check = strm->adler = state->check =
UPDATE_CHECK(state->check, strm->next_out - out, out); UPDATE(state->check, strm->next_out - out, out);
strm->data_type = (int)state->bits + (state->last ? 64 : 0) + strm->data_type = state->bits + (state->last ? 64 : 0) +
(state->mode == TYPE ? 128 : 0) + (state->mode == TYPE ? 128 : 0) +
(state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
@@ -1298,8 +1338,7 @@ int flush;
return ret; return ret;
} }
int ZEXPORT inflateEnd(strm) int ZEXPORT inflateEnd(z_streamp strm)
z_streamp strm;
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) if (inflateStateCheck(strm))
@@ -1312,11 +1351,8 @@ z_streamp strm;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
z_streamp strm; uInt *dictLength) {
Bytef *dictionary;
uInt *dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
@@ -1335,11 +1371,8 @@ uInt *dictLength;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
z_streamp strm; uInt dictLength) {
const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned long dictid; unsigned long dictid;
int ret; int ret;
@@ -1370,10 +1403,7 @@ uInt dictLength;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetHeader(strm, head) int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
z_streamp strm;
gz_headerp head;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
@@ -1398,11 +1428,8 @@ gz_headerp head;
called again with more data and the *have state. *have is initialized to called again with more data and the *have state. *have is initialized to
zero for the first call. zero for the first call.
*/ */
local unsigned syncsearch(have, buf, len) static unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
unsigned FAR *have; unsigned len) {
const unsigned char FAR *buf;
unsigned len;
{
unsigned got; unsigned got;
unsigned next; unsigned next;
@@ -1421,9 +1448,7 @@ unsigned len;
return next; return next;
} }
int ZEXPORT inflateSync(strm) int ZEXPORT inflateSync(z_streamp strm) {
z_streamp strm;
{
unsigned len; /* number of bytes to look at or looked at */ unsigned len; /* number of bytes to look at or looked at */
int flags; /* temporary to save header status */ int flags; /* temporary to save header status */
unsigned long in, out; /* temporary to save total_in and total_out */ unsigned long in, out; /* temporary to save total_in and total_out */
@@ -1479,9 +1504,7 @@ z_streamp strm;
block. When decompressing, PPP checks that at the end of input packet, block. When decompressing, PPP checks that at the end of input packet,
inflate is waiting for these length bytes. inflate is waiting for these length bytes.
*/ */
int ZEXPORT inflateSyncPoint(strm) int ZEXPORT inflateSyncPoint(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1489,10 +1512,7 @@ z_streamp strm;
return state->mode == STORED && state->bits == 0; return state->mode == STORED && state->bits == 0;
} }
int ZEXPORT inflateCopy(dest, source) int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
z_streamp dest;
z_streamp source;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
struct inflate_state FAR *copy; struct inflate_state FAR *copy;
unsigned char FAR *window; unsigned char FAR *window;
@@ -1536,10 +1556,7 @@ z_streamp source;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateUndermine(strm, subvert) int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
z_streamp strm;
int subvert;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1548,16 +1565,12 @@ int subvert;
state->sane = !subvert; state->sane = !subvert;
return Z_OK; return Z_OK;
#else #else
(void)subvert;
state->sane = 1; state->sane = 1;
return Z_DATA_ERROR; return Z_DATA_ERROR;
#endif #endif
} }
int ZEXPORT inflateValidate(strm, check) int ZEXPORT inflateValidate(z_streamp strm, int check) {
z_streamp strm;
int check;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -1569,24 +1582,13 @@ int check;
return Z_OK; return Z_OK;
} }
long ZEXPORT inflateMark(strm) long ZEXPORT inflateMark(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) if (inflateStateCheck(strm))
return -(1L << 16); return (long)(((unsigned long)0 - 1) << 16);
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
return (long)(((unsigned long)((long)state->back)) << 16) + return (long)(((unsigned long)((long)state->back)) << 16) +
(state->mode == COPY ? state->length : (state->mode == COPY ? state->length :
(state->mode == MATCH ? state->was - state->length : 0)); (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
View File

@@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2022 Mark Adler * Copyright (C) 1995-2023 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.12 Copyright 1995-2022 Mark Adler "; " inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome 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 in the documentation of your product. If for some reason you cannot
@@ -29,14 +29,9 @@ const char inflate_copyright[] =
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
codetype type; unsigned codes, code FAR * FAR *table,
unsigned short FAR *lens; unsigned FAR *bits, unsigned short FAR *work) {
unsigned codes;
code FAR * FAR *table;
unsigned FAR *bits;
unsigned short FAR *work;
{
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
@@ -62,7 +57,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 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 */ 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, 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, 199, 202}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 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, 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, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -188,7 +183,7 @@ unsigned short FAR *work;
extra = lext; extra = lext;
match = 257; match = 257;
break; break;
default: /* DISTS */ case DISTS:
base = dbase; base = dbase;
extra = dext; extra = dext;
match = 0; match = 0;
@@ -214,7 +209,7 @@ unsigned short FAR *work;
for (;;) { for (;;) {
/* create table entry */ /* create table entry */
here.bits = (unsigned char)(len - drop); here.bits = (unsigned char)(len - drop);
if (work[sym] + 1U < match) { if (work[sym] + 1 < match) {
here.op = (unsigned char)0; here.op = (unsigned char)0;
here.val = work[sym]; here.val = work[sym];
} }

18
deps/zlib/inftrees.h vendored
View File

@@ -36,17 +36,17 @@ typedef struct {
*/ */
/* Maximum size of the dynamic table. The maximum number of code structures is /* Maximum size of the dynamic table. The maximum number of code structures is
1444, which is the sum of 852 for literal/length codes and 592 for distance 1924, which is the sum of 1332 for literal/length codes and 592 for distance
codes. These values were found by exhaustive searches using the program codes. These values were found by exhaustive searches using the program
examples/enough.c found in the zlib distribtution. The arguments to that examples/enough.c found in the zlib distribution. The arguments to that
program are the number of symbols, the initial root table size, and the program are the number of symbols, the initial root table size, and the
maximum bit length of a code. "enough 286 9 15" for literal/length codes maximum bit length of a code. "enough 286 10 15" for literal/length codes
returns returns 852, and "enough 30 6 15" for distance codes returns 592. returns returns 1332, and "enough 30 9 15" for distance codes returns 592.
The initial root table size (9 or 6) is found in the fifth argument of the The initial root table size (10 or 9) is found in the fifth argument of the
inflate_table() calls in inflate.c and infback.c. If the root table size is 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 changed, then these maximum sizes would be need to be recalculated and
updated. */ updated. */
#define ENOUGH_LENS 852 #define ENOUGH_LENS 1332
#define ENOUGH_DISTS 592 #define ENOUGH_DISTS 592
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
@@ -57,6 +57,6 @@ typedef enum {
DISTS DISTS
} codetype; } codetype;
int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table, unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work)); unsigned FAR *bits, unsigned short FAR *work);

503
deps/zlib/trees.c vendored
View File

@@ -38,6 +38,7 @@
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
# include <ctype.h> # include <ctype.h>
# include <inttypes.h>
#endif #endif
/* =========================================================================== /* ===========================================================================
@@ -59,16 +60,16 @@
#define REPZ_11_138 18 #define REPZ_11_138 18
/* repeat a zero length 11-138 times (7 bits of repeat count) */ /* repeat a zero length 11-138 times (7 bits of repeat count) */
local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ static 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}; = {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};
local const int extra_dbits[D_CODES] /* extra bits for each distance code */ static 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}; = {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};
local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ static 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}; = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
local const uch bl_order[BL_CODES] static const uint8_t bl_order[BL_CODES]
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; = {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 /* The lengths of the bit length codes are sent in order of decreasing
* probability, to avoid transmitting the lengths for unused bit length codes. * probability, to avoid transmitting the lengths for unused bit length codes.
@@ -83,31 +84,31 @@ local const uch bl_order[BL_CODES]
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
/* non ANSI compilers may not accept trees.h */ /* non ANSI compilers may not accept trees.h */
local ct_data static_ltree[L_CODES+2]; static ct_data static_ltree[L_CODES+2];
/* The static literal tree. Since the bit lengths are imposed, there is no /* 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 * 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 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
* below). * below).
*/ */
local ct_data static_dtree[D_CODES]; static ct_data static_dtree[D_CODES];
/* The static distance tree. (Actually a trivial tree since all codes use /* The static distance tree. (Actually a trivial tree since all codes use
* 5 bits.) * 5 bits.)
*/ */
uch _dist_code[DIST_CODE_LEN]; uint8_t _dist_code[DIST_CODE_LEN];
/* Distance codes. The first 256 values correspond to the distances /* Distance codes. The first 256 values correspond to the distances
* 3 .. 258, the last 256 values correspond to the top 8 bits of * 3 .. 258, the last 256 values correspond to the top 8 bits of
* the 15 bit distances. * the 15 bit distances.
*/ */
uch _length_code[MAX_MATCH-MIN_MATCH+1]; uint8_t _length_code[MAX_MATCH-MIN_MATCH+1];
/* length code for each normalized match length (0 == MIN_MATCH) */ /* length code for each normalized match length (0 == MIN_MATCH) */
local int base_length[LENGTH_CODES]; static int base_length[LENGTH_CODES];
/* First normalized length for each code (0 = MIN_MATCH) */ /* First normalized length for each code (0 = MIN_MATCH) */
local int base_dist[D_CODES]; static int base_dist[D_CODES];
/* First normalized distance for each code (0 = distance of 1) */ /* First normalized distance for each code (0 = distance of 1) */
#else #else
@@ -116,45 +117,47 @@ local int base_dist[D_CODES];
struct static_tree_desc_s { struct static_tree_desc_s {
const ct_data *static_tree; /* static tree or NULL */ const ct_data *static_tree; /* static tree or NULL */
const intf *extra_bits; /* extra bits for each code or NULL */ const int *extra_bits; /* extra bits for each code or NULL */
int extra_base; /* base index for extra_bits */ int extra_base; /* base index for extra_bits */
int elems; /* max number of elements in the tree */ int elems; /* max number of elements in the tree */
int max_length; /* max bit length for the codes */ int max_length; /* max bit length for the codes */
}; };
local const static_tree_desc static_l_desc = static static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
local const static_tree_desc static_d_desc = static static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
local const static_tree_desc static_bl_desc = static static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
/* =========================================================================== /* ===========================================================================
* Local (static) routines in this file. * Local (static) routines in this file.
*/ */
local void tr_static_init OF((void)); static void tr_static_init (void);
local void init_block OF((deflate_state *s)); static void init_block (deflate_state *s);
local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); static void pqdownheap (deflate_state *s, ct_data *tree, int k);
local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); static void gen_bitlen (deflate_state *s, tree_desc *desc);
local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); static void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count);
local void build_tree OF((deflate_state *s, tree_desc *desc)); static void build_tree (deflate_state *s, tree_desc *desc);
local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); static void send_tree (deflate_state *s, ct_data *tree, int max_code);
local int build_bl_tree OF((deflate_state *s)); static int build_bl_tree (deflate_state *s);
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
int blcodes)); int blcodes);
local void compress_block OF((deflate_state *s, const ct_data *ltree, static void compress_block (deflate_state *s, const ct_data *ltree,
const ct_data *dtree)); const ct_data *dtree);
local int detect_data_type OF((deflate_state *s)); static int detect_data_type (deflate_state *s);
local unsigned bi_reverse OF((unsigned code, int len)); static unsigned bi_reverse (unsigned value, int length);
local void bi_windup OF((deflate_state *s)); static void bi_windup (deflate_state *s);
local void bi_flush OF((deflate_state *s)); static void bi_flush (deflate_state *s);
static void copy_block (deflate_state *s, uint8_t *buf, unsigned len,
int header);
#ifdef GEN_TREES_H #ifdef GEN_TREES_H
local void gen_trees_header OF((void)); static void gen_trees_header OF(void);
#endif #endif
#ifndef ZLIB_DEBUG #ifndef ZLIB_DEBUG
@@ -167,70 +170,36 @@ local void gen_trees_header OF((void));
send_bits(s, tree[c].Code, tree[c].Len); } send_bits(s, tree[c].Code, tree[c].Len); }
#endif #endif
/* ===========================================================================
* 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)); \
}
/* =========================================================================== /* ===========================================================================
* Send a value on a given number of bits. * Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits. * IN assertion: length <= 64 and value fits in length bits.
*/ */
#ifdef ZLIB_DEBUG
local void send_bits OF((deflate_state *s, int value, int length));
local void send_bits(s, value, length)
deflate_state *s; static void send_bits(deflate_state* s, uint64_t val, int len)
int value; /* value to send */
int length; /* number of bits */
{ {
Tracevv((stderr," l %2d v %4x ", length, value)); #ifdef ZLIB_DEBUG
Assert(length > 0 && length <= 15, "invalid length"); Tracevv((stderr," l %2d v %4" PRIx64 " ", len, val));
s->bits_sent += (ulg)length; Assert(len > 0 && len <= 64, "invalid length");
s->bits_sent += len;
#endif
/* If not enough room in bi_buf, use (valid) bits from bi_buf and s->bi_buf ^= (val<<s->bi_valid);
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) s->bi_valid += len;
* unused bits in value. if (s->bi_valid >= 64) {
*/ *(uint64_t*)(&s->pending_buf[s->pending]) = s->bi_buf;
if (s->bi_valid > (int)Buf_size - length) { s->pending += 8;
s->bi_buf |= (ush)value << s->bi_valid; s->bi_valid -= 64;
put_short(s, s->bi_buf); s->bi_buf = val >> (len - s->bi_valid);
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 */ /* the arguments must not have side effects */
/* =========================================================================== /* ===========================================================================
* Initialize the various 'constant' tables. * Initialize the various 'constant' tables.
*/ */
local void tr_static_init() static void tr_static_init(void) {
{
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
static int static_init_done = 0; static int static_init_done = 0;
int n; /* iterates over tree elements */ int n; /* iterates over tree elements */
@@ -238,7 +207,7 @@ local void tr_static_init()
int length; /* length value */ int length; /* length value */
int code; /* code value */ int code; /* code value */
int dist; /* distance index */ int dist; /* distance index */
ush bl_count[MAX_BITS+1]; uint16_t bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */ /* number of codes at each bit length for an optimal tree */
if (static_init_done) return; if (static_init_done) return;
@@ -257,7 +226,7 @@ local void tr_static_init()
for (code = 0; code < LENGTH_CODES-1; code++) { for (code = 0; code < LENGTH_CODES-1; code++) {
base_length[code] = length; base_length[code] = length;
for (n = 0; n < (1<<extra_lbits[code]); n++) { for (n = 0; n < (1<<extra_lbits[code]); n++) {
_length_code[length++] = (uch)code; _length_code[length++] = (uint8_t)code;
} }
} }
Assert (length == 256, "tr_static_init: length != 256"); Assert (length == 256, "tr_static_init: length != 256");
@@ -265,14 +234,14 @@ local void tr_static_init()
* in two different ways: code 284 + 5 bits or code 285, so we * in two different ways: code 284 + 5 bits or code 285, so we
* overwrite length_code[255] to use the best encoding: * overwrite length_code[255] to use the best encoding:
*/ */
_length_code[length-1] = (uch)code; _length_code[length-1] = (uint8_t)code;
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0; dist = 0;
for (code = 0 ; code < 16; code++) { for (code = 0 ; code < 16; code++) {
base_dist[code] = dist; base_dist[code] = dist;
for (n = 0; n < (1<<extra_dbits[code]); n++) { for (n = 0; n < (1<<extra_dbits[code]); n++) {
_dist_code[dist++] = (uch)code; _dist_code[dist++] = (uint8_t)code;
} }
} }
Assert (dist == 256, "tr_static_init: dist != 256"); Assert (dist == 256, "tr_static_init: dist != 256");
@@ -280,7 +249,7 @@ local void tr_static_init()
for ( ; code < D_CODES; code++) { for ( ; code < D_CODES; code++) {
base_dist[code] = dist << 7; base_dist[code] = dist << 7;
for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
_dist_code[256 + dist++] = (uch)code; _dist_code[256 + dist++] = (uint8_t)code;
} }
} }
Assert (dist == 256, "tr_static_init: 256+dist != 512"); Assert (dist == 256, "tr_static_init: 256+dist != 512");
@@ -323,8 +292,7 @@ local void tr_static_init()
((i) == (last)? "\n};\n\n" : \ ((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width)-1 ? ",\n" : ", ")) ((i) % (width) == (width)-1 ? ",\n" : ", "))
void gen_trees_header() void gen_trees_header(void) {
{
FILE *header = fopen("trees.h", "w"); FILE *header = fopen("trees.h", "w");
int i; int i;
@@ -332,38 +300,38 @@ void gen_trees_header()
fprintf(header, fprintf(header,
"/* header created automatically with -DGEN_TREES_H */\n\n"); "/* header created automatically with -DGEN_TREES_H */\n\n");
fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); fprintf(header, "static const ct_data static_ltree[L_CODES+2] = {\n");
for (i = 0; i < L_CODES+2; i++) { for (i = 0; i < L_CODES+2; i++) {
fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
} }
fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); fprintf(header, "static const ct_data static_dtree[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) { for (i = 0; i < D_CODES; i++) {
fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
} }
fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); fprintf(header, "const uint8_t ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
for (i = 0; i < DIST_CODE_LEN; i++) { for (i = 0; i < DIST_CODE_LEN; i++) {
fprintf(header, "%2u%s", _dist_code[i], fprintf(header, "%2u%s", _dist_code[i],
SEPARATOR(i, DIST_CODE_LEN-1, 20)); SEPARATOR(i, DIST_CODE_LEN-1, 20));
} }
fprintf(header, fprintf(header,
"const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); "const uint8_t ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
fprintf(header, "%2u%s", _length_code[i], fprintf(header, "%2u%s", _length_code[i],
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
} }
fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); fprintf(header, "static const int base_length[LENGTH_CODES] = {\n");
for (i = 0; i < LENGTH_CODES; i++) { for (i = 0; i < LENGTH_CODES; i++) {
fprintf(header, "%1u%s", base_length[i], fprintf(header, "%1u%s", base_length[i],
SEPARATOR(i, LENGTH_CODES-1, 20)); SEPARATOR(i, LENGTH_CODES-1, 20));
} }
fprintf(header, "local const int base_dist[D_CODES] = {\n"); fprintf(header, "static const int base_dist[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) { for (i = 0; i < D_CODES; i++) {
fprintf(header, "%5u%s", base_dist[i], fprintf(header, "%5u%s", base_dist[i],
SEPARATOR(i, D_CODES-1, 10)); SEPARATOR(i, D_CODES-1, 10));
@@ -376,9 +344,7 @@ void gen_trees_header()
/* =========================================================================== /* ===========================================================================
* Initialize the tree data structures for a new zlib stream. * Initialize the tree data structures for a new zlib stream.
*/ */
void ZLIB_INTERNAL _tr_init(s) void ZLIB_INTERNAL _tr_init(deflate_state *s) {
deflate_state *s;
{
tr_static_init(); tr_static_init();
s->l_desc.dyn_tree = s->dyn_ltree; s->l_desc.dyn_tree = s->dyn_ltree;
@@ -404,8 +370,7 @@ void ZLIB_INTERNAL _tr_init(s)
/* =========================================================================== /* ===========================================================================
* Initialize a new block. * Initialize a new block.
*/ */
local void init_block(s) static void init_block(deflate_state *s)
deflate_state *s;
{ {
int n; /* iterates over tree elements */ int n; /* iterates over tree elements */
@@ -448,11 +413,7 @@ local void init_block(s)
* when the heap property is re-established (each father smaller than its * when the heap property is re-established (each father smaller than its
* two sons). * two sons).
*/ */
local void pqdownheap(s, tree, k) static void pqdownheap(deflate_state *s, ct_data *tree, int k) {
deflate_state *s;
ct_data *tree; /* the tree to restore */
int k; /* node to move down */
{
int v = s->heap[k]; int v = s->heap[k];
int j = k << 1; /* left son of k */ int j = k << 1; /* left son of k */
while (j <= s->heap_len) { while (j <= s->heap_len) {
@@ -483,10 +444,7 @@ local void pqdownheap(s, tree, k)
* The length opt_len is updated; static_len is also updated if stree is * The length opt_len is updated; static_len is also updated if stree is
* not null. * not null.
*/ */
local void gen_bitlen(s, desc) static void gen_bitlen(deflate_state *s, tree_desc *desc) {
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree; ct_data *tree = desc->dyn_tree;
int max_code = desc->max_code; int max_code = desc->max_code;
const ct_data *stree = desc->stat_desc->static_tree; const ct_data *stree = desc->stat_desc->static_tree;
@@ -497,7 +455,7 @@ local void gen_bitlen(s, desc)
int n, m; /* iterate over the tree elements */ int n, m; /* iterate over the tree elements */
int bits; /* bit length */ int bits; /* bit length */
int xbits; /* extra bits */ int xbits; /* extra bits */
ush f; /* frequency */ uint16_t f; /* frequency */
int overflow = 0; /* number of elements with bit length too large */ int overflow = 0; /* number of elements with bit length too large */
for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
@@ -511,7 +469,7 @@ local void gen_bitlen(s, desc)
n = s->heap[h]; n = s->heap[h];
bits = tree[tree[n].Dad].Len + 1; bits = tree[tree[n].Dad].Len + 1;
if (bits > max_length) bits = max_length, overflow++; if (bits > max_length) bits = max_length, overflow++;
tree[n].Len = (ush)bits; tree[n].Len = (uint16_t)bits;
/* We overwrite tree[n].Dad which is no longer needed */ /* We overwrite tree[n].Dad which is no longer needed */
if (n > max_code) continue; /* not a leaf node */ if (n > max_code) continue; /* not a leaf node */
@@ -520,12 +478,12 @@ local void gen_bitlen(s, desc)
xbits = 0; xbits = 0;
if (n >= base) xbits = extra[n-base]; if (n >= base) xbits = extra[n-base];
f = tree[n].Freq; f = tree[n].Freq;
s->opt_len += (ulg)f * (unsigned)(bits + xbits); s->opt_len += (ulg)f * (bits + xbits);
if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits); if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
} }
if (overflow == 0) return; if (overflow == 0) return;
Tracev((stderr,"\nbit length overflow\n")); Trace((stderr,"\nbit length overflow\n"));
/* This happens for example on obj2 and pic of the Calgary corpus */ /* This happens for example on obj2 and pic of the Calgary corpus */
/* Find the first bit length which could increase: */ /* Find the first bit length which could increase: */
@@ -552,9 +510,10 @@ local void gen_bitlen(s, desc)
m = s->heap[--h]; m = s->heap[--h];
if (m > max_code) continue; if (m > max_code) continue;
if ((unsigned) tree[m].Len != (unsigned) bits) { if ((unsigned) tree[m].Len != (unsigned) bits) {
Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq; s->opt_len += ((long)bits - (long)tree[m].Len)
tree[m].Len = (ush)bits; *(long)tree[m].Freq;
tree[m].Len = (uint16_t)bits;
} }
n--; n--;
} }
@@ -569,13 +528,10 @@ local void gen_bitlen(s, desc)
* OUT assertion: the field code is set for all tree elements of non * OUT assertion: the field code is set for all tree elements of non
* zero code length. * zero code length.
*/ */
local void gen_codes (tree, max_code, bl_count) 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 */
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 */
{ {
ush next_code[MAX_BITS+1]; /* next code value for each bit length */ uint16_t next_code[MAX_BITS+1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */ uint16_t code = 0; /* running code value */
int bits; /* bit index */ int bits; /* bit index */
int n; /* code index */ int n; /* code index */
@@ -583,8 +539,7 @@ local void gen_codes (tree, max_code, bl_count)
* without bit reversal. * without bit reversal.
*/ */
for (bits = 1; bits <= MAX_BITS; bits++) { for (bits = 1; bits <= MAX_BITS; bits++) {
code = (code + bl_count[bits-1]) << 1; next_code[bits] = 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 /* Check that the bit counts in bl_count are consistent. The last code
* must be all ones. * must be all ones.
@@ -597,7 +552,7 @@ local void gen_codes (tree, max_code, bl_count)
int len = tree[n].Len; int len = tree[n].Len;
if (len == 0) continue; if (len == 0) continue;
/* Now reverse the bits */ /* Now reverse the bits */
tree[n].Code = (ush)bi_reverse(next_code[len]++, len); tree[n].Code = bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", 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)); n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
@@ -612,10 +567,7 @@ local void gen_codes (tree, max_code, bl_count)
* and corresponding code. The length opt_len is updated; static_len is * 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. * also updated if stree is not null. The field max_code is set.
*/ */
local void build_tree(s, desc) static void build_tree(deflate_state *s, tree_desc *desc) {
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree; ct_data *tree = desc->dyn_tree;
const ct_data *stree = desc->stat_desc->static_tree; const ct_data *stree = desc->stat_desc->static_tree;
int elems = desc->stat_desc->elems; int elems = desc->stat_desc->elems;
@@ -670,9 +622,9 @@ local void build_tree(s, desc)
/* Create a new node father of n and m */ /* Create a new node father of n and m */
tree[node].Freq = tree[n].Freq + tree[m].Freq; tree[node].Freq = tree[n].Freq + tree[m].Freq;
s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? s->depth[node] = (uint8_t)((s->depth[n] >= s->depth[m] ?
s->depth[n] : s->depth[m]) + 1); s->depth[n] : s->depth[m]) + 1);
tree[n].Dad = tree[m].Dad = (ush)node; tree[n].Dad = tree[m].Dad = (uint16_t)node;
#ifdef DUMP_BL_TREE #ifdef DUMP_BL_TREE
if (tree == s->bl_tree) { if (tree == s->bl_tree) {
fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
@@ -700,11 +652,7 @@ local void build_tree(s, desc)
* Scan a literal or distance tree to determine the frequencies of the codes * Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree. * in the bit length tree.
*/ */
local void scan_tree (s, tree, max_code) static void scan_tree(deflate_state *s, ct_data *tree, int 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 n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */ int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */ int curlen; /* length of current code */
@@ -714,7 +662,7 @@ local void scan_tree (s, tree, max_code)
int min_count = 4; /* min repeat count */ int min_count = 4; /* min repeat count */
if (nextlen == 0) max_count = 138, min_count = 3; if (nextlen == 0) max_count = 138, min_count = 3;
tree[max_code+1].Len = (ush)0xffff; /* guard */ tree[max_code+1].Len = (uint16_t)0xffff; /* guard */
for (n = 0; n <= max_code; n++) { for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len; curlen = nextlen; nextlen = tree[n+1].Len;
@@ -745,11 +693,7 @@ local void scan_tree (s, tree, max_code)
* Send a literal or distance tree in compressed form, using the codes in * Send a literal or distance tree in compressed form, using the codes in
* bl_tree. * bl_tree.
*/ */
local void send_tree (s, tree, max_code) static void send_tree(deflate_state *s, ct_data *tree, int 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 n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */ int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */ int curlen; /* length of current code */
@@ -796,9 +740,7 @@ local void send_tree (s, tree, max_code)
* Construct the Huffman tree for the bit lengths and return the index in * Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send. * bl_order of the last bit length code to send.
*/ */
local int build_bl_tree(s) static int build_bl_tree(deflate_state *s) {
deflate_state *s;
{
int max_blindex; /* index of last bit length code of non zero freq */ int max_blindex; /* index of last bit length code of non zero freq */
/* Determine the bit length frequencies for literal and distance trees */ /* Determine the bit length frequencies for literal and distance trees */
@@ -819,8 +761,8 @@ local int build_bl_tree(s)
if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
} }
/* Update opt_len to include the bit length tree and counts */ /* Update opt_len to include the bit length tree and counts */
s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4; s->opt_len += 3*(max_blindex+1) + 5+5+4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", Tracev((stderr, "\ndyn trees: dyn %" PRId64 ", stat %" PRId64,
s->opt_len, s->static_len)); s->opt_len, s->static_len));
return max_blindex; return max_blindex;
@@ -831,10 +773,8 @@ local int build_bl_tree(s)
* lengths of the bit length codes, the literal tree and the distance tree. * lengths of the bit length codes, the literal tree and the distance tree.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/ */
local void send_all_trees(s, lcodes, dcodes, blcodes) static void send_all_trees(deflate_state *s, int lcodes, int dcodes,
deflate_state *s; int blcodes) {
int lcodes, dcodes, blcodes; /* number of codes for each tree */
{
int rank; /* index in bl_order */ int rank; /* index in bl_order */
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
@@ -848,45 +788,32 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
Tracev((stderr, "\nbl code %2d ", bl_order[rank])); Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
} }
Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); Tracev((stderr, "\nbl tree: sent %" PRId64, s->bits_sent));
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); Tracev((stderr, "\nlit tree: sent %" PRId64, s->bits_sent));
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); Tracev((stderr, "\ndist tree: sent %" PRId64, s->bits_sent));
} }
/* =========================================================================== /* ===========================================================================
* Send a stored block * Send a stored block
*/ */
void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) 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 */
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 */ 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 #ifdef ZLIB_DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; s->compressed_len = (s->compressed_len + 3 + 7) & (uint64_t)~7L;
s->compressed_len += (stored_len + 4) << 3; s->compressed_len += (stored_len + 4) << 3;
s->bits_sent += 2*16;
s->bits_sent += stored_len<<3;
#endif #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) * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
*/ */
void ZLIB_INTERNAL _tr_flush_bits(s) void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
deflate_state *s;
{
bi_flush(s); bi_flush(s);
} }
@@ -894,8 +821,7 @@ void ZLIB_INTERNAL _tr_flush_bits(s)
* Send one empty static block to give enough lookahead for inflate. * Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer. * This takes 10 bits, of which 7 may remain in the bit buffer.
*/ */
void ZLIB_INTERNAL _tr_align(s) void ZLIB_INTERNAL _tr_align(deflate_state *s)
deflate_state *s;
{ {
send_bits(s, STATIC_TREES<<1, 3); send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree); send_code(s, END_BLOCK, static_ltree);
@@ -907,15 +833,11 @@ void ZLIB_INTERNAL _tr_align(s)
/* =========================================================================== /* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static * Determine the best encoding for the current block: dynamic trees, static
* trees or store, and write out the encoded block. * trees or store, and output the encoded block to the zip file.
*/ */
void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) 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 */
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 */
{ {
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ uint64_t 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 */ int max_blindex = 0; /* index of last bit length code of non zero freq */
/* Build the Huffman trees unless a stored block is forced */ /* Build the Huffman trees unless a stored block is forced */
@@ -927,11 +849,11 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
/* Construct the literal and distance trees */ /* Construct the literal and distance trees */
build_tree(s, (tree_desc *)(&(s->l_desc))); build_tree(s, (tree_desc *)(&(s->l_desc)));
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, Tracev((stderr, "\nlit data: dyn %" PRId64 ", stat %" PRId64, s->opt_len,
s->static_len)); s->static_len));
build_tree(s, (tree_desc *)(&(s->d_desc))); build_tree(s, (tree_desc *)(&(s->d_desc)));
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, Tracev((stderr, "\ndist data: dyn %" PRId64 ", stat %" PRId64, s->opt_len,
s->static_len)); s->static_len));
/* At this point, opt_len and static_len are the total bit lengths of /* At this point, opt_len and static_len are the total bit lengths of
* the compressed block data, excluding the tree representations. * the compressed block data, excluding the tree representations.
@@ -946,21 +868,24 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
opt_lenb = (s->opt_len+3+7)>>3; opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3; static_lenb = (s->static_len+3+7)>>3;
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", Tracev((stderr, "\nopt %" PRIu64 "(%" PRIu64 ") stat %" PRIu64 "(%" PRIu64 ") stored %" PRIu64 " lit %u ",
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->sym_next / 3)); s->sym_next / 3));
if (static_lenb <= opt_lenb) opt_lenb = static_lenb; #ifndef FORCE_STATIC
if (static_lenb <= opt_lenb || s->strategy == Z_FIXED)
#endif
opt_lenb = static_lenb;
} else { } else {
Assert(buf != (char*)0, "lost buf"); Assert(buf != (uint8_t*)0, "lost buf");
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
} }
#ifdef FORCE_STORED #ifdef FORCE_STORED
if (buf != (char*)0) { /* force stored block */ if (buf != NULL) { /* force stored block */
#else #else
if (stored_len+4 <= opt_lenb && buf != (char*)0) { if (stored_len+4 <= opt_lenb && buf != NULL) {
/* 4: two words for the lengths */ /* 4: two words for the lengths */
#endif #endif
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
@@ -971,11 +896,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
*/ */
_tr_stored_block(s, buf, stored_len, last); _tr_stored_block(s, buf, stored_len, last);
#ifdef FORCE_STATIC } else if (static_lenb == opt_lenb) {
} 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); send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree, compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree); (const ct_data *)static_dtree);
@@ -993,9 +914,6 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
#endif #endif
} }
Assert (s->compressed_len == s->bits_sent, "bad compressed size"); 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); init_block(s);
if (last) { if (last) {
@@ -1004,7 +922,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
s->compressed_len += 7; /* align on byte boundary */ s->compressed_len += 7; /* align on byte boundary */
#endif #endif
} }
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, Tracev((stderr,"\ncomprlen %" PRIu64 "(%" PRIu64 ") ", s->compressed_len>>3,
s->compressed_len-7*last)); s->compressed_len-7*last));
} }
@@ -1012,14 +930,11 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
* Save the match info and tally the frequency counts. Return true if * Save the match info and tally the frequency counts. Return true if
* the current block must be flushed. * the current block must be flushed.
*/ */
int ZLIB_INTERNAL _tr_tally (s, dist, lc) 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) */
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++] = dist; s->sym_buf[s->sym_next++] = (uint16_t)dist;
s->sym_buf[s->sym_next++] = dist >> 8; s->sym_buf[s->sym_next++] = (uint16_t)dist >> 8;
s->sym_buf[s->sym_next++] = lc; s->sym_buf[s->sym_next++] = (uint8_t)lc;
if (dist == 0) { if (dist == 0) {
/* lc is the unmatched char */ /* lc is the unmatched char */
s->dyn_ltree[lc].Freq++; s->dyn_ltree[lc].Freq++;
@@ -1027,9 +942,9 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
s->matches++; s->matches++;
/* Here, lc is the match length - MIN_MATCH */ /* Here, lc is the match length - MIN_MATCH */
dist--; /* dist = match distance - 1 */ dist--; /* dist = match distance - 1 */
Assert((ush)dist < (ush)MAX_DIST(s) && Assert((uint16_t)dist < (ush)MAX_DIST(s) &&
(ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && (uint16_t)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
(ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); (uint16_t)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
s->dyn_dtree[d_code(dist)].Freq++; s->dyn_dtree[d_code(dist)].Freq++;
@@ -1040,10 +955,7 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
/* =========================================================================== /* ===========================================================================
* Send the block data compressed using the given Huffman trees * Send the block data compressed using the given Huffman trees
*/ */
local void compress_block(s, ltree, dtree) static void compress_block(deflate_state *s, const ct_data *ltree, /* literal tree */ const ct_data *dtree) /* distance tree */
deflate_state *s;
const ct_data *ltree; /* literal tree */
const ct_data *dtree; /* distance tree */
{ {
unsigned dist; /* distance of matched string */ unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */ int lc; /* match length or unmatched char (if dist == 0) */
@@ -1051,31 +963,115 @@ local void compress_block(s, ltree, dtree)
unsigned code; /* the code to send */ unsigned code; /* the code to send */
int extra; /* number of extra bits 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 { if (s->sym_next != 0) do {
dist = s->sym_buf[sx++] & 0xff; dist = s->sym_buf[sx++] & 0xff;
dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
lc = s->sym_buf[sx++]; lc = s->sym_buf[sx++];
if (dist == 0) { if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */ 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);
}
Tracecv(isgraph(lc), (stderr," '%c' ", lc)); Tracecv(isgraph(lc), (stderr," '%c' ", lc));
} else { } else {
uint64_t val ;
int len ;
/* Here, lc is the match length - MIN_MATCH */ /* Here, lc is the match length - MIN_MATCH */
code = _length_code[lc]; code = _length_code[lc];
send_code(s, code+LITERALS+1, ltree); /* send the length code */
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);
}
extra = extra_lbits[code]; extra = extra_lbits[code];
if (extra != 0) { if (extra != 0) {
lc -= base_length[code]; lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */ 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);
}
} }
dist--; /* dist is now the match distance - 1 */ dist--; /* dist is now the match distance - 1 */
code = d_code(dist); code = d_code(dist);
Assert (code < D_CODES, "bad d_code"); 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]; extra = extra_dbits[code];
if (extra != 0) { if (extra != 0) {
dist -= (unsigned)base_dist[code]; dist -= base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
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);
}
} }
} /* literal or match pair ? */ } /* literal or match pair ? */
@@ -1084,7 +1080,26 @@ local void compress_block(s, ltree, dtree)
} while (sx < s->sym_next); } while (sx < s->sym_next);
send_code(s, END_BLOCK, ltree); 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;
} }
/* =========================================================================== /* ===========================================================================
@@ -1100,8 +1115,7 @@ local void compress_block(s, ltree, dtree)
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
* IN assertion: the fields Freq of dyn_ltree are set. * IN assertion: the fields Freq of dyn_ltree are set.
*/ */
local int detect_data_type(s) static int detect_data_type(deflate_state *s)
deflate_state *s;
{ {
/* block_mask is the bit mask of block-listed bytes /* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31 * set bits 0..6, 14..25, and 28..31
@@ -1134,9 +1148,9 @@ local int detect_data_type(s)
* method would use a table) * method would use a table)
* IN assertion: 1 <= len <= 15 * IN assertion: 1 <= len <= 15
*/ */
local unsigned bi_reverse(code, len) static unsigned bi_reverse(unsigned code, /* the value to invert */
unsigned code; /* the value to invert */ int len) /* its bit length */
int len; /* its bit length */
{ {
register unsigned res = 0; register unsigned res = 0;
do { do {
@@ -1149,14 +1163,14 @@ local unsigned bi_reverse(code, len)
/* =========================================================================== /* ===========================================================================
* Flush the bit buffer, keeping at most 7 bits in it. * Flush the bit buffer, keeping at most 7 bits in it.
*/ */
local void bi_flush(s) static void bi_flush(deflate_state *s)
deflate_state *s;
{ {
if (s->bi_valid == 16) { while (s->bi_valid >= 16) {
put_short(s, s->bi_buf); put_short(s, s->bi_buf);
s->bi_buf = 0; s->bi_buf >>= 16;
s->bi_valid = 0; s->bi_valid -= 16;
} else if (s->bi_valid >= 8) { }
if (s->bi_valid >= 8) {
put_byte(s, (Byte)s->bi_buf); put_byte(s, (Byte)s->bi_buf);
s->bi_buf >>= 8; s->bi_buf >>= 8;
s->bi_valid -= 8; s->bi_valid -= 8;
@@ -1166,9 +1180,13 @@ local void bi_flush(s)
/* =========================================================================== /* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary * Flush the bit buffer and align the output on a byte boundary
*/ */
local void bi_windup(s) static void bi_windup(deflate_state *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) { if (s->bi_valid > 8) {
put_short(s, s->bi_buf); put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) { } else if (s->bi_valid > 0) {
@@ -1180,3 +1198,26 @@ local void bi_windup(s)
s->bits_sent = (s->bits_sent+7) & ~7; s->bits_sent = (s->bits_sent+7) & ~7;
#endif #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
View File

@@ -24,12 +24,8 @@
Z_DATA_ERROR if the input data was corrupted, including if the input data is Z_DATA_ERROR if the input data was corrupted, including if the input data is
an incomplete zlib stream. an incomplete zlib stream.
*/ */
int ZEXPORT uncompress2 (dest, destLen, source, sourceLen) int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong *sourceLen) {
uLongf *destLen;
const Bytef *source;
uLong *sourceLen;
{
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1; const uInt max = (uInt)-1;
@@ -83,11 +79,7 @@ int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
err; err;
} }
int ZEXPORT uncompress (dest, destLen, source, sourceLen) int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong sourceLen) {
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return uncompress2(dest, destLen, source, &sourceLen); return uncompress2(dest, destLen, source, &sourceLen);
} }

81
deps/zlib/zconf.h vendored
View File

@@ -7,7 +7,7 @@
#ifndef ZCONF_H #ifndef ZCONF_H
#define ZCONF_H #define ZCONF_H
#include <stdint.h>
/* /*
* If you *really* need a unique prefix for all types and library functions, * 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. * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
@@ -29,7 +29,6 @@
# define adler32 z_adler32 # define adler32 z_adler32
# define adler32_combine z_adler32_combine # define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64 # define adler32_combine64 z_adler32_combine64
# define adler32_z z_adler32_z
# ifndef Z_SOLO # ifndef Z_SOLO
# define compress z_compress # define compress z_compress
# define compress2 z_compress2 # define compress2 z_compress2
@@ -38,14 +37,10 @@
# define crc32 z_crc32 # define crc32 z_crc32
# define crc32_combine z_crc32_combine # define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64 # define crc32_combine64 z_crc32_combine64
# define crc32_z z_crc32_z
# define deflate z_deflate # define deflate z_deflate
# define deflateBound z_deflateBound # define deflateBound z_deflateBound
# define deflateCopy z_deflateCopy # define deflateCopy z_deflateCopy
# define deflateEnd z_deflateEnd # define deflateEnd z_deflateEnd
# define deflateGetDictionary z_deflateGetDictionary
# define deflateInit z_deflateInit
# define deflateInit2 z_deflateInit2
# define deflateInit2_ z_deflateInit2_ # define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_ # define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams # define deflateParams z_deflateParams
@@ -72,8 +67,6 @@
# define gzeof z_gzeof # define gzeof z_gzeof
# define gzerror z_gzerror # define gzerror z_gzerror
# define gzflush z_gzflush # define gzflush z_gzflush
# define gzfread z_gzfread
# define gzfwrite z_gzfwrite
# define gzgetc z_gzgetc # define gzgetc z_gzgetc
# define gzgetc_ z_gzgetc_ # define gzgetc_ z_gzgetc_
# define gzgets z_gzgets # define gzgets z_gzgets
@@ -85,6 +78,7 @@
# define gzopen_w z_gzopen_w # define gzopen_w z_gzopen_w
# endif # endif
# define gzprintf z_gzprintf # define gzprintf z_gzprintf
# define gzvprintf z_gzvprintf
# define gzputc z_gzputc # define gzputc z_gzputc
# define gzputs z_gzputs # define gzputs z_gzputs
# define gzread z_gzread # define gzread z_gzread
@@ -95,39 +89,32 @@
# define gztell z_gztell # define gztell z_gztell
# define gztell64 z_gztell64 # define gztell64 z_gztell64
# define gzungetc z_gzungetc # define gzungetc z_gzungetc
# define gzvprintf z_gzvprintf
# define gzwrite z_gzwrite # define gzwrite z_gzwrite
# endif # endif
# define inflate z_inflate # define inflate z_inflate
# define inflateBack z_inflateBack # define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd # define inflateBackEnd z_inflateBackEnd
# define inflateBackInit z_inflateBackInit
# define inflateBackInit_ z_inflateBackInit_ # define inflateBackInit_ z_inflateBackInit_
# define inflateCodesUsed z_inflateCodesUsed
# define inflateCopy z_inflateCopy # define inflateCopy z_inflateCopy
# define inflateEnd z_inflateEnd # define inflateEnd z_inflateEnd
# define inflateGetDictionary z_inflateGetDictionary
# define inflateGetHeader z_inflateGetHeader # define inflateGetHeader z_inflateGetHeader
# define inflateInit z_inflateInit
# define inflateInit2 z_inflateInit2
# define inflateInit2_ z_inflateInit2_ # define inflateInit2_ z_inflateInit2_
# define inflateInit_ z_inflateInit_ # define inflateInit_ z_inflateInit_
# define inflateMark z_inflateMark # define inflateMark z_inflateMark
# define inflatePrime z_inflatePrime # define inflatePrime z_inflatePrime
# define inflateReset z_inflateReset # define inflateReset z_inflateReset
# define inflateReset2 z_inflateReset2 # define inflateReset2 z_inflateReset2
# define inflateResetKeep z_inflateResetKeep
# define inflateSetDictionary z_inflateSetDictionary # define inflateSetDictionary z_inflateSetDictionary
# define inflateGetDictionary z_inflateGetDictionary
# define inflateSync z_inflateSync # define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint # define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine # define inflateUndermine z_inflateUndermine
# define inflateValidate z_inflateValidate # define inflateResetKeep z_inflateResetKeep
# define inflate_copyright z_inflate_copyright # define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast # define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table # define inflate_table z_inflate_table
# ifndef Z_SOLO # ifndef Z_SOLO
# define uncompress z_uncompress # define uncompress z_uncompress
# define uncompress2 z_uncompress2
# endif # endif
# define zError z_zError # define zError z_zError
# ifndef Z_SOLO # ifndef Z_SOLO
@@ -237,19 +224,24 @@
# define z_const # define z_const
#endif #endif
#ifdef Z_SOLO #ifndef Z_SOLO
typedef unsigned long z_size_t; # ifdef NO_SIZE_T
#else
# define z_longlong long long
# if defined(NO_SIZE_T)
typedef unsigned NO_SIZE_T z_size_t; typedef unsigned NO_SIZE_T z_size_t;
# elif defined(STDC) # else
# include <stddef.h> # include <stddef.h>
typedef size_t z_size_t; typedef size_t z_size_t;
# else
typedef unsigned long z_size_t;
# endif # endif
# undef z_longlong # 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
# endif
#endif #endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
@@ -279,28 +271,10 @@
Of course this will generally degrade compression (there's no free lunch). Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects. 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 /* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations). * model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have * This was tested only with MSC; for other MSDOS compilers you may have
@@ -349,6 +323,9 @@
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
@@ -388,10 +365,10 @@
#endif #endif
#if !defined(__MACTYPES__) #if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */ typedef uint8_t Byte; /* 8 bits */
#endif #endif
typedef unsigned int uInt; /* 16 bits or more */ typedef uint32_t uInt; /* 32 bits */
typedef unsigned long uLong; /* 32 bits or more */ typedef uint64_t uLong; /* 64 bits */
#ifdef SMALL_MEDIUM #ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
@@ -472,7 +449,11 @@ typedef uLong FAR uLongf;
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) # if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # 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
# ifdef VMS # ifdef VMS
# include <unixio.h> /* for off_t */ # include <unixio.h> /* for off_t */
# endif # endif
@@ -507,7 +488,7 @@ typedef uLong FAR uLongf;
#if !defined(_WIN32) && defined(Z_LARGE64) #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#else #else
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) # if defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64 # define z_off64_t __int64
# else # else
# define z_off64_t z_off_t # define z_off64_t z_off_t

513
deps/zlib/zlib.h vendored

File diff suppressed because it is too large Load Diff

94
deps/zlib/zutil.c vendored
View File

@@ -11,26 +11,23 @@
#endif #endif
z_const char * const z_errmsg[10] = { z_const char * const z_errmsg[10] = {
(z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ "need dictionary", /* Z_NEED_DICT 2 */
(z_const char *)"stream end", /* Z_STREAM_END 1 */ "stream end", /* Z_STREAM_END 1 */
(z_const char *)"", /* Z_OK 0 */ "", /* Z_OK 0 */
(z_const char *)"file error", /* Z_ERRNO (-1) */ "file error", /* Z_ERRNO (-1) */
(z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */ "stream error", /* Z_STREAM_ERROR (-2) */
(z_const char *)"data error", /* Z_DATA_ERROR (-3) */ "data error", /* Z_DATA_ERROR (-3) */
(z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */ "insufficient memory", /* Z_MEM_ERROR (-4) */
(z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */ "buffer error", /* Z_BUF_ERROR (-5) */
(z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ "incompatible version",/* Z_VERSION_ERROR (-6) */
(z_const char *)"" ""};
};
const char * ZEXPORT zlibVersion() const char * ZEXPORT zlibVersion(void) {
{
return ZLIB_VERSION; return ZLIB_VERSION;
} }
uLong ZEXPORT zlibCompileFlags() uLong ZEXPORT zlibCompileFlags(void) {
{
uLong flags; uLong flags;
flags = 0; flags = 0;
@@ -119,9 +116,7 @@ uLong ZEXPORT zlibCompileFlags()
# endif # endif
int ZLIB_INTERNAL z_verbose = verbose; int ZLIB_INTERNAL z_verbose = verbose;
void ZLIB_INTERNAL z_error (m) void ZLIB_INTERNAL z_error(char *m) {
char *m;
{
fprintf(stderr, "%s\n", m); fprintf(stderr, "%s\n", m);
exit(1); exit(1);
} }
@@ -130,9 +125,7 @@ void ZLIB_INTERNAL z_error (m)
/* exported to allow conversion of error code to string for compress() and /* exported to allow conversion of error code to string for compress() and
* uncompress() * uncompress()
*/ */
const char * ZEXPORT zError(err) const char * ZEXPORT zError(int err) {
int err;
{
return ERR_MSG(err); return ERR_MSG(err);
} }
@@ -146,22 +139,14 @@ const char * ZEXPORT zError(err)
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void ZLIB_INTERNAL zmemcpy(dest, source, len) void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
Bytef* dest;
const Bytef* source;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = *source++; /* ??? to be unrolled */ *dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0); } while (--len != 0);
} }
int ZLIB_INTERNAL zmemcmp(s1, s2, len) int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j; uInt j;
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
@@ -170,10 +155,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len)
return 0; return 0;
} }
void ZLIB_INTERNAL zmemzero(dest, len) void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
Bytef* dest;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = 0; /* ??? to be unrolled */ *dest++ = 0; /* ??? to be unrolled */
@@ -216,11 +198,9 @@ local ptr_table table[MAX_PTR];
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
{ {
voidpf buf; voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
(void)opaque;
/* If we allocate less than 65520 bytes, we assume that farmalloc /* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized. * will return a usable pointer which doesn't have to be normalized.
*/ */
@@ -240,12 +220,8 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
return buf; return buf;
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{
int n; int n;
(void)opaque;
if (*(ush*)&ptr != 0) { /* object < 64K */ if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr); farfree(ptr);
return; return;
@@ -261,6 +237,7 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
next_ptr--; next_ptr--;
return; return;
} }
ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found"); Assert(0, "zcfree: ptr not found");
} }
@@ -277,15 +254,13 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
# define _hfree hfree # define _hfree hfree
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
{ if (opaque) opaque = 0; /* to make compiler happy */
(void)opaque;
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{ if (opaque) opaque = 0; /* to make compiler happy */
(void)opaque;
_hfree(ptr); _hfree(ptr);
} }
@@ -297,27 +272,20 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc(uInt items, uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
voidpf opaque; if (opaque) items += size - size; /* make compiler happy */
unsigned items;
unsigned size;
{
(void)opaque;
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size); (voidpf)calloc(items, size);
} }
void ZLIB_INTERNAL zcfree (opaque, ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
voidpf opaque;
voidpf ptr;
{
(void)opaque;
free(ptr); free(ptr);
if (opaque) return; /* make compiler happy */
} }
#endif /* MY_ZCALLOC */ #endif /* MY_ZCALLOC */

30
deps/zlib/zutil.h vendored
View File

@@ -20,6 +20,7 @@
#endif #endif
#include "zlib.h" #include "zlib.h"
#include <stdint.h>
#if defined(STDC) && !defined(Z_SOLO) #if defined(STDC) && !defined(Z_SOLO)
# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
@@ -42,17 +43,6 @@ typedef unsigned short ush;
typedef ush FAR ushf; typedef ush FAR ushf;
typedef unsigned long ulg; 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 */ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */ /* (size given to avoid silly warnings with Visual C++) */
@@ -191,8 +181,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_WIN32) && \ #if !defined(_WIN32) && \
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
#endif #endif
/* common defaults */ /* common defaults */
@@ -231,16 +221,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define zmemzero(dest, len) memset(dest, 0, len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
# include <stdio.h> # include <stdio.h>
extern int ZLIB_INTERNAL z_verbose; extern int ZLIB_INTERNAL z_verbose;
extern void ZLIB_INTERNAL z_error OF((char *m)); extern void ZLIB_INTERNAL z_error(char *m);
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;}
@@ -257,9 +247,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
unsigned size)); unsigned size);
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
#endif #endif
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \