Disable zlib-ng internal tests when BUILD_SHARED_LIBS=ON.
When BUILD_SHARED_LIBS=ON some zlib-ng internal functions are not exported,
which are used by gtest_zlib and benchmark_zlib. Therefore, we must disable
those tests/projects.
Replace __builtin_ctz[ll] fallback functions with branchless implementations.
Added debug assert check for value = 0.
Added more details to the comment to avoid future confusion.
Added fallback logic for older MSVC versions, just in case.
This should reduce the cost of indirection that occurs when calling functable
chunk copying functions inside inflate_fast. It should also allow the compiler
to optimize the inflate fast path for the specific architecture.
Mark Adler [Thu, 15 Dec 2022 17:07:13 +0000 (09:07 -0800)]
Fix bug in deflateBound() for level 0 and memLevel 9.
memLevel 9 would cause deflateBound() to assume the use of fixed
blocks, even if the compression level was 0, which forces stored
blocks. That could result in a bound less than the size of the
compressed data. Now level 0 always uses the stored blocks bound.
Mika Lindqvist [Sat, 21 Jan 2023 23:16:11 +0000 (01:16 +0200)]
Allow disabling visibility attribute with configure
* Disable visibility check for Cygwin, MinGW and MSYS as the compiler will only issue warning instead of error for unsupported attributes.
Fix ABI checking...
* Ubuntu 22.04 use different format for ABI files so old ones need to be removed
* Use more recent zlib-ng commit to avoid issues with internal adler32 and crc32 functions
Pavel P [Fri, 13 Jan 2023 18:31:48 +0000 (21:31 +0300)]
Fix compilation error where `crc32_fold` type matches field name in struct functable_s
If functable.h is included by a c++ compiler, compiler issues the following error (VS 2022):
```
zlib-ng/functable.h(20,49): error C2327: 'functable_s::crc32_fold': is not a type name, static, or enumerator
```
The error happens on line 20 because on previous line crc32_fold is declared as a struct member. Using `struct crc32_fold_s` instead of `crc32_fold` fixes the error.
Ilya Leoshkevich [Thu, 20 Oct 2022 00:28:47 +0000 (02:28 +0200)]
IBM zSystems DFLTCC: Support inflate with small window
There is no hardware control for DFLTCC window size, and because of
that supporting small windows for deflate is not trivial: one has to
make sure that DFLTCC does not emit large distances, which most likely
entails somehow trimming the window and/or input in order to make sure
that whave + avail_in <= wsize.
But inflate is much easier: one only has to allocate enough space. Do
that in dfltcc_alloc_window(), and also introduce ZCOPY_WINDOW() in
order to copy everything, not just what the software implementation
cares about.
After this change, software and hardware window formats no longer
match: the software will use wbits and wsize, and the hardware will use
HB_BITS and HB_SIZE. Unlike deflate, inflate does not switch between
software and hardware implementations mid-stream, which leaves only
inflateSetDictionary() and inflateGetDictionary() interesting.
Use CMake detection for Emscripten due to a bug in vcpkg.
When installing for wasm32 with vcpkg, CMake's try_run does not end up running
with the correct compiler. This issue has been mention in a few existing vcpkg
portfiles.
Alternatively, we could check the VCPKG_TARGET_ARCHITECTURE variable for wasm32
but instead we check for EMSCRIPTEN CMake variable.
This patch adds the ability to run zlib-ng test suite against the
original zlib as follows:
cmake -DZLIB_COMPAT=ON -DZLIBNG_ENABLE_TESTS=OFF .
make
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu make test
The benefit of this is that modifications to the original zlib can be
tested with a more extensive zlib-ng's testsuite, and the assumptions
that the zlib-ng tests make can be validated against the original zlib.
In addition to a number of tests that exercise purely zlib-ng specific
API, there are a few that expect zlib-ng specific behavior from the
original zlib API:
- deflate() (obviously) emits different streams
- zlib-ng's deflatePrime() can take more than 16 bits
- zVersion() returns a different string
Adjust or disable the respective tests for ZLIBNG_ENABLE_TESTS=OFF.
Ilya Leoshkevich [Thu, 20 Oct 2022 04:28:44 +0000 (06:28 +0200)]
Fix deflate() with Z_BEST_COMPRESSION ignoring the dictionary
deflate_slow() uses s->quick_insert_string(), while
deflateSetDictionary() uses functable.insert_string(). These functions
use different hashing algorithms, which leads to deflate_slow()
ignoring the dictionary.
Fix by using s->insert_string() instead of functable.insert_string(),
which is set by lm_set_level() and matches what deflate_*() uses
(suggested by Mika Lindqvist).
Mika Lindqvist [Wed, 5 Oct 2022 10:58:28 +0000 (13:58 +0300)]
Fix memcpy() overflow in adler32_fold.c and crc32_fold.c
* On 32-bit platforms, last parameter of memcpy() is limited to SSIZE_MAX, but is likely to overlap if used