From 6141d21116692cd95c0c5dc17106758c372b9fc4 Mon Sep 17 00:00:00 2001 From: Konstantin Nosov Date: Fri, 14 Oct 2022 11:59:08 +0300 Subject: [PATCH] Updated for zlib 1.2.13 - Prepared patch for zlib in order to recover missing ASMV option - Updated build script for work with newer Visual C compiler, it can't work with "OLDCRT" option anymore, so - using staric CRT now - longest_match declaration in match.h should not be static ('local') --- README.md | 6 ++++++ Sources/match.h | 2 +- Sources/zlib_1.2.13.patch | 45 +++++++++++++++++++++++++++++++++++++++ build/package.sh | 2 +- build/zlib.rc | 2 +- build/zlibdll.project | 4 +++- test.sh | 8 +++---- zlib/readme.txt | 2 ++ 8 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 Sources/zlib_1.2.13.patch diff --git a/README.md b/README.md index 7a8305e..727186b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ is to making a file with contents looking like and linking zlib with this file instead of deflate.c. +#### Zlib 1.2.13 or newer + +Note: since zlib 1.2.13 (October 2022), ASMV option has been removed from zlib source, therefore there's no possibility to replace longest_match +function without patching the original source code. So, you'll need to apply patch to the zlib source code in order to make things buildable. You +may find the patch in Sources/zlib_1.2.13.patch. + ### Building a 32-bit assembly version diff --git a/Sources/match.h b/Sources/match.h index d9cf87f..8563b36 100644 --- a/Sources/match.h +++ b/Sources/match.h @@ -20,7 +20,7 @@ /* Please retain this line */ const char fast_lm_copyright[] = " Fast match finder for zlib, https://github.com/gildor2/fast_zlib "; -local uInt longest_match(s, cur_match) +uInt longest_match(s, cur_match) deflate_state *s; IPos cur_match; /* current match */ { diff --git a/Sources/zlib_1.2.13.patch b/Sources/zlib_1.2.13.patch new file mode 100644 index 0000000..ba5eff7 --- /dev/null +++ b/Sources/zlib_1.2.13.patch @@ -0,0 +1,45 @@ +diff -Nrw -U5 original/deflate.c patched/deflate.c +--- original/deflate.c 2022-10-13 08:06:55 +0300 ++++ patched/deflate.c 2022-10-14 11:25:54 +0300 +@@ -85,11 +85,15 @@ + local block_state deflate_huff OF((deflate_state *s, int flush)); + local void lm_init OF((deflate_state *s)); + local void putShortMSB OF((deflate_state *s, uInt b)); + local void flush_pending OF((z_streamp strm)); + local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); ++#ifndef ASMV + local uInt longest_match OF((deflate_state *s, IPos cur_match)); ++#else ++uInt longest_match OF((deflate_state *s, IPos cur_match)); ++#endif + + #ifdef ZLIB_DEBUG + local void check_match OF((deflate_state *s, IPos start, IPos match, + int length)); + #endif +@@ -1263,10 +1267,12 @@ + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; + } + ++#ifndef ASMV ++ + #ifndef FASTEST + /* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is +@@ -1480,10 +1486,12 @@ + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; + } + + #endif /* FASTEST */ + ++#endif ++ + #ifdef ZLIB_DEBUG + + #define EQUAL 0 + /* result of memcmp for equal strings */ + diff --git a/build/package.sh b/build/package.sh index 8367653..78a7b77 100644 --- a/build/package.sh +++ b/build/package.sh @@ -46,7 +46,7 @@ contains minizip library. To use winapi DLL you should add define ZLIB_WINAPI be Konstantin Nosov https://github.com/gildor2/fast_zlib -http://www.gildor.org +https://www.gildor.org/ EOF echo "Now \"tmp\" directory contains data for zipping." diff --git a/build/zlib.rc b/build/zlib.rc index d42b425..73bceff 100644 --- a/build/zlib.rc +++ b/build/zlib.rc @@ -36,7 +36,7 @@ BEGIN VALUE "ProductName", "zlib\0" VALUE "ProductVersion", ZLIB_VERSION "\0" VALUE "Comments","Fast deflate version by Konstantin Nosov, www.gildor.org\0" - VALUE "LegalCopyright", "(C) 1995-2017 Jean-loup Gailly & Mark Adler\0" + VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0" END END BLOCK "VarFileInfo" diff --git a/build/zlibdll.project b/build/zlibdll.project index 439ec63..a651ebe 100644 --- a/build/zlibdll.project +++ b/build/zlibdll.project @@ -4,7 +4,7 @@ LIBC = shared CONSOLE = 1 OPTIMIZE = speed PDB = 2 -OLDCRT = 1 +OLDCRT = 0 R = .. # root directory of the project ZLIB = $R/zlib @@ -21,6 +21,8 @@ DLLDIR = $R/build/binaries/$PLATFORM-$CONV DEFINES += OLDCRT vsnprintf=_vsnprintf # define vsnprintf to use underscore version of the function because non-underscore is unavailable in msvcrt WDKCRT = $R/../Libs/msvcrt !include $WDKCRT/msvcrt.project + !else + LIBC = static !endif !endif diff --git a/test.sh b/test.sh index 4c6eba4..faf20a0 100644 --- a/test.sh +++ b/test.sh @@ -137,9 +137,7 @@ function DoTests if [ "$dir" ]; then DoTests "$dir" else - DoTests C:/Projects/Epic/UnrealEngine4-latest/Engine/Source --exclude=ThirdParty - DoTests C:/3-UnrealEngine/UE_4.18/Engine/Binaries/Win64 - DoTests C:/1 -# DoTests C:/Data/Images -# DoTests C:/Downloads/torrent/Trollhunters + DoTests D:/EpicGames/UE_5.0/Engine/Source --exclude=ThirdParty + DoTests D:/EpicGames/UE_5.0/Engine/Binaries/Win64 + DoTests D:/!unsorted/silesia fi diff --git a/zlib/readme.txt b/zlib/readme.txt index 3ca8737..5a8eed7 100644 --- a/zlib/readme.txt +++ b/zlib/readme.txt @@ -1 +1,3 @@ Put extracted zlib sources here. + +Note: starting with zlib 1.2.13 you'll need to apply patch to make code buildable, you may find it in Sources/zlib_1.2.13.patch