405 Commits

Author SHA1 Message Date
Izumi Raine
b98f0c9be4
Add tests for libdeflate_zlib_*
Adds programs/test_zlib.c which currently does the following:
1. Create some dummy data and compress it
2. Try to decompress with libdeflate_zlib_decompress
3. Try to decompress with libdeflate_zlib_decompress, with unnecessary
   trailing bytes after the compressed data
4. Try to decompress with libdeflate_zlib_decompress_ex, with
   unnecessary trailing bytes after the compressed data

In each step, we check that we get back the original data.
2020-04-17 18:29:31 +02:00
Izumi Raine
66606d7a4a
Clarify comments on zlib decompression functions 2020-04-16 18:23:47 +02:00
Izumi Raine
5ed95f48d4
Add function libdeflate_zlib_decompress_ex
Additionally, libdeflate_zlib_decompress now returns successfully in
case there are additional trailing bytes in the input buffer after the
compressed stream.
2020-04-16 18:15:11 +02:00
Eric Biggers
b255565de2 cirrus.yml: use working images 2020-04-15 21:52:44 -07:00
Eric Biggers
3107ae1f7e v1.5 v1.5 2019-12-28 13:33:41 -06:00
Eric Biggers
ecffc1f5fb Include libdeflate.def in Windows releases
... just in case someone needs it.
2019-12-28 13:33:41 -06:00
Eric Biggers
5d2fd6e515 Export stdcall functions as both suffixed and non-suffixed
The default is suffixed names, but some programming languages expect
non-suffixed names.

Resolves https://github.com/ebiggers/libdeflate/issues/59
2019-12-28 13:20:50 -06:00
Eric Biggers
3acda56db0 Declare __stdcall correctly for MSVC
Unfortunately, MSVC only accepts __stdcall after the return type, while
gcc only accepts __attribute__((visibility("default"))) before the
return type.  So we need a macro in each location.

Also, MSVC doesn't define __i386__; that's gcc specific.  So instead use
'_WIN32 && !_WIN64' to detect 32-bit Windows.
2019-12-28 13:20:50 -06:00
Eric Biggers
91e972e864 v1.4 v1.4 2019-12-27 10:48:44 -06:00
Eric Biggers
5f3830983c Use stdcall calling convention on 32-bit Windows
Not all programming languages support the cdecl calling convention.
stdcall is what the Win32 API uses, and it seems to be the better choice
for maximum compatibility with other programming languages.

So, switch from cdecl to stdcall.

Resolves https://github.com/ebiggers/libdeflate/issues/58
2019-12-27 10:48:44 -06:00
Roy Storey
faaad7b33f Test freebsd with cirrus-ci
[EB - changed script to use the new 'make check' target]
2019-08-30 15:59:43 -05:00
Eric Biggers
07cf1a7c87 README.md: add Travis CI badge 2019-08-30 15:56:07 -05:00
Eric Biggers
776cddc10f Add .travis.yml
Add a Travis CI configuration file which runs most tests on recent
Linux, and runs basic tests on older Linux, macOS, and Windows.
2019-08-30 00:14:43 -05:00
Eric Biggers
1a440dffea Makefile: build dylib on macOS
On macOS, shared libraries end in "$(SOVERSION).dylib", not
".so.$(SOVERSION)" like on Linux.  Also, a different linker option is
needed to set the equivalent of the soname.

This is based on patches from:

	Elmar Pruesse <elmar.pruesse@ucdenver.edu>
and
	Roy Storey <kiwiroy@users.noreply.github.com>

but refactored, and fixed to not break the Windows build.
2019-08-30 00:14:43 -05:00
Eric Biggers
e227dee9e6 Makefile: add 'make check' target
Add the standard 'make check' target, to run some quick tests.
2019-08-30 00:14:43 -05:00
Eric Biggers
09f14551d8 detect.sh: use -Wno-error
Don't let -Werror interfere with the feature detection.
2019-08-30 00:14:43 -05:00
Eric Biggers
a0f88e7787 checksum_benchmarks.sh: set pipefail
Otherwise, a build failure may go undetected.
2019-08-30 00:14:43 -05:00
Eric Biggers
7a05749937 checksum_benchmarks.sh: generate test data file automatically
To make the script easier to use, don't make the user provide an
external file.
2019-08-30 00:14:43 -05:00
Eric Biggers
7a72b4a94c run_tests.sh: generate SMOKEDATA file automatically
To make the script easier to use, don't make the user provide an
external file.
2019-08-30 00:14:43 -05:00
Eric Biggers
9dcdcd0085 gzip_tests.sh: address some shellcheck warnings 2019-08-30 00:14:43 -05:00
Eric Biggers
a89fd8251b gzip_tests.sh: add assert_equals() function 2019-08-30 00:14:43 -05:00
Eric Biggers
0015560a82 test_slow_decompression: skip by default since it's flaky
Since this is a performance-based test, unfortunately it's always going
to be flaky, so it needs to be skipped by default.
2019-08-30 00:14:43 -05:00
Eric Biggers
8474418509 test_util: make alloc_guarded_buffer() return void
Its return value is not checked, which is a bug.  But it's a test
utility, so it's better to exit on failure instead.
2019-08-30 00:14:43 -05:00
Eric Biggers
f1e56f54b2 test_util: use MAP_ANONYMOUS instead of /dev/zero
Apparently, mmap'ing /dev/zero fails on macOS.  So contrary to the
intent, it's not actually portable.  Switch to MAP_ANONYMOUS instead,
with a fallback to MAP_ANON if it's not defined.
2019-08-30 00:14:43 -05:00
Eric Biggers
2a2e24dc8b lib: fix some typos in comments 2019-08-24 17:38:50 -07:00
Eric Biggers
ab6ba9d521 Makefile: enable -Wimplicit-fallthrough 2019-08-15 23:06:24 -07:00
Eric Biggers
858751572e v1.3 v1.3 2019-08-11 17:36:38 -07:00
Eric Biggers
2bdbe040fe test_slow_decompression: make less flaky 2019-08-11 17:36:09 -07:00
Eric Biggers
c9ed42ae3b Makefile: improve portability of 'make install'
Resolves https://github.com/ebiggers/libdeflate/issues/47
2019-07-05 10:35:32 -07:00
Eric Biggers
debaabad37 Makefile: improve documentation for make options
Resolves https://github.com/ebiggers/libdeflate/issues/46
2019-07-02 20:13:13 -07:00
Eric Biggers
9e9b62f03f Makefile: change default PREFIX to /usr/local
Use the same default installation prefix as autotools-based projects.
2019-07-02 20:13:13 -07:00
Eric Biggers
5038748d61 lib/deflate_compress: fix return value for output >= 4 GiB
The API returns the compressed size as a size_t, so
deflate_flush_output() needs to return size_t as well, not u32.
Otherwise sizes >= 4 GiB are truncated.

This bug has been there since the beginning.

(This only matters if you compress a buffer that large in a single go,
which obviously is not a good idea, but no matter -- it's a bug.)

Resolves https://github.com/ebiggers/libdeflate/issues/44
2019-05-21 21:13:59 -07:00
Eric Biggers
e90463fb04 programs/gunzip: allocate at least one byte for decompressed data
libdeflate's 'gunzip' program fails if the uncompressed file size is a
nonzero multiple of 4 GiB because then the ISIZE field in the gzip file
is 0, so gunzip allocates no space for the decompressed data.  Then when
libdeflate returns LIBDEFLATE_INSUFFICIENT_SPACE, gunzip doubles the
buffer size which stays 0, causing it to report "file corrupt or too
large to be processed by this program".

While neither libdeflate nor its 'gunzip' program is designed for single
gzip streams this large anyway, this particular bug can easily be fixed
by always allocating at least one byte for the decompressed data.
2019-05-21 21:13:59 -07:00
Martin Mokrejs
bc40841abf Makefile: support overriding default optimization flags
Add the user-specified CFLAGS after the default optimization flags
rather than before, so that the default optimization flags can be
overridden.

[EB - updated comment and improved commit message]
2019-03-11 22:29:19 -07:00
Martin Mokrejs
96ce0ffcde Makefile: support custom BINDIR, INCDIR, and LIBDIR
The Makefile forced installation into $(PREFIX)/lib, e.g. /usr/lib.
But many distros use /usr/lib64 instead.

Therefore, allow specifying a custom BINDIR, INCDIR, and/or LIBDIR.

This allows the parent shell to call on Gentoo Linux:

    make install DESTDIR="${DESTDIR}/${EPREFIX}" LIBDIR=/usr/"$(get_libdir)"

[EB - improved commit message]
2019-03-11 21:46:42 -07:00
Eric Biggers
cb7ee82c22 v1.2 v1.2 2019-01-14 21:37:48 -08:00
Eric Biggers
f952b9acd5 run_tests.sh: update host whitelist 2019-01-14 21:37:48 -08:00
Eric Biggers
7512dfb845 test_incomplete_codes: add another test case 2019-01-14 21:37:48 -08:00
Eric Biggers
449b5adc16 lib/deflate_decompress: slight simplification in build_decode_table() 2019-01-14 21:37:48 -08:00
Eric Biggers
333eff73b2 tools/run_tests.sh: run all test programs in exec_tests.sh 2018-12-28 10:25:44 -06:00
Eric Biggers
d3878bc8ae programs: new test program - test_incomplete_codes 2018-12-28 10:25:44 -06:00
Eric Biggers
c398e237b6 programs: move output_bitstream to test_util 2018-12-28 10:25:44 -06:00
Eric Biggers
ce6a95f47b programs: add test_util
Move program utility functions that are used only by "test programs"
(i.e. not by gzip/gunzip) from prog_util.{c,h} into test_util.{c,h}.
This reduces the code that is compiled for the default build target,
which excludes the test programs.
2018-12-28 10:25:44 -06:00
Eric Biggers
a64bd1e830 lib/deflate_decompress: optimize build_decode_table() via table doubling
Another build_decode_table() optimization: rather than filling all the
entries for each codeword using strided stores, just fill one initially
and fill the rest by memcpy()s as the table is incrementally expanded.

Also make some other cleanups and small optimizations.
2018-12-27 17:10:23 -06:00
dawg
954b59041a Include stdlib.h for _byteswap_* on MSVC. 2018-12-26 10:23:14 -06:00
Eric Biggers
bfc3f610e1 lib/deflate_decompress: build subtables separately
Further improve build_decode_table() performance by splitting the "fill
direct entries" and "fill subtable pointers and subtables" steps into
separate loops and making some other optimizations.
2018-12-25 23:57:43 -06:00
Eric Biggers
515b7ad15c lib/deflate_decompress: move len_counts[] and offsets[] to stack
This improves performance, and these arrays are not very large.
2018-12-25 22:15:10 -06:00
Eric Biggers
1a3f34eab9 lib/deflate_decompress: optimize codeword incrementing 2018-12-25 21:29:13 -06:00
Eric Biggers
a25f3b86d7 lib/deflate_decompress: further optimize match copying 2018-12-25 18:14:32 -06:00
Orivej Desh
6750e4f19d Makefile: make the installation prefix configurable 2018-12-25 14:40:48 -06:00