Skip to content

Commit

Permalink
Merge branch 'zlib-ng'
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Oct 15, 2021
2 parents b1a0a91 + 8daf9ef commit 23082f0
Show file tree
Hide file tree
Showing 20 changed files with 230 additions and 183 deletions.
6 changes: 3 additions & 3 deletions Modules/ThirdParty/ZLIB/UpdateFromUpstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ shopt -s dotglob
readonly name="zlib-ng"
readonly ownership="Zlib-ng Upstream <kwrobot@kitware.com>"
readonly subtree="Modules/ThirdParty/ZLIB/src/itk$name"
readonly repo="https://github.com/dzenanz/zlib-ng.git"
readonly repo="https://github.com/zlib-ng/zlib-ng.git"
readonly tag="develop"
readonly paths="
CMakeLists.txt
Expand All @@ -24,9 +24,9 @@ zlib_name_mangling.h.empty
zlib.pc.cmakein
zlib.map
win32/zlibcompat.def
win32/zlibcompat.def.in
win32/zlib1.rc
win32/zlib.def
win32/zlib.def.in
.gitattributes
README.md
Expand Down
2 changes: 2 additions & 0 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/.gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.c text
*.h text
Makefile text
configure text eol=lf
testCVEinputs.sh text eol=lf
4 changes: 2 additions & 2 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/crc32-vx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* relicensed under the zlib license.
*/

#include "../../zutil.h"
#include "../../crc32_p.h"
#include "zutil.h"
#include "crc32_p.h"

#include <vecintrin.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* dfltcc_deflate.c - IBM Z DEFLATE CONVERSION CALL general support. */

#include "../../zbuild.h"
#include "zbuild.h"
#include "dfltcc_common.h"
#include "dfltcc_detail.h"

Expand Down
30 changes: 27 additions & 3 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/dfltcc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#define DFLTCC_COMMON_H

#ifdef ZLIB_COMPAT
#include "../../zlib.h"
#include "zlib.h"
#else
#include "../../zlib-ng.h"
#include "zlib-ng.h"
#endif
#include "../../zutil.h"
#include "zutil.h"

void Z_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size);
void Z_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size);
Expand All @@ -26,4 +26,28 @@ void Z_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w);

#define TRY_FREE_WINDOW dfltcc_free_window

#define DFLTCC_BLOCK_HEADER_BITS 3
#define DFLTCC_HLITS_COUNT_BITS 5
#define DFLTCC_HDISTS_COUNT_BITS 5
#define DFLTCC_HCLENS_COUNT_BITS 4
#define DFLTCC_MAX_HCLENS 19
#define DFLTCC_HCLEN_BITS 3
#define DFLTCC_MAX_HLITS 286
#define DFLTCC_MAX_HDISTS 30
#define DFLTCC_MAX_HLIT_HDIST_BITS 7
#define DFLTCC_MAX_SYMBOL_BITS 16
#define DFLTCC_MAX_EOBS_BITS 15
#define DFLTCC_MAX_PADDING_BITS 7

#define DEFLATE_BOUND_COMPLEN(source_len) \
((DFLTCC_BLOCK_HEADER_BITS + \
DFLTCC_HLITS_COUNT_BITS + \
DFLTCC_HDISTS_COUNT_BITS + \
DFLTCC_HCLENS_COUNT_BITS + \
DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \
(DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \
(source_len) * DFLTCC_MAX_SYMBOL_BITS + \
DFLTCC_MAX_EOBS_BITS + \
DFLTCC_MAX_PADDING_BITS) >> 3)

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
$ make
*/

#include "../../zbuild.h"
#include "../../zutil.h"
#include "../../deflate.h"
#include "../../trees_emit.h"
#include "zbuild.h"
#include "zutil.h"
#include "deflate.h"
#include "trees_emit.h"
#include "dfltcc_deflate.h"
#include "dfltcc_detail.h"

Expand Down Expand Up @@ -210,7 +210,7 @@ int Z_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *res
*strm->next_out = (unsigned char)state->bi_buf;
/* Honor history and check value */
param->nt = 0;
param->cv = state->wrap == 2 ? ZSWAP32(strm->adler) : strm->adler;
param->cv = state->wrap == 2 ? ZSWAP32(state->crc_fold.value) : strm->adler;

/* When opening a block, choose a Huffman-Table Type */
if (!param->bcf) {
Expand Down Expand Up @@ -241,7 +241,10 @@ int Z_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *res
state->bi_buf = 0; /* Avoid accessing next_out */
else
state->bi_buf = *strm->next_out & ((1 << state->bi_valid) - 1);
strm->adler = state->wrap == 2 ? ZSWAP32(param->cv) : param->cv;
if (state->wrap == 2)
state->crc_fold.value = ZSWAP32(param->cv);
else
strm->adler = param->cv;

/* Unmask the input data */
strm->avail_in += masked_avail_in;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ int Z_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned cha
#define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
do { \
if (dfltcc_can_deflate((strm))) \
(complen) = (3 + 5 + 5 + 4 + 19 * 3 + (286 + 30) * 7 + \
(source_len) * 16 + 15 + 7) >> 3; \
(complen) = DEFLATE_BOUND_COMPLEN(source_len); \
} while (0)

#define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
$ make
*/

#include "../../zbuild.h"
#include "../../zutil.h"
#include "../../inftrees.h"
#include "../../inflate.h"
#include "zbuild.h"
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "dfltcc_inflate.h"
#include "dfltcc_detail.h"

Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/s390.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../zutil.h"
#include "zutil.h"
#include "s390.h"

#include <sys/auxv.h>
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/s390.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef S390_H_
#define S390_H_

#include "../../zutil.h"
#include "zutil.h"

extern int s390_cpu_has_vx;

Expand Down
19 changes: 18 additions & 1 deletion Modules/ThirdParty/ZLIB/src/itkzlib-ng/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#define ZLIB_INTERNAL
#include "zbuild.h"
#include "zutil.h"
#if defined(ZLIB_COMPAT)
# include "zlib.h"
#else
# include "zlib-ng.h"
#endif

/* ===========================================================================
* Architecture-specific hooks.
*/
#ifdef S390_DFLTCC_DEFLATE
# include "arch/s390/dfltcc_common.h"
#else
/* Returns the upper bound on compressed data length based on uncompressed data length, assuming default settings.
* Zero means that arch-specific deflation code behaves identically to the regular zlib-ng algorithms. */
# define DEFLATE_BOUND_COMPLEN(source_len) 0
#endif

/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
Expand Down Expand Up @@ -73,6 +84,12 @@ int Z_EXPORT PREFIX(compress)(unsigned char *dest, z_size_t *destLen, const unsi
this function needs to be updated.
*/
z_size_t Z_EXPORT PREFIX(compressBound)(z_size_t sourceLen) {
z_size_t complen = DEFLATE_BOUND_COMPLEN(sourceLen);

if (complen > 0)
/* Architecture-specific code provided an upper bound. */
return complen + ZLIB_WRAPLEN;

#ifndef NO_QUICK_STRATEGY
/* Quick deflate strategy worse case is 9 bits per literal, rounded to nearest byte,
plus the size of block & gzip headers and footers */
Expand Down
1 change: 0 additions & 1 deletion Modules/ThirdParty/ZLIB/src/itkzlib-ng/deflate_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
/* Find the longest match, discarding those <= prev_length.
* At this point we have always match length < WANT_MIN_MATCH
*/

if (dist <= MAX_DIST(s) && dist > 0 && hash_head != 0) {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/ZLIB/src/itkzlib-ng/inffast.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void Z_INTERNAL zng_inflate_fast(PREFIX3(stream) *strm, unsigned long start) {
/* Detect if out and window point to the same memory allocation. In this instance it is
necessary to use safe chunk copy functions to prevent overwriting the window. If the
window is overwritten then future matches with far distances will fail to copy correctly. */
extra_safe = (out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize);
extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize);

/* decode literals and length/distances until end-of-block or not enough
input data or output space */
Expand Down
4 changes: 2 additions & 2 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,8 @@ int32_t Z_EXPORT PREFIX(inflateSync)(PREFIX3(stream) *strm) {
in = strm->total_in;
out = strm->total_out;
PREFIX(inflateReset)(strm);
strm->total_in = in;
strm->total_out = out;
strm->total_in = (z_size_t)in;
strm->total_out = (z_size_t)out;
state->flags = flags;
state->mode = TYPE;
return Z_OK;
Expand Down
61 changes: 0 additions & 61 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/win32/zlib.def

This file was deleted.

61 changes: 61 additions & 0 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/win32/zlib.def.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
; zlib data compression library
EXPORTS
; basic functions
@ZLIB_SYMBOL_PREFIX@zlibVersion
@ZLIB_SYMBOL_PREFIX@deflate
@ZLIB_SYMBOL_PREFIX@deflateEnd
@ZLIB_SYMBOL_PREFIX@inflate
@ZLIB_SYMBOL_PREFIX@inflateEnd
; advanced functions
@ZLIB_SYMBOL_PREFIX@deflateSetDictionary
@ZLIB_SYMBOL_PREFIX@deflateGetDictionary
@ZLIB_SYMBOL_PREFIX@deflateCopy
@ZLIB_SYMBOL_PREFIX@deflateReset
@ZLIB_SYMBOL_PREFIX@deflateParams
@ZLIB_SYMBOL_PREFIX@deflateTune
@ZLIB_SYMBOL_PREFIX@deflateBound
@ZLIB_SYMBOL_PREFIX@deflatePending
@ZLIB_SYMBOL_PREFIX@deflatePrime
@ZLIB_SYMBOL_PREFIX@deflateSetHeader
@ZLIB_SYMBOL_PREFIX@inflateSetDictionary
@ZLIB_SYMBOL_PREFIX@inflateGetDictionary
@ZLIB_SYMBOL_PREFIX@inflateSync
@ZLIB_SYMBOL_PREFIX@inflateCopy
@ZLIB_SYMBOL_PREFIX@inflateReset
@ZLIB_SYMBOL_PREFIX@inflateReset2
@ZLIB_SYMBOL_PREFIX@inflatePrime
@ZLIB_SYMBOL_PREFIX@inflateMark
@ZLIB_SYMBOL_PREFIX@inflateGetHeader
@ZLIB_SYMBOL_PREFIX@inflateBack
@ZLIB_SYMBOL_PREFIX@inflateBackEnd
@ZLIB_SYMBOL_PREFIX@zlibCompileFlags
; utility functions
@ZLIB_SYMBOL_PREFIX@compress
@ZLIB_SYMBOL_PREFIX@compress2
@ZLIB_SYMBOL_PREFIX@compressBound
@ZLIB_SYMBOL_PREFIX@uncompress
@ZLIB_SYMBOL_PREFIX@uncompress2
; large file functions
@ZLIB_SYMBOL_PREFIX@adler32_combine64
@ZLIB_SYMBOL_PREFIX@crc32_combine64
; checksum functions
@ZLIB_SYMBOL_PREFIX@adler32
@ZLIB_SYMBOL_PREFIX@adler32_z
@ZLIB_SYMBOL_PREFIX@crc32
@ZLIB_SYMBOL_PREFIX@crc32_z
@ZLIB_SYMBOL_PREFIX@adler32_combine
@ZLIB_SYMBOL_PREFIX@crc32_combine
; various hacks, don't look :)
@ZLIB_SYMBOL_PREFIX@deflateInit_
@ZLIB_SYMBOL_PREFIX@deflateInit2_
@ZLIB_SYMBOL_PREFIX@inflateInit_
@ZLIB_SYMBOL_PREFIX@inflateInit2_
@ZLIB_SYMBOL_PREFIX@inflateBackInit_
@ZLIB_SYMBOL_PREFIX@zError
@ZLIB_SYMBOL_PREFIX@inflateSyncPoint
@ZLIB_SYMBOL_PREFIX@get_crc_table
@ZLIB_SYMBOL_PREFIX@inflateUndermine
@ZLIB_SYMBOL_PREFIX@inflateValidate
@ZLIB_SYMBOL_PREFIX@inflateCodesUsed
@ZLIB_SYMBOL_PREFIX@inflateResetKeep
@ZLIB_SYMBOL_PREFIX@deflateResetKeep
Loading

0 comments on commit 23082f0

Please sign in to comment.