Compare commits

..
11 Commits
Author SHA1 Message Date
Yann ColletandGitHub 794ea1b0af Merge pull request #3984 from facebook/dev
v1.5.6
2024-03-21 15:05:51 -07:00
Yann ColletandGitHub 63779c7982 Merge pull request #3595 from facebook/dev
v1.5.5 last changes
2023-04-04 13:13:52 -07:00
Yann ColletandGitHub d507e02940 Merge pull request #3590 from facebook/dev
v1.5.5
2023-04-03 14:38:22 -07:00
Yann ColletandGitHub 73e19c4cf1 Merge pull request #3585 from facebook/dev
Preparation for release v1.5.5
2023-04-01 18:06:35 -07:00
Yann ColletandGitHub 945f27758c Merge pull request #3487 from facebook/dev
release v1.5.4
2023-02-09 16:41:50 -08:00
Felix HandteandGitHub e47e674cd0 Merge pull request #2995 from facebook/v1.5.2-rc
Zstandard v1.5.2
2022-01-20 16:17:18 -05:00
Yann ColletandGitHub 791626dfb9 Merge pull request #2942 from facebook/dev
update man pages for v1.5.1
2021-12-20 14:49:18 -08:00
Yann ColletandGitHub f4a541b021 Merge pull request #2941 from facebook/dev
v1.5.1
2021-12-20 13:49:33 -08:00
senandGitHub a488ba114e Zstd 1.5.0 Release
Zstd 1.5.0 Release
2021-05-14 10:59:34 -04:00
Felix HandteandGitHub e4558ffd1d Merge pull request #2515 from facebook/dev
ZStandard v1.4.9
2021-03-02 17:20:57 -05:00
Yann ColletandGitHub 97a3da1df0 Merge pull request #2435 from facebook/dev
v1.4.8 hotfix
2020-12-18 16:39:42 -08:00
60 changed files with 203 additions and 665 deletions
+1
View File
@@ -3,6 +3,7 @@ task:
freebsd_instance: freebsd_instance:
matrix: matrix:
image_family: freebsd-14-0 image_family: freebsd-14-0
image_family: freebsd-13-2
install_script: pkg install -y gmake coreutils install_script: pkg install -y gmake coreutils
script: | script: |
MOREFLAGS="-Werror" gmake -j all MOREFLAGS="-Werror" gmake -j all
+4 -4
View File
@@ -31,12 +31,12 @@ jobs:
run: make test run: make test
# lasts ~26mn # lasts ~26mn
make-test-macos: make-test-osx:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1 - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: make test on macos - name: OS-X test
run: make test run: make test # make -c lib all doesn't work because of the fact that it's not a tty
# lasts ~24mn # lasts ~24mn
make-test-32bit: make-test-32bit:
@@ -247,7 +247,7 @@ jobs:
shell: msys2 {0} shell: msys2 {0}
steps: steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1 - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- uses: msys2/setup-msys2@d0e80f58dffbc64f6a3a1f43527d469b4fc7b6c8 # tag=v2.23.0 - uses: msys2/setup-msys2@cc11e9188b693c2b100158c3322424c4cc1dadea # tag=v2.22.0
with: with:
msystem: MINGW64 msystem: MINGW64
install: make install: make
+1 -50
View File
@@ -237,50 +237,6 @@ jobs:
meson test -C builddir/ --print-errorlogs meson test -C builddir/ --print-errorlogs
meson install -C builddir --destdir staging/ meson install -C builddir --destdir staging/
meson-mingw-cross-compilation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: Install packages
run: |
sudo apt-get -qqq update
sudo apt-get -y install build-essential python3-pip ninja-build {gcc,g++}-mingw-w64-x86-64
pip install --pre meson
- name: Build with Meson
run: |
cat > cross.ini <<EOF
[binaries]
ar = 'x86_64-w64-mingw32-ar'
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ld = 'x86_64-w64-mingw32-ld'
objcopy = 'x86_64-w64-mingw32-objcopy'
objdump = 'x86_64-w64-mingw32-objdump'
strip = 'x86_64-w64-mingw32-strip'
windres = 'x86_64-w64-mingw32-windres'
[host_machine]
system = 'windows'
endian = 'little'
cpu_family = 'x86_64'
cpu = 'x86_64'
EOF
# pzstd doesn't build; skip -Dbin_contrib=true
meson setup \
--buildtype=debugoptimized \
--cross-file=cross.ini \
-Db_lundef=false \
-Dbin_programs=true \
-Dbin_tests=true \
-Ddefault_library=both \
build/meson builddir
ninja -C builddir/
if grep -- -pthread builddir/meson-private/libzstd.pc; then
echo "Error: found stray pthread dependency"
exit 1
fi
meson-windows: meson-windows:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
@@ -499,7 +455,7 @@ jobs:
shell: msys2 {0} shell: msys2 {0}
steps: steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1 - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- uses: msys2/setup-msys2@d0e80f58dffbc64f6a3a1f43527d469b4fc7b6c8 # tag=v2.23.0 - uses: msys2/setup-msys2@cc11e9188b693c2b100158c3322424c4cc1dadea # tag=v2.22.0
with: with:
msystem: ${{ matrix.msystem }} msystem: ${{ matrix.msystem }}
install: make diffutils install: make diffutils
@@ -576,11 +532,6 @@ jobs:
make -j allzstd && make -j allzstd &&
make -C tests fuzzer && make -C tests fuzzer &&
./tests/fuzzer.exe -v -T1m ./tests/fuzzer.exe -v -T1m
- name: cygwin install test
shell: C:\cygwin\bin\bash.exe --noprofile --norc -eo pipefail '{0}'
run: >-
make -j &&
make install
pkg-config: pkg-config:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+1 -1
View File
@@ -59,6 +59,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard. # Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning" - name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@c7f9125735019aa87cfc361530512d50ea439c71 # tag=v3.25.1 uses: github/codeql-action/upload-sarif@3ab4101902695724f9365a384f86c1074d94e18c # tag=v3.24.7
with: with:
sarif_file: results.sarif sarif_file: results.sarif
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
shell: msys2 {0} shell: msys2 {0}
steps: steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3 - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3
- uses: msys2/setup-msys2@d0e80f58dffbc64f6a3a1f43527d469b4fc7b6c8 # tag=v2.23.0 - uses: msys2/setup-msys2@5beef6d11f48bba68b9eb503e3adc60b23c0cc36 # tag=v2
with: with:
msystem: ${{ matrix.msystem }} msystem: ${{ matrix.msystem }}
install: make zlib git p7zip mingw-w64-${{matrix.env}}-gcc install: make zlib git p7zip mingw-w64-${{matrix.env}}-gcc
+2 -2
View File
@@ -3,7 +3,7 @@ api: Promote `ZSTD_c_targetCBlockSize` to Stable API by @felixhandte
api: new `ZSTD_d_maxBlockSize` experimental parameter, to reduce streaming decompression memory, by @terrelln api: new `ZSTD_d_maxBlockSize` experimental parameter, to reduce streaming decompression memory, by @terrelln
perf: improve performance of param `ZSTD_c_targetCBlockSize`, by @Cyan4973 perf: improve performance of param `ZSTD_c_targetCBlockSize`, by @Cyan4973
perf: improved compression of arrays of integers at high compression, by @Cyan4973 perf: improved compression of arrays of integers at high compression, by @Cyan4973
lib: reduce binary size with selective build-time exclusion, by @felixhandte lib: reduce binary size with selective built-time exclusion, by @felixhandte
lib: improved huffman speed on small data and linux kernel, by @terrelln lib: improved huffman speed on small data and linux kernel, by @terrelln
lib: accept dictionaries with partial literal tables, by @terrelln lib: accept dictionaries with partial literal tables, by @terrelln
lib: fix CCtx size estimation with external sequence producer, by @embg lib: fix CCtx size estimation with external sequence producer, by @embg
@@ -489,7 +489,7 @@ misc: added /contrib/docker script by @gyscos
v1.3.3 (Dec 21, 2017) v1.3.3 (Dec 21, 2017)
perf: faster zstd_opt strategy (levels 16-19) perf: faster zstd_opt strategy (levels 16-19)
fix : bug #944 : multithreading with shared dictionary and large data, reported by @gsliepen fix : bug #944 : multithreading with shared ditionary and large data, reported by @gsliepen
cli : fix : content size written in header by default cli : fix : content size written in header by default
cli : fix : improved LZ4 format support, by @felixhandte cli : fix : improved LZ4 format support, by @felixhandte
cli : new : hidden command `-S`, to benchmark multiple files while generating one result per file cli : new : hidden command `-S`, to benchmark multiple files while generating one result per file
+6 -6
View File
@@ -151,7 +151,7 @@ clean:
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# make install is validated only for Linux, macOS, Hurd and some BSD targets # make install is validated only for Linux, macOS, Hurd and some BSD targets
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT% CYGWIN_NT% Haiku AIX,$(shell sh -c 'MSYSTEM="MSYS" uname') )) ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT CYGWIN_NT Haiku AIX))
HOST_OS = POSIX HOST_OS = POSIX
@@ -293,10 +293,10 @@ regressiontest:
$(MAKE) -C $(FUZZDIR) regressiontest $(MAKE) -C $(FUZZDIR) regressiontest
uasanregressiontest: uasanregressiontest:
$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined -Werror" CXXFLAGS="-O3 -fsanitize=address,undefined -Werror" $(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
msanregressiontest: msanregressiontest:
$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory -Werror" CXXFLAGS="-O3 -fsanitize=memory -Werror" $(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
update_regressionResults : REGRESS_RESULTS_DIR := /tmp/regress_results_dir/ update_regressionResults : REGRESS_RESULTS_DIR := /tmp/regress_results_dir/
update_regressionResults: update_regressionResults:
@@ -390,19 +390,19 @@ lz4install:
endif endif
ifneq (,$(filter MSYS%,$(shell sh -c 'MSYSTEM="MSYS" uname') )) ifneq (,$(filter MSYS%,$(shell uname)))
HOST_OS = MSYS HOST_OS = MSYS
endif endif
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# target specific tests # target specific tests
#------------------------------------------------------------------------ #------------------------------------------------------------------------
ifneq (,$(filter MSYS POSIX,$(HOST_OS))) ifneq (,$(filter $(HOST_OS),MSYS POSIX))
CMAKE ?= cmake CMAKE ?= cmake
CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON
ifneq (,$(filter MSYS%,$(shell sh -c 'MSYSTEM="MSYS" uname'))) ifneq (,$(filter MSYS%,$(shell uname)))
CMAKE_PARAMS = -G"MSYS Makefiles" -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON CMAKE_PARAMS = -G"MSYS Makefiles" -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
endif endif
+14 -13
View File
@@ -29,10 +29,10 @@ a list of known ports and bindings is provided on [Zstandard homepage](https://f
## Benchmarks ## Benchmarks
For reference, several fast compression algorithms were tested and compared For reference, several fast compression algorithms were tested and compared
on a desktop featuring a Core i7-9700K CPU @ 4.9GHz on a desktop running Ubuntu 20.04 (`Linux 5.11.0-41-generic`),
and running Ubuntu 20.04 (`Linux ubu20 5.15.0-101-generic`), with a Core i7-9700K CPU @ 4.9GHz,
using [lzbench], an open-source in-memory benchmark by @inikep using [lzbench], an open-source in-memory benchmark by @inikep
compiled with [gcc] 9.4.0, compiled with [gcc] 9.3.0,
on the [Silesia compression corpus]. on the [Silesia compression corpus].
[lzbench]: https://github.com/inikep/lzbench [lzbench]: https://github.com/inikep/lzbench
@@ -41,23 +41,24 @@ on the [Silesia compression corpus].
| Compressor name | Ratio | Compression| Decompress.| | Compressor name | Ratio | Compression| Decompress.|
| --------------- | ------| -----------| ---------- | | --------------- | ------| -----------| ---------- |
| **zstd 1.5.6 -1** | 2.887 | 510 MB/s | 1580 MB/s | | **zstd 1.5.1 -1** | 2.887 | 530 MB/s | 1700 MB/s |
| [zlib] 1.2.11 -1 | 2.743 | 95 MB/s | 400 MB/s | | [zlib] 1.2.11 -1 | 2.743 | 95 MB/s | 400 MB/s |
| brotli 1.0.9 -0 | 2.702 | 395 MB/s | 430 MB/s | | brotli 1.0.9 -0 | 2.702 | 395 MB/s | 450 MB/s |
| **zstd 1.5.6 --fast=1** | 2.437 | 545 MB/s | 1890 MB/s | | **zstd 1.5.1 --fast=1** | 2.437 | 600 MB/s | 2150 MB/s |
| **zstd 1.5.6 --fast=3** | 2.239 | 650 MB/s | 2000 MB/s | | **zstd 1.5.1 --fast=3** | 2.239 | 670 MB/s | 2250 MB/s |
| quicklz 1.5.0 -1 | 2.238 | 525 MB/s | 750 MB/s | | quicklz 1.5.0 -1 | 2.238 | 540 MB/s | 760 MB/s |
| lzo1x 2.10 -1 | 2.106 | 650 MB/s | 825 MB/s | | **zstd 1.5.1 --fast=4** | 2.148 | 710 MB/s | 2300 MB/s |
| [lz4] 1.9.4 | 2.101 | 700 MB/s | 4000 MB/s | | lzo1x 2.10 -1 | 2.106 | 660 MB/s | 845 MB/s |
| lzf 3.6 -1 | 2.077 | 420 MB/s | 830 MB/s | | [lz4] 1.9.3 | 2.101 | 740 MB/s | 4500 MB/s |
| snappy 1.1.9 | 2.073 | 530 MB/s | 1660 MB/s | | lzf 3.6 -1 | 2.077 | 410 MB/s | 830 MB/s |
| snappy 1.1.9 | 2.073 | 550 MB/s | 1750 MB/s |
[zlib]: https://www.zlib.net/ [zlib]: https://www.zlib.net/
[lz4]: https://lz4.github.io/lz4/ [lz4]: https://lz4.github.io/lz4/
The negative compression levels, specified with `--fast=#`, The negative compression levels, specified with `--fast=#`,
offer faster compression and decompression speed offer faster compression and decompression speed
at the cost of compression ratio. at the cost of compression ratio (compared to level 1).
Zstd can also offer stronger compression ratios at the cost of compression speed. Zstd can also offer stronger compression ratios at the cost of compression speed.
Speed vs Compression trade-off is configurable by small increments. Speed vs Compression trade-off is configurable by small increments.
+21 -15
View File
@@ -2,7 +2,7 @@
IF "%1%" == "" GOTO display_help IF "%1%" == "" GOTO display_help
SETLOCAL ENABLEDELAYEDEXPANSION SETLOCAL
SET msbuild_version=%1 SET msbuild_version=%1
@@ -19,7 +19,7 @@ GOTO build
:display_help :display_help
echo Syntax: build.generic.cmd msbuild_version msbuild_platform msbuild_configuration msbuild_toolset echo Syntax: build.generic.cmd msbuild_version msbuild_platform msbuild_configuration msbuild_toolset
echo msbuild_version: VS installed version (latest, VS2012, VS2013, VS2015, VS2017, VS2019, ...) echo msbuild_version: VS installed version (VS2012, VS2013, VS2015, VS2017, VS2019, ...)
echo msbuild_platform: Platform (x64 or Win32) echo msbuild_platform: Platform (x64 or Win32)
echo msbuild_configuration: VS configuration (Release or Debug) echo msbuild_configuration: VS configuration (Release or Debug)
echo msbuild_toolset: Platform Toolset (v100, v110, v120, v140, v141, v142, ...) echo msbuild_toolset: Platform Toolset (v100, v110, v120, v140, v141, v142, ...)
@@ -29,23 +29,29 @@ EXIT /B 1
:build :build
SET msbuild="%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" SET msbuild="%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
SET msbuild_vs2017community="%programfiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
SET msbuild_vs2017professional="%programfiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
SET msbuild_vs2017enterprise="%programfiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe"
IF %msbuild_version% == VS2013 SET msbuild="%programfiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" IF %msbuild_version% == VS2013 SET msbuild="%programfiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe"
IF %msbuild_version% == VS2015 SET msbuild="%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" IF %msbuild_version% == VS2015 SET msbuild="%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
IF %msbuild_version% == VS2017 SET vswhere_params=-version [15,16) -products * IF %msbuild_version% == VS2017Community SET msbuild=%msbuild_vs2017community%
IF %msbuild_version% == VS2017Community SET vswhere_params=-version [15,16) -products Community IF %msbuild_version% == VS2017Professional SET msbuild=%msbuild_vs2017professional%
IF %msbuild_version% == VS2017Enterprise SET vswhere_params=-version [15,16) -products Enterprise IF %msbuild_version% == VS2017Enterprise SET msbuild=%msbuild_vs2017enterprise%
IF %msbuild_version% == VS2017Professional SET vswhere_params=-version [15,16) -products Professional IF %msbuild_version% == VS2017 (
IF %msbuild_version% == VS2019 SET vswhere_params=-version [16,17) -products * IF EXIST %msbuild_vs2017community% SET msbuild=%msbuild_vs2017community%
IF %msbuild_version% == VS2022 SET vswhere_params=-version [17,18) -products * IF EXIST %msbuild_vs2017professional% SET msbuild=%msbuild_vs2017professional%
REM Add the next Visual Studio version here. IF EXIST %msbuild_vs2017enterprise% SET msbuild=%msbuild_vs2017enterprise%
IF %msbuild_version% == latest SET vswhere_params=-latest -products * )
IF NOT DEFINED vswhere_params GOTO skip_vswhere :: VS2019
SET vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" SET msbuild_vs2019community="%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
FOR /F "USEBACKQ TOKENS=*" %%F IN (`%vswhere% !vswhere_params! -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) DO ( SET msbuild_vs2019professional="%programfiles(x86)%\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
SET msbuild="%%F" SET msbuild_vs2019enterprise="%programfiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
IF %msbuild_version% == VS2019 (
IF EXIST %msbuild_vs2019community% SET msbuild=%msbuild_vs2019community%
IF EXIST %msbuild_vs2019professional% SET msbuild=%msbuild_vs2019professional%
IF EXIST %msbuild_vs2019enterprise% SET msbuild=%msbuild_vs2019enterprise%
) )
:skip_vswhere
SET project="%~p0\..\VS2010\zstd.sln" SET project="%~p0\..\VS2010\zstd.sln"
@@ -57,7 +57,7 @@ macro(ADD_ZSTD_COMPILATION_FLAGS)
# Note that zstd source code is compatible with both C++98 and above # Note that zstd source code is compatible with both C++98 and above
# and C-gnu90 (c90 + long long + variadic macros ) and above # and C-gnu90 (c90 + long long + variadic macros ) and above
# EnableCompilerFlag("-std=c++11" false true) # Set C++ compilation to c++11 standard # EnableCompilerFlag("-std=c++11" false true) # Set C++ compilation to c++11 standard
# EnableCompilerFlag("-std=c99" true false) # Set C compilation to c99 standard # EnableCompilerFlag("-std=c99" true false) # Set C compiation to c99 standard
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC)
# clang-cl normally maps -Wall to -Weverything. # clang-cl normally maps -Wall to -Weverything.
EnableCompilerFlag("/clang:-Wall" true true false) EnableCompilerFlag("/clang:-Wall" true true false)
+1 -1
View File
@@ -118,7 +118,7 @@ endmacro ()
# Define directories containing the library's public headers # Define directories containing the library's public headers
set(PUBLIC_INCLUDE_DIRS ${LIBRARY_DIR}) set(PUBLIC_INCLUDE_DIRS ${LIBRARY_DIR})
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /I ${LIBRARY_DIR}")
# Split project to static and shared libraries build # Split project to static and shared libraries build
set(library_targets) set(library_targets)
if (ZSTD_BUILD_SHARED) if (ZSTD_BUILD_SHARED)
+2 -7
View File
@@ -88,13 +88,8 @@ feature_lz4 = get_option('lz4')
# ============================================================================= # =============================================================================
libm_dep = cc.find_library('m', required: false) libm_dep = cc.find_library('m', required: false)
if host_machine_os == os_windows thread_dep = dependency('threads', required: feature_multi_thread)
thread_dep = dependency('', required: false) use_multi_thread = thread_dep.found()
use_multi_thread = not feature_multi_thread.disabled()
else
thread_dep = dependency('threads', required: feature_multi_thread)
use_multi_thread = thread_dep.found()
endif
# Arguments in dependency should be equivalent to those passed to pkg-config # Arguments in dependency should be equivalent to those passed to pkg-config
zlib_dep = dependency('zlib', required: feature_zlib) zlib_dep = dependency('zlib', required: feature_zlib)
use_zlib = zlib_dep.found() use_zlib = zlib_dep.found()
+1 -1
View File
@@ -27,7 +27,7 @@ option('bin_contrib', type: 'boolean', value: false,
description: 'Enable contrib build') description: 'Enable contrib build')
option('multi_thread', type: 'feature', value: 'enabled', option('multi_thread', type: 'feature', value: 'enabled',
description: 'Enable multi-threading when pthread or Windows is detected') description: 'Enable multi-threading when pthread is detected')
option('zlib', type: 'feature', value: 'auto', option('zlib', type: 'feature', value: 'auto',
description: 'Enable zlib support') description: 'Enable zlib support')
option('lzma', type: 'feature', value: 'auto', option('lzma', type: 'feature', value: 'auto',
-36
View File
@@ -153,20 +153,6 @@ typedef ZSTD_CCtx zstd_cctx;
*/ */
size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters); size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters);
/**
* zstd_cctx_workspace_bound_with_ext_seq_prod() - max memory needed to
* initialize a zstd_cctx when using the block-level external sequence
* producer API.
* @parameters: The compression parameters to be used.
*
* If multiple compression parameters might be used, the caller must call
* this function for each set of parameters and use the maximum size.
*
* Return: A lower bound on the size of the workspace that is passed to
* zstd_init_cctx().
*/
size_t zstd_cctx_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *parameters);
/** /**
* zstd_init_cctx() - initialize a zstd compression context * zstd_init_cctx() - initialize a zstd compression context
* @workspace: The workspace to emplace the context into. It must outlive * @workspace: The workspace to emplace the context into. It must outlive
@@ -271,16 +257,6 @@ typedef ZSTD_CStream zstd_cstream;
*/ */
size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams); size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams);
/**
* zstd_cstream_workspace_bound_with_ext_seq_prod() - memory needed to initialize
* a zstd_cstream when using the block-level external sequence producer API.
* @cparams: The compression parameters to be used for compression.
*
* Return: A lower bound on the size of the workspace that is passed to
* zstd_init_cstream().
*/
size_t zstd_cstream_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *cparams);
/** /**
* zstd_init_cstream() - initialize a zstd streaming compression context * zstd_init_cstream() - initialize a zstd streaming compression context
* @parameters The zstd parameters to use for compression. * @parameters The zstd parameters to use for compression.
@@ -440,18 +416,6 @@ size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output,
*/ */
size_t zstd_find_frame_compressed_size(const void *src, size_t src_size); size_t zstd_find_frame_compressed_size(const void *src, size_t src_size);
/**
* zstd_register_sequence_producer() - exposes the zstd library function
* ZSTD_registerSequenceProducer(). This is used for the block-level external
* sequence producer API. See upstream zstd.h for detailed documentation.
*/
typedef ZSTD_sequenceProducer_F zstd_sequence_producer_f;
void zstd_register_sequence_producer(
zstd_cctx *cctx,
void* sequence_producer_state,
zstd_sequence_producer_f sequence_producer
);
/** /**
* struct zstd_frame_params - zstd frame parameters stored in the frame header * struct zstd_frame_params - zstd frame parameters stored in the frame header
* @frameContentSize: The frame content size, or ZSTD_CONTENTSIZE_UNKNOWN if not * @frameContentSize: The frame content size, or ZSTD_CONTENTSIZE_UNKNOWN if not
@@ -16,7 +16,6 @@
#include "common/zstd_deps.h" #include "common/zstd_deps.h"
#include "common/zstd_internal.h" #include "common/zstd_internal.h"
#include "compress/zstd_compress_internal.h"
#define ZSTD_FORWARD_IF_ERR(ret) \ #define ZSTD_FORWARD_IF_ERR(ret) \
do { \ do { \
@@ -86,52 +85,6 @@ size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *cparams)
} }
EXPORT_SYMBOL(zstd_cctx_workspace_bound); EXPORT_SYMBOL(zstd_cctx_workspace_bound);
// Used by zstd_cctx_workspace_bound_with_ext_seq_prod()
static size_t dummy_external_sequence_producer(
void *sequenceProducerState,
ZSTD_Sequence *outSeqs, size_t outSeqsCapacity,
const void *src, size_t srcSize,
const void *dict, size_t dictSize,
int compressionLevel,
size_t windowSize)
{
(void)sequenceProducerState;
(void)outSeqs; (void)outSeqsCapacity;
(void)src; (void)srcSize;
(void)dict; (void)dictSize;
(void)compressionLevel;
(void)windowSize;
return ZSTD_SEQUENCE_PRODUCER_ERROR;
}
static void init_cctx_params_from_compress_params(
ZSTD_CCtx_params *cctx_params,
const zstd_compression_parameters *compress_params)
{
ZSTD_parameters zstd_params;
memset(&zstd_params, 0, sizeof(zstd_params));
zstd_params.cParams = *compress_params;
ZSTD_CCtxParams_init_advanced(cctx_params, zstd_params);
}
size_t zstd_cctx_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *compress_params)
{
ZSTD_CCtx_params cctx_params;
init_cctx_params_from_compress_params(&cctx_params, compress_params);
ZSTD_CCtxParams_registerSequenceProducer(&cctx_params, NULL, dummy_external_sequence_producer);
return ZSTD_estimateCCtxSize_usingCCtxParams(&cctx_params);
}
EXPORT_SYMBOL(zstd_cctx_workspace_bound_with_ext_seq_prod);
size_t zstd_cstream_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *compress_params)
{
ZSTD_CCtx_params cctx_params;
init_cctx_params_from_compress_params(&cctx_params, compress_params);
ZSTD_CCtxParams_registerSequenceProducer(&cctx_params, NULL, dummy_external_sequence_producer);
return ZSTD_estimateCStreamSize_usingCCtxParams(&cctx_params);
}
EXPORT_SYMBOL(zstd_cstream_workspace_bound_with_ext_seq_prod);
zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size) zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size)
{ {
if (workspace == NULL) if (workspace == NULL)
@@ -207,14 +160,5 @@ size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output)
} }
EXPORT_SYMBOL(zstd_end_stream); EXPORT_SYMBOL(zstd_end_stream);
void zstd_register_sequence_producer(
zstd_cctx *cctx,
void* sequence_producer_state,
zstd_sequence_producer_f sequence_producer
) {
ZSTD_registerSequenceProducer(cctx, sequence_producer_state, sequence_producer);
}
EXPORT_SYMBOL(zstd_register_sequence_producer);
MODULE_LICENSE("Dual BSD/GPL"); MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("Zstd Compressor"); MODULE_DESCRIPTION("Zstd Compressor");
-20
View File
@@ -18,26 +18,6 @@ This document lists a few known cases where invalid data was formerly accepted
by the decoder, and what has changed since. by the decoder, and what has changed since.
Truncated Huffman states
------------------------
**Last affected version**: v1.5.6
**Produced by the reference compressor**: No
**Example Frame**: `28b5 2ffd 0000 5500 0072 8001 0420 7e1f 02aa 00`
When using FSE-compressed Huffman weights, the compressed weight bitstream
could contain fewer bits than necessary to decode the initial states.
The reference decompressor up to v1.5.6 will decode truncated or missing
initial states as zero, which can result in a valid Huffman tree if only
the second state is truncated.
In newer versions, truncated initial states are reported as a corruption
error by the decoder.
Offset == 0 Offset == 0
----------- -----------
+1 -1
View File
@@ -10,7 +10,7 @@
ZSTD ?= zstd # note: requires zstd installation on local system ZSTD ?= zstd # note: requires zstd installation on local system
UNAME?= $(shell sh -c 'MSYSTEM="MSYS" uname') UNAME?= $(shell uname)
ifeq ($(UNAME), SunOS) ifeq ($(UNAME), SunOS)
DIFF ?= gdiff DIFF ?= gdiff
else else
+2 -4
View File
@@ -1125,6 +1125,8 @@ If it is a 3, another 2-bits repeat flag follows, and so on.
When last symbol reaches cumulated total of `1 << Accuracy_Log`, When last symbol reaches cumulated total of `1 << Accuracy_Log`,
decoding is complete. decoding is complete.
If the last symbol makes cumulated total go above `1 << Accuracy_Log`,
distribution is considered corrupted.
If this process results in a non-zero probability for a value outside of the If this process results in a non-zero probability for a value outside of the
valid range of values that the FSE table is defined for, even if that value is valid range of values that the FSE table is defined for, even if that value is
not used, then the data is considered corrupted. not used, then the data is considered corrupted.
@@ -1362,10 +1364,6 @@ symbols for each of the final states are decoded and the process is complete.
If this process would produce more weights than the maximum number of decoded If this process would produce more weights than the maximum number of decoded
weights (255), then the data is considered corrupted. weights (255), then the data is considered corrupted.
If either of the 2 initial states are absent or truncated, then the data is
considered corrupted. Consequently, it is not possible to encode fewer than
2 weights using this mode.
#### Conversion from weights to Huffman prefix codes #### Conversion from weights to Huffman prefix codes
All present symbols shall now have a `Weight` value. All present symbols shall now have a `Weight` value.
+1 -1
View File
@@ -298,7 +298,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
* Special: value 0 means "use default strategy". */ * Special: value 0 means "use default strategy". */
ZSTD_c_targetCBlockSize=130, </b>/* v1.5.6+<b> ZSTD_c_targetCBlockSize=130, </b>/* v1.5.6+<b>
* Attempts to fit compressed block size into approximately targetCBlockSize. * Attempts to fit compressed block size into approximatively targetCBlockSize.
* Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX. * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
* Note that it's not a guarantee, just a convergence target (default:0). * Note that it's not a guarantee, just a convergence target (default:0).
* No target when targetCBlockSize == 0. * No target when targetCBlockSize == 0.
+4 -22
View File
@@ -63,8 +63,6 @@ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi
LDFLAGS_DYNLIB += -pthread LDFLAGS_DYNLIB += -pthread
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded CPPFLAGS_STATICLIB += # static library build defaults to single-threaded
# pkg-config Libs.private points to LDFLAGS_DYNLIB
PCLIB := $(LDFLAGS_DYNLIB)
ifeq ($(findstring GCC,$(CCVER)),GCC) ifeq ($(findstring GCC,$(CCVER)),GCC)
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
@@ -188,15 +186,12 @@ lib : libzstd.a libzstd
%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD %-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
%-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD %-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD
%-mt : LDFLAGS_DYNLIB := -pthread %-mt : LDFLAGS_DYNLIB := -pthread
%-mt : PCLIB :=
%-mt : PCMTLIB := $(LDFLAGS_DYNLIB)
%-mt : % %-mt : %
@echo multi-threaded build completed @echo multi-threaded build completed
%-nomt : CPPFLAGS_DYNLIB := %-nomt : CPPFLAGS_DYNLIB :=
%-nomt : LDFLAGS_DYNLIB := %-nomt : LDFLAGS_DYNLIB :=
%-nomt : CPPFLAGS_STATICLIB := %-nomt : CPPFLAGS_STATICLIB :=
%-nomt : PCLIB :=
%-nomt : % %-nomt : %
@echo single-threaded build completed @echo single-threaded build completed
@@ -266,7 +261,7 @@ clean:
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# make install is validated only for below listed environments # make install is validated only for below listed environments
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME))) ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT CYGWIN_NT))
lib: libzstd.pc lib: libzstd.pc
@@ -297,21 +292,13 @@ PCLIBPREFIX := $(if $(findstring $(LIBDIR),$(PCLIBDIR)),,$${exec_prefix})
# to PREFIX, rather than as a resolved value. # to PREFIX, rather than as a resolved value.
PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix}) PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix})
ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
ifneq ($(MT),)
PCLIB :=
PCMTLIB := $(LDFLAGS_DYNLIB)
else
PCLIB := $(LDFLAGS_DYNLIB)
endif
ifneq (,$(filter FreeBSD NetBSD DragonFly,$(UNAME)))
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
else else
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
endif endif
ifneq (,$(filter SunOS,$(UNAME))) ifneq (,$(filter $(UNAME),SunOS))
INSTALL ?= ginstall INSTALL ?= ginstall
else else
INSTALL ?= install INSTALL ?= install
@@ -321,10 +308,6 @@ INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644 INSTALL_DATA ?= $(INSTALL) -m 644
# pkg-config library define.
# For static single-threaded library declare -pthread in Libs.private
# For static multi-threaded library declare -pthread in Libs and Cflags
.PHONY: libzstd.pc
libzstd.pc: libzstd.pc.in libzstd.pc: libzstd.pc.in
@echo creating pkgconfig @echo creating pkgconfig
@sed \ @sed \
@@ -333,8 +316,7 @@ libzstd.pc: libzstd.pc.in
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \ -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \ -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
-e 's|@VERSION@|$(VERSION)|' \ -e 's|@VERSION@|$(VERSION)|' \
-e 's|@LIBS_MT@|$(PCMTLIB)|' \ -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
-e 's|@LIBS_PRIVATE@|$(PCLIB)|' \
$< >$@ $< >$@
.PHONY: install .PHONY: install
-4
View File
@@ -27,16 +27,12 @@ Enabling multithreading requires 2 conditions :
For convenience, we provide a build target to generate multi and single threaded libraries: For convenience, we provide a build target to generate multi and single threaded libraries:
- Force enable multithreading on both dynamic and static libraries by appending `-mt` to the target, e.g. `make lib-mt`. - Force enable multithreading on both dynamic and static libraries by appending `-mt` to the target, e.g. `make lib-mt`.
Note that the `.pc` generated on calling `make lib-mt` will already include the require Libs and Cflags.
- Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`. - Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`.
- By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`. - By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`.
When linking a POSIX program with a multithreaded version of `libzstd`, When linking a POSIX program with a multithreaded version of `libzstd`,
note that it's necessary to invoke the `-pthread` flag during link stage. note that it's necessary to invoke the `-pthread` flag during link stage.
The `.pc` generated from `make install` or `make install-pc` always assume a single-threaded static library
is compiled. To correctly generate a `.pc` for the multi-threaded static library, set `MT=1` as ENV variable.
Multithreading capabilities are exposed Multithreading capabilities are exposed
via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351). via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351).
-8
View File
@@ -43,8 +43,6 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros32(U32 val)
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 4) # elif defined(__GNUC__) && (__GNUC__ >= 4)
return (unsigned)__builtin_ctz(val); return (unsigned)__builtin_ctz(val);
# elif defined(__ICCARM__)
return (unsigned)__builtin_ctz(val);
# else # else
return ZSTD_countTrailingZeros32_fallback(val); return ZSTD_countTrailingZeros32_fallback(val);
# endif # endif
@@ -84,8 +82,6 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 4) # elif defined(__GNUC__) && (__GNUC__ >= 4)
return (unsigned)__builtin_clz(val); return (unsigned)__builtin_clz(val);
# elif defined(__ICCARM__)
return (unsigned)__builtin_clz(val);
# else # else
return ZSTD_countLeadingZeros32_fallback(val); return ZSTD_countLeadingZeros32_fallback(val);
# endif # endif
@@ -109,8 +105,6 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(__LP64__) # elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(__LP64__)
return (unsigned)__builtin_ctzll(val); return (unsigned)__builtin_ctzll(val);
# elif defined(__ICCARM__)
return (unsigned)__builtin_ctzll(val);
# else # else
{ {
U32 mostSignificantWord = (U32)(val >> 32); U32 mostSignificantWord = (U32)(val >> 32);
@@ -142,8 +136,6 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 4) # elif defined(__GNUC__) && (__GNUC__ >= 4)
return (unsigned)(__builtin_clzll(val)); return (unsigned)(__builtin_clzll(val));
# elif defined(__ICCARM__)
return (unsigned)(__builtin_clzll(val));
# else # else
{ {
U32 mostSignificantWord = (U32)(val >> 32); U32 mostSignificantWord = (U32)(val >> 32);
+5 -7
View File
@@ -27,7 +27,7 @@
# define INLINE_KEYWORD # define INLINE_KEYWORD
#endif #endif
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__) #if defined(__GNUC__) || defined(__ICCARM__)
# define FORCE_INLINE_ATTR __attribute__((always_inline)) # define FORCE_INLINE_ATTR __attribute__((always_inline))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
# define FORCE_INLINE_ATTR __forceinline # define FORCE_INLINE_ATTR __forceinline
@@ -54,7 +54,7 @@
#endif #endif
/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */ /* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__) #if defined(__GNUC__)
# define UNUSED_ATTR __attribute__((unused)) # define UNUSED_ATTR __attribute__((unused))
#else #else
# define UNUSED_ATTR # define UNUSED_ATTR
@@ -95,8 +95,6 @@
#ifndef MEM_STATIC /* already defined in Linux Kernel mem.h */ #ifndef MEM_STATIC /* already defined in Linux Kernel mem.h */
#if defined(__GNUC__) #if defined(__GNUC__)
# define MEM_STATIC static __inline UNUSED_ATTR # define MEM_STATIC static __inline UNUSED_ATTR
#elif defined(__IAR_SYSTEMS_ICC__)
# define MEM_STATIC static inline UNUSED_ATTR
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
# define MEM_STATIC static inline # define MEM_STATIC static inline
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@@ -110,7 +108,7 @@
#ifdef _MSC_VER #ifdef _MSC_VER
# define FORCE_NOINLINE static __declspec(noinline) # define FORCE_NOINLINE static __declspec(noinline)
#else #else
# if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__) # if defined(__GNUC__) || defined(__ICCARM__)
# define FORCE_NOINLINE static __attribute__((__noinline__)) # define FORCE_NOINLINE static __attribute__((__noinline__))
# else # else
# define FORCE_NOINLINE static # define FORCE_NOINLINE static
@@ -119,7 +117,7 @@
/* target attribute */ /* target attribute */
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__) #if defined(__GNUC__) || defined(__ICCARM__)
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target))) # define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
#else #else
# define TARGET_ATTRIBUTE(target) # define TARGET_ATTRIBUTE(target)
@@ -326,7 +324,7 @@
#endif #endif
/** /**
* Helper function to perform a wrapped pointer difference without triggering * Helper function to perform a wrapped pointer difference without trigging
* UBSAN. * UBSAN.
* *
* @returns lhs - rhs with wrapping * @returns lhs - rhs with wrapping
+1 -1
View File
@@ -35,7 +35,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
U32 f7b = 0; U32 f7b = 0;
U32 f7c = 0; U32 f7c = 0;
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
#if !defined(__clang__) || __clang_major__ >= 16 #if !defined(__clang__)
int reg[4]; int reg[4];
__cpuid((int*)reg, 0); __cpuid((int*)reg, 0);
{ {
-2
View File
@@ -190,8 +190,6 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
FSE_initDState(&state1, &bitD, dt); FSE_initDState(&state1, &bitD, dt);
FSE_initDState(&state2, &bitD, dt); FSE_initDState(&state2, &bitD, dt);
RETURN_ERROR_IF(BIT_reloadDStream(&bitD)==BIT_DStream_overflow, corruption_detected, "");
#define FSE_GETSYMBOL(statePtr) fast ? FSE_decodeSymbolFast(statePtr, &bitD) : FSE_decodeSymbol(statePtr, &bitD) #define FSE_GETSYMBOL(statePtr) fast ? FSE_decodeSymbolFast(statePtr, &bitD) : FSE_decodeSymbol(statePtr, &bitD)
/* 4 symbols per loop */ /* 4 symbols per loop */
-6
View File
@@ -30,8 +30,6 @@ extern "C" {
#if defined(_MSC_VER) /* Visual Studio */ #if defined(_MSC_VER) /* Visual Studio */
# include <stdlib.h> /* _byteswap_ulong */ # include <stdlib.h> /* _byteswap_ulong */
# include <intrin.h> /* _byteswap_* */ # include <intrin.h> /* _byteswap_* */
#elif defined(__ICCARM__)
# include <intrinsics.h>
#endif #endif
/*-************************************************************** /*-**************************************************************
@@ -156,8 +154,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
return 1; return 1;
#elif defined(__DMC__) && defined(_M_IX86) #elif defined(__DMC__) && defined(_M_IX86)
return 1; return 1;
#elif defined(__IAR_SYSTEMS_ICC__) && __LITTLE_ENDIAN__
return 1;
#else #else
const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
return one.c[0]; return one.c[0];
@@ -250,8 +246,6 @@ MEM_STATIC U32 MEM_swap32(U32 in)
#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
|| (defined(__clang__) && __has_builtin(__builtin_bswap32)) || (defined(__clang__) && __has_builtin(__builtin_bswap32))
return __builtin_bswap32(in); return __builtin_bswap32(in);
#elif defined(__ICCARM__)
return __REV(in);
#else #else
return MEM_swap32_fallback(in); return MEM_swap32_fallback(in);
#endif #endif
+1 -1
View File
@@ -90,7 +90,7 @@
#endif #endif
/** /**
* Only enable assembly for GNU C compatible compilers, * Only enable assembly for GNUC compatible compilers,
* because other platforms may not support GAS assembly syntax. * because other platforms may not support GAS assembly syntax.
* *
* Only enable assembly for Linux / MacOS, other platforms may * Only enable assembly for Linux / MacOS, other platforms may
-12
View File
@@ -24,18 +24,6 @@
#ifndef ZSTD_DEPS_COMMON #ifndef ZSTD_DEPS_COMMON
#define ZSTD_DEPS_COMMON #define ZSTD_DEPS_COMMON
/* Even though we use qsort_r only for the dictionary builder, the macro
* _GNU_SOURCE has to be declared *before* the inclusion of any standard
* header and the script 'combine.sh' combines the whole zstd source code
* in a single file.
*/
#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \
defined(__CYGWIN__) || defined(__MSYS__)
#if !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
#endif
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
+2 -2
View File
@@ -2606,7 +2606,7 @@ ZSTD_reduceTable_internal (U32* const table, U32 const size, U32 const reducerVa
/* Protect special index values < ZSTD_WINDOW_START_INDEX. */ /* Protect special index values < ZSTD_WINDOW_START_INDEX. */
U32 const reducerThreshold = reducerValue + ZSTD_WINDOW_START_INDEX; U32 const reducerThreshold = reducerValue + ZSTD_WINDOW_START_INDEX;
assert((size & (ZSTD_ROWSIZE-1)) == 0); /* multiple of ZSTD_ROWSIZE */ assert((size & (ZSTD_ROWSIZE-1)) == 0); /* multiple of ZSTD_ROWSIZE */
assert(size < (1U<<31)); /* can be cast to int */ assert(size < (1U<<31)); /* can be casted to int */
#if ZSTD_MEMORY_SANITIZER && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE) #if ZSTD_MEMORY_SANITIZER && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
/* To validate that the table reuse logic is sound, and that we don't /* To validate that the table reuse logic is sound, and that we don't
@@ -5622,7 +5622,7 @@ size_t ZSTD_freeCDict(ZSTD_CDict* cdict)
* workspaceSize: Use ZSTD_estimateCDictSize() * workspaceSize: Use ZSTD_estimateCDictSize()
* to determine how large workspace must be. * to determine how large workspace must be.
* cParams : use ZSTD_getCParams() to transform a compression level * cParams : use ZSTD_getCParams() to transform a compression level
* into its relevant cParams. * into its relevants cParams.
* @return : pointer to ZSTD_CDict*, or NULL if error (size too small) * @return : pointer to ZSTD_CDict*, or NULL if error (size too small)
* Note : there is no corresponding "free" function. * Note : there is no corresponding "free" function.
* Since workspace was allocated externally, it must be freed externally. * Since workspace was allocated externally, it must be freed externally.
-7
View File
@@ -1315,13 +1315,6 @@ MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32 curr,
return matchLowest; return matchLowest;
} }
/* index_safety_check:
* intentional underflow : ensure repIndex isn't overlapping dict + prefix
* @return 1 if values are not overlapping,
* 0 otherwise */
MEM_STATIC int ZSTD_index_overlap_check(const U32 prefixLowestIndex, const U32 repIndex) {
return ((U32)((prefixLowestIndex-1) - repIndex) >= 3);
}
/* debug functions */ /* debug functions */
+4 -4
View File
@@ -392,7 +392,7 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
hashLong[h2] = hashSmall[h] = curr; /* update hash tables */ hashLong[h2] = hashSmall[h] = curr; /* update hash tables */
/* check repcode */ /* check repcode */
if ((ZSTD_index_overlap_check(prefixLowestIndex, repIndex)) if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend; const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4; mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
@@ -513,7 +513,7 @@ _match_stored:
const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ? const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
dictBase + repIndex2 - dictIndexDelta : dictBase + repIndex2 - dictIndexDelta :
base + repIndex2; base + repIndex2;
if ( (ZSTD_index_overlap_check(prefixLowestIndex, repIndex2)) if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
&& (MEM_read32(repMatch2) == MEM_read32(ip)) ) { && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend; const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4; size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
@@ -651,7 +651,7 @@ size_t ZSTD_compressBlock_doubleFast_extDict_generic(
size_t mLength; size_t mLength;
hashSmall[hSmall] = hashLong[hLong] = curr; /* update hash table */ hashSmall[hSmall] = hashLong[hLong] = curr; /* update hash table */
if (((ZSTD_index_overlap_check(prefixStartIndex, repIndex)) if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
& (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */ & (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend; const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
@@ -719,7 +719,7 @@ size_t ZSTD_compressBlock_doubleFast_extDict_generic(
U32 const current2 = (U32)(ip-base); U32 const current2 = (U32)(ip-base);
U32 const repIndex2 = current2 - offset_2; U32 const repIndex2 = current2 - offset_2;
const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2; const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
if ( ((ZSTD_index_overlap_check(prefixStartIndex, repIndex2)) if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
& (offset_2 <= current2 - dictStartIndex)) & (offset_2 <= current2 - dictStartIndex))
&& (MEM_read32(repMatch2) == MEM_read32(ip)) ) { && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend; const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
+4 -3
View File
@@ -546,7 +546,8 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
size_t const dictHashAndTag1 = ZSTD_hashPtr(ip1, dictHBits, mls); size_t const dictHashAndTag1 = ZSTD_hashPtr(ip1, dictHBits, mls);
hashTable[hash0] = curr; /* update hash table */ hashTable[hash0] = curr; /* update hash table */
if ((ZSTD_index_overlap_check(prefixStartIndex, repIndex)) if (((U32) ((prefixStartIndex - 1) - repIndex) >=
3) /* intentional underflow : ensure repIndex isn't overlapping dict + prefix */
&& (MEM_read32(repMatch) == MEM_read32(ip0 + 1))) { && (MEM_read32(repMatch) == MEM_read32(ip0 + 1))) {
const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend; const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip0 + 1 + 4, repMatch + 4, iend, repMatchEnd, prefixStart) + 4; mLength = ZSTD_count_2segments(ip0 + 1 + 4, repMatch + 4, iend, repMatchEnd, prefixStart) + 4;
@@ -630,7 +631,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? const BYTE* repMatch2 = repIndex2 < prefixStartIndex ?
dictBase - dictIndexDelta + repIndex2 : dictBase - dictIndexDelta + repIndex2 :
base + repIndex2; base + repIndex2;
if ( (ZSTD_index_overlap_check(prefixStartIndex, repIndex2)) if ( ((U32)((prefixStartIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
&& (MEM_read32(repMatch2) == MEM_read32(ip0))) { && (MEM_read32(repMatch2) == MEM_read32(ip0))) {
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend; const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4; size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
@@ -924,7 +925,7 @@ _match: /* Requires: ip0, match0, offcode, matchEnd */
while (ip0 <= ilimit) { while (ip0 <= ilimit) {
U32 const repIndex2 = (U32)(ip0-base) - offset_2; U32 const repIndex2 = (U32)(ip0-base) - offset_2;
const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2; const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
if ( ((ZSTD_index_overlap_check(prefixStartIndex, repIndex2)) & (offset_2 > 0)) if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (offset_2 > 0)) /* intentional underflow */
&& (MEM_read32(repMatch2) == MEM_read32(ip0)) ) { && (MEM_read32(repMatch2) == MEM_read32(ip0)) ) {
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend; const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4; size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
+11 -11
View File
@@ -1123,9 +1123,9 @@ ZSTD_row_getMatchMask(const BYTE* const tagRow, const BYTE tag, const U32 headGr
/* The high-level approach of the SIMD row based match finder is as follows: /* The high-level approach of the SIMD row based match finder is as follows:
* - Figure out where to insert the new entry: * - Figure out where to insert the new entry:
* - Generate a hash for current input position and split it into a one byte of tag and `rowHashLog` bits of index. * - Generate a hash for current input posistion and split it into a one byte of tag and `rowHashLog` bits of index.
* - The hash is salted by a value that changes on every context reset, so when the same table is used * - The hash is salted by a value that changes on every contex reset, so when the same table is used
* we will avoid collisions that would otherwise slow us down by introducing phantom matches. * we will avoid collisions that would otherwise slow us down by intorducing phantom matches.
* - The hashTable is effectively split into groups or "rows" of 15 or 31 entries of U32, and the index determines * - The hashTable is effectively split into groups or "rows" of 15 or 31 entries of U32, and the index determines
* which row to insert into. * which row to insert into.
* - Determine the correct position within the row to insert the entry into. Each row of 15 or 31 can * - Determine the correct position within the row to insert the entry into. Each row of 15 or 31 can
@@ -1590,7 +1590,7 @@ size_t ZSTD_compressBlock_lazy_generic(
&& repIndex < prefixLowestIndex) ? && repIndex < prefixLowestIndex) ?
dictBase + (repIndex - dictIndexDelta) : dictBase + (repIndex - dictIndexDelta) :
base + repIndex; base + repIndex;
if ((ZSTD_index_overlap_check(prefixLowestIndex, repIndex)) if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend; const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
matchLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4; matchLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
@@ -1642,7 +1642,7 @@ size_t ZSTD_compressBlock_lazy_generic(
const BYTE* repMatch = repIndex < prefixLowestIndex ? const BYTE* repMatch = repIndex < prefixLowestIndex ?
dictBase + (repIndex - dictIndexDelta) : dictBase + (repIndex - dictIndexDelta) :
base + repIndex; base + repIndex;
if ((ZSTD_index_overlap_check(prefixLowestIndex, repIndex)) if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
&& (MEM_read32(repMatch) == MEM_read32(ip)) ) { && (MEM_read32(repMatch) == MEM_read32(ip)) ) {
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend; const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
size_t const mlRep = ZSTD_count_2segments(ip+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4; size_t const mlRep = ZSTD_count_2segments(ip+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
@@ -1678,7 +1678,7 @@ size_t ZSTD_compressBlock_lazy_generic(
const BYTE* repMatch = repIndex < prefixLowestIndex ? const BYTE* repMatch = repIndex < prefixLowestIndex ?
dictBase + (repIndex - dictIndexDelta) : dictBase + (repIndex - dictIndexDelta) :
base + repIndex; base + repIndex;
if ((ZSTD_index_overlap_check(prefixLowestIndex, repIndex)) if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
&& (MEM_read32(repMatch) == MEM_read32(ip)) ) { && (MEM_read32(repMatch) == MEM_read32(ip)) ) {
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend; const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
size_t const mlRep = ZSTD_count_2segments(ip+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4; size_t const mlRep = ZSTD_count_2segments(ip+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
@@ -1740,7 +1740,7 @@ _storeSequence:
const BYTE* repMatch = repIndex < prefixLowestIndex ? const BYTE* repMatch = repIndex < prefixLowestIndex ?
dictBase - dictIndexDelta + repIndex : dictBase - dictIndexDelta + repIndex :
base + repIndex; base + repIndex;
if ( (ZSTD_index_overlap_check(prefixLowestIndex, repIndex)) if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex) >= 3 /* intentional overflow */)
&& (MEM_read32(repMatch) == MEM_read32(ip)) ) { && (MEM_read32(repMatch) == MEM_read32(ip)) ) {
const BYTE* const repEnd2 = repIndex < prefixLowestIndex ? dictEnd : iend; const BYTE* const repEnd2 = repIndex < prefixLowestIndex ? dictEnd : iend;
matchLength = ZSTD_count_2segments(ip+4, repMatch+4, iend, repEnd2, prefixLowest) + 4; matchLength = ZSTD_count_2segments(ip+4, repMatch+4, iend, repEnd2, prefixLowest) + 4;
@@ -1986,7 +1986,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
const U32 repIndex = (U32)(curr+1 - offset_1); const U32 repIndex = (U32)(curr+1 - offset_1);
const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; const BYTE* const repBase = repIndex < dictLimit ? dictBase : base;
const BYTE* const repMatch = repBase + repIndex; const BYTE* const repMatch = repBase + repIndex;
if ( (ZSTD_index_overlap_check(dictLimit, repIndex)) if ( ((U32)((dictLimit-1) - repIndex) >= 3) /* intentional overflow */
& (offset_1 <= curr+1 - windowLow) ) /* note: we are searching at curr+1 */ & (offset_1 <= curr+1 - windowLow) ) /* note: we are searching at curr+1 */
if (MEM_read32(ip+1) == MEM_read32(repMatch)) { if (MEM_read32(ip+1) == MEM_read32(repMatch)) {
/* repcode detected we should take it */ /* repcode detected we should take it */
@@ -2027,7 +2027,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
const U32 repIndex = (U32)(curr - offset_1); const U32 repIndex = (U32)(curr - offset_1);
const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; const BYTE* const repBase = repIndex < dictLimit ? dictBase : base;
const BYTE* const repMatch = repBase + repIndex; const BYTE* const repMatch = repBase + repIndex;
if ( (ZSTD_index_overlap_check(dictLimit, repIndex)) if ( ((U32)((dictLimit-1) - repIndex) >= 3) /* intentional overflow : do not test positions overlapping 2 memory segments */
& (offset_1 <= curr - windowLow) ) /* equivalent to `curr > repIndex >= windowLow` */ & (offset_1 <= curr - windowLow) ) /* equivalent to `curr > repIndex >= windowLow` */
if (MEM_read32(ip) == MEM_read32(repMatch)) { if (MEM_read32(ip) == MEM_read32(repMatch)) {
/* repcode detected */ /* repcode detected */
@@ -2059,7 +2059,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
const U32 repIndex = (U32)(curr - offset_1); const U32 repIndex = (U32)(curr - offset_1);
const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; const BYTE* const repBase = repIndex < dictLimit ? dictBase : base;
const BYTE* const repMatch = repBase + repIndex; const BYTE* const repMatch = repBase + repIndex;
if ( (ZSTD_index_overlap_check(dictLimit, repIndex)) if ( ((U32)((dictLimit-1) - repIndex) >= 3) /* intentional overflow : do not test positions overlapping 2 memory segments */
& (offset_1 <= curr - windowLow) ) /* equivalent to `curr > repIndex >= windowLow` */ & (offset_1 <= curr - windowLow) ) /* equivalent to `curr > repIndex >= windowLow` */
if (MEM_read32(ip) == MEM_read32(repMatch)) { if (MEM_read32(ip) == MEM_read32(repMatch)) {
/* repcode detected */ /* repcode detected */
@@ -2113,7 +2113,7 @@ _storeSequence:
const U32 repIndex = repCurrent - offset_2; const U32 repIndex = repCurrent - offset_2;
const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; const BYTE* const repBase = repIndex < dictLimit ? dictBase : base;
const BYTE* const repMatch = repBase + repIndex; const BYTE* const repMatch = repBase + repIndex;
if ( (ZSTD_index_overlap_check(dictLimit, repIndex)) if ( ((U32)((dictLimit-1) - repIndex) >= 3) /* intentional overflow : do not test positions overlapping 2 memory segments */
& (offset_2 <= repCurrent - windowLow) ) /* equivalent to `curr > repIndex >= windowLow` */ & (offset_2 <= repCurrent - windowLow) ) /* equivalent to `curr > repIndex >= windowLow` */
if (MEM_read32(ip) == MEM_read32(repMatch)) { if (MEM_read32(ip) == MEM_read32(repMatch)) {
/* repcode detected we should take it */ /* repcode detected we should take it */
+2 -2
View File
@@ -664,13 +664,13 @@ ZSTD_insertBtAndGetAllMatches (
assert(curr >= windowLow); assert(curr >= windowLow);
if ( dictMode == ZSTD_extDict if ( dictMode == ZSTD_extDict
&& ( ((repOffset-1) /*intentional overflow*/ < curr - windowLow) /* equivalent to `curr > repIndex >= windowLow` */ && ( ((repOffset-1) /*intentional overflow*/ < curr - windowLow) /* equivalent to `curr > repIndex >= windowLow` */
& (ZSTD_index_overlap_check(dictLimit, repIndex)) ) & (((U32)((dictLimit-1) - repIndex) >= 3) ) /* intentional overflow : do not test positions overlapping 2 memory segments */)
&& (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch)) ) { && (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch)) ) {
repLen = (U32)ZSTD_count_2segments(ip+minMatch, repMatch+minMatch, iLimit, dictEnd, prefixStart) + minMatch; repLen = (U32)ZSTD_count_2segments(ip+minMatch, repMatch+minMatch, iLimit, dictEnd, prefixStart) + minMatch;
} }
if (dictMode == ZSTD_dictMatchState if (dictMode == ZSTD_dictMatchState
&& ( ((repOffset-1) /*intentional overflow*/ < curr - (dmsLowLimit + dmsIndexDelta)) /* equivalent to `curr > repIndex >= dmsLowLimit` */ && ( ((repOffset-1) /*intentional overflow*/ < curr - (dmsLowLimit + dmsIndexDelta)) /* equivalent to `curr > repIndex >= dmsLowLimit` */
& (ZSTD_index_overlap_check(dictLimit, repIndex)) ) & ((U32)((dictLimit-1) - repIndex) >= 3) ) /* intentional overflow : do not test positions overlapping 2 memory segments */
&& (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch)) ) { && (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch)) ) {
repLen = (U32)ZSTD_count_2segments(ip+minMatch, repMatch+minMatch, iLimit, dmsEnd, prefixStart) + minMatch; repLen = (U32)ZSTD_count_2segments(ip+minMatch, repMatch+minMatch, iLimit, dmsEnd, prefixStart) + minMatch;
} } } }
+1 -1
View File
@@ -811,7 +811,7 @@ size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
/** ZSTD_decompressBound() : /** ZSTD_decompressBound() :
* compatible with legacy mode * compatible with legacy mode
* `src` must point to the start of a ZSTD frame or a skippable frame * `src` must point to the start of a ZSTD frame or a skippeable frame
* `srcSize` must be at least as large as the frame contained * `srcSize` must be at least as large as the frame contained
* @return : the maximum decompressed size of the compressed source * @return : the maximum decompressed size of the compressed source
*/ */
+1 -1
View File
@@ -358,7 +358,7 @@ size_t ZSTD_decodeLiteralsBlock_wrapper(ZSTD_DCtx* dctx,
* - start from default distributions, present in /lib/common/zstd_internal.h * - start from default distributions, present in /lib/common/zstd_internal.h
* - generate tables normally, using ZSTD_buildFSETable() * - generate tables normally, using ZSTD_buildFSETable()
* - printout the content of tables * - printout the content of tables
* - prettify output, report below, test with fuzzer to ensure it's correct */ * - pretify output, report below, test with fuzzer to ensure it's correct */
/* Default FSE distribution table for Literal Lengths */ /* Default FSE distribution table for Literal Lengths */
static const ZSTD_seqSymbol LL_defaultDTable[(1<<LL_DEFAULTNORMLOG)+1] = { static const ZSTD_seqSymbol LL_defaultDTable[(1<<LL_DEFAULTNORMLOG)+1] = {
+19 -60
View File
@@ -21,17 +21,8 @@
/*-************************************* /*-*************************************
* Dependencies * Dependencies
***************************************/ ***************************************/
/* qsort_r is an extension. */
#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \
defined(__CYGWIN__) || defined(__MSYS__)
#if !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
#endif
#include <stdio.h> /* fprintf */ #include <stdio.h> /* fprintf */
#include <stdlib.h> /* malloc, free, qsort_r */ #include <stdlib.h> /* malloc, free, qsort */
#include <string.h> /* memset */ #include <string.h> /* memset */
#include <time.h> /* clock */ #include <time.h> /* clock */
@@ -241,10 +232,8 @@ typedef struct {
unsigned d; unsigned d;
} COVER_ctx_t; } COVER_ctx_t;
#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER) /* We need a global context for qsort... */
/* C90 only offers qsort() that needs a global context. */
static COVER_ctx_t *g_coverCtx = NULL; static COVER_ctx_t *g_coverCtx = NULL;
#endif
/*-************************************* /*-*************************************
* Helper functions * Helper functions
@@ -287,15 +276,11 @@ static int COVER_cmp8(COVER_ctx_t *ctx, const void *lp, const void *rp) {
/** /**
* Same as COVER_cmp() except ties are broken by pointer value * Same as COVER_cmp() except ties are broken by pointer value
* NOTE: g_coverCtx must be set to call this function. A global is required because
* qsort doesn't take an opaque pointer.
*/ */
#if (defined(_WIN32) && defined(_MSC_VER)) || defined(__APPLE__) static int WIN_CDECL COVER_strict_cmp(const void *lp, const void *rp) {
static int WIN_CDECL COVER_strict_cmp(void* g_coverCtx, const void* lp, const void* rp) { int result = COVER_cmp(g_coverCtx, lp, rp);
#elif defined(_GNU_SOURCE)
static int COVER_strict_cmp(const void *lp, const void *rp, void *g_coverCtx) {
#else /* C90 fallback.*/
static int COVER_strict_cmp(const void *lp, const void *rp) {
#endif
int result = COVER_cmp((COVER_ctx_t*)g_coverCtx, lp, rp);
if (result == 0) { if (result == 0) {
result = lp < rp ? -1 : 1; result = lp < rp ? -1 : 1;
} }
@@ -304,50 +289,14 @@ static int COVER_strict_cmp(const void *lp, const void *rp) {
/** /**
* Faster version for d <= 8. * Faster version for d <= 8.
*/ */
#if (defined(_WIN32) && defined(_MSC_VER)) || defined(__APPLE__) static int WIN_CDECL COVER_strict_cmp8(const void *lp, const void *rp) {
static int WIN_CDECL COVER_strict_cmp8(void* g_coverCtx, const void* lp, const void* rp) { int result = COVER_cmp8(g_coverCtx, lp, rp);
#elif defined(_GNU_SOURCE)
static int COVER_strict_cmp8(const void *lp, const void *rp, void *g_coverCtx) {
#else /* C90 fallback.*/
static int COVER_strict_cmp8(const void *lp, const void *rp) {
#endif
int result = COVER_cmp8((COVER_ctx_t*)g_coverCtx, lp, rp);
if (result == 0) { if (result == 0) {
result = lp < rp ? -1 : 1; result = lp < rp ? -1 : 1;
} }
return result; return result;
} }
/**
* Abstract away divergence of qsort_r() parameters.
* Hopefully when C11 become the norm, we will be able
* to clean it up.
*/
static void stableSort(COVER_ctx_t *ctx) {
#if defined(__APPLE__)
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
ctx,
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#elif defined(_GNU_SOURCE)
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
ctx);
#elif defined(_WIN32) && defined(_MSC_VER)
qsort_s(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
ctx);
#elif defined(__OpenBSD__)
g_coverCtx = ctx;
mergesort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#else /* C90 fallback.*/
g_coverCtx = ctx;
/* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#endif
}
/** /**
* Returns the first pointer in [first, last) whose element does not compare * Returns the first pointer in [first, last) whose element does not compare
* less than value. If no such element exists it returns last. * less than value. If no such element exists it returns last.
@@ -671,7 +620,17 @@ static size_t COVER_ctx_init(COVER_ctx_t *ctx, const void *samplesBuffer,
for (i = 0; i < ctx->suffixSize; ++i) { for (i = 0; i < ctx->suffixSize; ++i) {
ctx->suffix[i] = i; ctx->suffix[i] = i;
} }
stableSort(ctx); /* qsort doesn't take an opaque pointer, so pass as a global.
* On OpenBSD qsort() is not guaranteed to be stable, their mergesort() is.
*/
g_coverCtx = ctx;
#if defined(__OpenBSD__)
mergesort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#else
qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#endif
} }
DISPLAYLEVEL(2, "Computing frequencies\n"); DISPLAYLEVEL(2, "Computing frequencies\n");
/* For each dmer group (group of positions with the same first d bytes): /* For each dmer group (group of positions with the same first d bytes):
-4
View File
@@ -3919,10 +3919,6 @@ ZBUFFv06_DCtx* ZBUFFv06_createDCtx(void)
if (zbd==NULL) return NULL; if (zbd==NULL) return NULL;
memset(zbd, 0, sizeof(*zbd)); memset(zbd, 0, sizeof(*zbd));
zbd->zd = ZSTDv06_createDCtx(); zbd->zd = ZSTDv06_createDCtx();
if (zbd->zd==NULL) {
ZBUFFv06_freeDCtx(zbd); /* avoid leaking the context */
return NULL;
}
zbd->stage = ZBUFFds_init; zbd->stage = ZBUFFds_init;
return zbd; return zbd;
} }
+4 -2
View File
@@ -22,7 +22,7 @@ LIBZSTD_MK_INCLUDED := 1
# By default, library's directory is same as this included makefile # By default, library's directory is same as this included makefile
LIB_SRCDIR ?= $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) LIB_SRCDIR ?= $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
LIB_BINDIR ?= $(LIB_SRCDIR) LIB_BINDIR ?= $(LIBSRC_DIR)
# ZSTD_LIB_MINIFY is a helper variable that # ZSTD_LIB_MINIFY is a helper variable that
# configures a bunch of other variables to space-optimized defaults. # configures a bunch of other variables to space-optimized defaults.
@@ -206,13 +206,15 @@ endif
endif endif
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
UNAME := $(shell sh -c 'MSYSTEM="MSYS" uname') UNAME := $(shell uname)
ifndef BUILD_DIR ifndef BUILD_DIR
ifeq ($(UNAME), Darwin) ifeq ($(UNAME), Darwin)
ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0) ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
HASH ?= md5 HASH ?= md5
endif endif
else ifeq ($(UNAME), FreeBSD)
HASH ?= gmd5sum
else ifeq ($(UNAME), NetBSD) else ifeq ($(UNAME), NetBSD)
HASH ?= md5 -n HASH ?= md5 -n
else ifeq ($(UNAME), OpenBSD) else ifeq ($(UNAME), OpenBSD)
+2 -2
View File
@@ -11,6 +11,6 @@ Name: zstd
Description: fast lossless compression algorithm library Description: fast lossless compression algorithm library
URL: https://facebook.github.io/zstd/ URL: https://facebook.github.io/zstd/
Version: @VERSION@ Version: @VERSION@
Libs: -L${libdir} -lzstd @LIBS_MT@ Libs: -L${libdir} -lzstd
Libs.private: @LIBS_PRIVATE@ Libs.private: @LIBS_PRIVATE@
Cflags: -I${includedir} @LIBS_MT@ Cflags: -I${includedir}
+35 -52
View File
@@ -57,7 +57,7 @@ extern "C" {
#else #else
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */ # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
# define ZSTD_DEPRECATED(message) [[deprecated(message)]] # define ZSTD_DEPRECATED(message) [[deprecated(message)]]
# elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__) || defined(__IAR_SYSTEMS_ICC__) # elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__)
# define ZSTD_DEPRECATED(message) __attribute__((deprecated(message))) # define ZSTD_DEPRECATED(message) __attribute__((deprecated(message)))
# elif defined(__GNUC__) && (__GNUC__ >= 3) # elif defined(__GNUC__) && (__GNUC__ >= 3)
# define ZSTD_DEPRECATED(message) __attribute__((deprecated)) # define ZSTD_DEPRECATED(message) __attribute__((deprecated))
@@ -157,40 +157,37 @@ ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
int compressionLevel); int compressionLevel);
/*! ZSTD_decompress() : /*! ZSTD_decompress() :
* `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames. * `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
* Multiple compressed frames can be decompressed at once with this method. * `dstCapacity` is an upper bound of originalSize to regenerate.
* The result will be the concatenation of all decompressed frames, back to back. * If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
* `dstCapacity` is an upper bound of originalSize to regenerate. * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
* First frame's decompressed size can be extracted using ZSTD_getFrameContentSize(). * or an errorCode if it fails (which can be tested using ZSTD_isError()). */
* If maximum upper bound isn't known, prefer using streaming mode to decompress data.
* @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
* or an errorCode if it fails (which can be tested using ZSTD_isError()). */
ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/*! ZSTD_getFrameContentSize() : requires v1.3.0+ /*! ZSTD_getFrameContentSize() : requires v1.3.0+
* `src` should point to the start of a ZSTD encoded frame. * `src` should point to the start of a ZSTD encoded frame.
* `srcSize` must be at least as large as the frame header. * `srcSize` must be at least as large as the frame header.
* hint : any size >= `ZSTD_frameHeaderSize_max` is large enough. * hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
* @return : - decompressed size of `src` frame content, if known * @return : - decompressed size of `src` frame content, if known
* - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined * - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
* - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) * - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
* note 1 : a 0 return value means the frame is valid but "empty". * note 1 : a 0 return value means the frame is valid but "empty".
* note 2 : decompressed size is an optional field, it may not be present (typically in streaming mode). * note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode.
* When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
* In which case, it's necessary to use streaming mode to decompress data. * In which case, it's necessary to use streaming mode to decompress data.
* Optionally, application can rely on some implicit limit, * Optionally, application can rely on some implicit limit,
* as ZSTD_decompress() only needs an upper bound of decompressed size. * as ZSTD_decompress() only needs an upper bound of decompressed size.
* (For example, data could be necessarily cut into blocks <= 16 KB). * (For example, data could be necessarily cut into blocks <= 16 KB).
* note 3 : decompressed size is always present when compression is completed using single-pass functions, * note 3 : decompressed size is always present when compression is completed using single-pass functions,
* such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict(). * such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
* note 4 : decompressed size can be very large (64-bits value), * note 4 : decompressed size can be very large (64-bits value),
* potentially larger than what local system can handle as a single memory segment. * potentially larger than what local system can handle as a single memory segment.
* In which case, it's necessary to use streaming mode to decompress data. * In which case, it's necessary to use streaming mode to decompress data.
* note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified. * note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
* Always ensure return value fits within application's authorized limits. * Always ensure return value fits within application's authorized limits.
* Each application can set its own limits. * Each application can set its own limits.
* note 6 : This function replaces ZSTD_getDecompressedSize() */ * note 6 : This function replaces ZSTD_getDecompressedSize() */
#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1) #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) #define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize); ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
@@ -395,7 +392,7 @@ typedef enum {
* Special: value 0 means "use default strategy". */ * Special: value 0 means "use default strategy". */
ZSTD_c_targetCBlockSize=130, /* v1.5.6+ ZSTD_c_targetCBlockSize=130, /* v1.5.6+
* Attempts to fit compressed block size into approximately targetCBlockSize. * Attempts to fit compressed block size into approximatively targetCBlockSize.
* Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX. * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
* Note that it's not a guarantee, just a convergence target (default:0). * Note that it's not a guarantee, just a convergence target (default:0).
* No target when targetCBlockSize == 0. * No target when targetCBlockSize == 0.
@@ -858,7 +855,7 @@ ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
* *
* A ZSTD_DStream object is required to track streaming operations. * A ZSTD_DStream object is required to track streaming operations.
* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources. * Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
* ZSTD_DStream objects can be re-employed multiple times. * ZSTD_DStream objects can be reused multiple times.
* *
* Use ZSTD_initDStream() to start a new decompression operation. * Use ZSTD_initDStream() to start a new decompression operation.
* @return : recommended first input size * @return : recommended first input size
@@ -868,21 +865,16 @@ ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
* The function will update both `pos` fields. * The function will update both `pos` fields.
* If `input.pos < input.size`, some input has not been consumed. * If `input.pos < input.size`, some input has not been consumed.
* It's up to the caller to present again remaining data. * It's up to the caller to present again remaining data.
*
* The function tries to flush all data decoded immediately, respecting output buffer size. * The function tries to flush all data decoded immediately, respecting output buffer size.
* If `output.pos < output.size`, decoder has flushed everything it could. * If `output.pos < output.size`, decoder has flushed everything it could.
* * But if `output.pos == output.size`, there might be some data left within internal buffers.,
* However, when `output.pos == output.size`, it's more difficult to know.
* If @return > 0, the frame is not complete, meaning
* either there is still some data left to flush within internal buffers,
* or there is more input to read to complete the frame (or both).
* In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer. * In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
* Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX. * Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
* @return : 0 when a frame is completely decoded and fully flushed, * @return : 0 when a frame is completely decoded and fully flushed,
* or an error code, which can be tested using ZSTD_isError(), * or an error code, which can be tested using ZSTD_isError(),
* or any other value > 0, which means there is still some decoding or flushing to do to complete current frame : * or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
* the return value is a suggested next input size (just a hint for better latency) * the return value is a suggested next input size (just a hint for better latency)
* that will never request more than the remaining content of the compressed frame. * that will never request more than the remaining frame size.
* *******************************************************************************/ * *******************************************************************************/
typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same object (>= v1.3.0) */ typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same object (>= v1.3.0) */
@@ -909,10 +901,9 @@ ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
* Function will update both input and output `pos` fields exposing current state via these fields: * Function will update both input and output `pos` fields exposing current state via these fields:
* - `input.pos < input.size`, some input remaining and caller should provide remaining input * - `input.pos < input.size`, some input remaining and caller should provide remaining input
* on the next call. * on the next call.
* - `output.pos < output.size`, decoder flushed internal output buffer. * - `output.pos < output.size`, decoder finished and flushed all remaining buffers.
* - `output.pos == output.size`, unflushed data potentially present in the internal buffers, * - `output.pos == output.size`, potentially uncflushed data present in the internal buffers,
* check ZSTD_decompressStream() @return value, * call ZSTD_decompressStream() again to flush remaining data to output.
* if > 0, invoke it again to flush remaining data to output.
* Note : with no additional input, amount of data flushed <= ZSTD_BLOCKSIZE_MAX. * Note : with no additional input, amount of data flushed <= ZSTD_BLOCKSIZE_MAX.
* *
* @return : 0 when a frame is completely decoded and fully flushed, * @return : 0 when a frame is completely decoded and fully flushed,
@@ -1805,15 +1796,7 @@ static
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((__unused__)) __attribute__((__unused__))
#endif #endif
#if defined(__clang__) && __clang_major__ >= 5
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */ ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
#if defined(__clang__) && __clang_major__ >= 5
#pragma clang diagnostic pop
#endif
ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem); ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
+3 -3
View File
@@ -345,7 +345,7 @@ include $(wildcard $(DEPFILES))
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets # make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME))) ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT CYGWIN_NT))
HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0) HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
EGREP_OPTIONS ?= EGREP_OPTIONS ?=
@@ -388,14 +388,14 @@ datarootdir ?= $(PREFIX)/share
mandir ?= $(datarootdir)/man mandir ?= $(datarootdir)/man
man1dir ?= $(mandir)/man1 man1dir ?= $(mandir)/man1
ifneq (,$(filter OpenBSD FreeBSD NetBSD DragonFly SunOS,$(UNAME))) ifneq (,$(filter $(UNAME),OpenBSD FreeBSD NetBSD DragonFly SunOS))
MANDIR ?= $(PREFIX)/man MANDIR ?= $(PREFIX)/man
MAN1DIR ?= $(MANDIR)/man1 MAN1DIR ?= $(MANDIR)/man1
else else
MAN1DIR ?= $(man1dir) MAN1DIR ?= $(man1dir)
endif endif
ifneq (,$(filter SunOS,$(UNAME))) ifneq (,$(filter $(UNAME),SunOS))
INSTALL ?= ginstall INSTALL ?= ginstall
else else
INSTALL ?= install INSTALL ?= install
+1 -1
View File
@@ -298,7 +298,7 @@ static fileStats DiB_fileStats(const char** fileNamesTable, int nbFiles, size_t
fs.oneSampleTooLarge |= (fileSize > 2*SAMPLESIZE_MAX); fs.oneSampleTooLarge |= (fileSize > 2*SAMPLESIZE_MAX);
/* Limit to the first SAMPLESIZE_MAX (128kB) of the file */ /* Limit to the first SAMPLESIZE_MAX (128kB) of the file */
DISPLAYLEVEL(3, "Sample file '%s' is too large, limiting to %d KB\n", DISPLAYLEVEL(3, "Sample file '%s' is too large, limiting to %d KB",
fileNamesTable[n], SAMPLESIZE_MAX / (1 KB)); fileNamesTable[n], SAMPLESIZE_MAX / (1 KB));
} }
fs.nbSamples += 1; fs.nbSamples += 1;
+17 -10
View File
@@ -1494,7 +1494,7 @@ FIO_compressZstdFrame(FIO_ctx_t* const fCtx,
int compressionLevel, U64* readsize) int compressionLevel, U64* readsize)
{ {
cRess_t const ress = *ressPtr; cRess_t const ress = *ressPtr;
IOJob_t* writeJob = AIO_WritePool_acquireJob(ressPtr->writeCtx); IOJob_t *writeJob = AIO_WritePool_acquireJob(ressPtr->writeCtx);
U64 compressedfilesize = 0; U64 compressedfilesize = 0;
ZSTD_EndDirective directive = ZSTD_e_continue; ZSTD_EndDirective directive = ZSTD_e_continue;
@@ -1526,7 +1526,8 @@ FIO_compressZstdFrame(FIO_ctx_t* const fCtx,
CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, prefs->streamSrcSize) ); CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, prefs->streamSrcSize) );
} }
{ int windowLog; {
int windowLog;
UTIL_HumanReadableSize_t windowSize; UTIL_HumanReadableSize_t windowSize;
CHECK(ZSTD_CCtx_getParameter(ress.cctx, ZSTD_c_windowLog, &windowLog)); CHECK(ZSTD_CCtx_getParameter(ress.cctx, ZSTD_c_windowLog, &windowLog));
if (windowLog == 0) { if (windowLog == 0) {
@@ -1541,6 +1542,7 @@ FIO_compressZstdFrame(FIO_ctx_t* const fCtx,
windowSize = UTIL_makeHumanReadableSize(MAX(1ULL, MIN(1ULL << windowLog, pledgedSrcSize))); windowSize = UTIL_makeHumanReadableSize(MAX(1ULL, MIN(1ULL << windowLog, pledgedSrcSize)));
DISPLAYLEVEL(4, "Decompression will require %.*f%s of memory\n", windowSize.precision, windowSize.value, windowSize.suffix); DISPLAYLEVEL(4, "Decompression will require %.*f%s of memory\n", windowSize.precision, windowSize.value, windowSize.suffix);
} }
(void)srcFileName;
/* Main compression loop */ /* Main compression loop */
do { do {
@@ -2437,14 +2439,12 @@ FIO_decompressZstdFrame(FIO_ctx_t* const fCtx, dRess_t* ress,
U64 alreadyDecoded) /* for multi-frames streams */ U64 alreadyDecoded) /* for multi-frames streams */
{ {
U64 frameSize = 0; U64 frameSize = 0;
const char* srcFName20 = srcFileName; IOJob_t *writeJob = AIO_WritePool_acquireJob(ress->writeCtx);
IOJob_t* writeJob = AIO_WritePool_acquireJob(ress->writeCtx);
assert(writeJob);
/* display last 20 characters only when not --verbose */ /* display last 20 characters only when not --verbose */
{ size_t const srcFileLength = strlen(srcFileName); { size_t const srcFileLength = strlen(srcFileName);
if ((srcFileLength>20) && (g_display_prefs.displayLevel<3)) if ((srcFileLength>20) && (g_display_prefs.displayLevel<3))
srcFName20 += srcFileLength-20; srcFileName += srcFileLength-20;
} }
ZSTD_DCtx_reset(ress->dctx, ZSTD_reset_session_only); ZSTD_DCtx_reset(ress->dctx, ZSTD_reset_session_only);
@@ -2471,12 +2471,19 @@ FIO_decompressZstdFrame(FIO_ctx_t* const fCtx, dRess_t* ress,
AIO_WritePool_enqueueAndReacquireWriteJob(&writeJob); AIO_WritePool_enqueueAndReacquireWriteJob(&writeJob);
frameSize += outBuff.pos; frameSize += outBuff.pos;
if (fCtx->nbFilesTotal > 1) { if (fCtx->nbFilesTotal > 1) {
DISPLAYUPDATE_PROGRESS( size_t srcFileNameSize = strlen(srcFileName);
"\rDecompress: %2u/%2u files. Current: %s : %.*f%s... ", if (srcFileNameSize > 18) {
fCtx->currFileIdx+1, fCtx->nbFilesTotal, srcFName20, hrs.precision, hrs.value, hrs.suffix); const char* truncatedSrcFileName = srcFileName + srcFileNameSize - 15;
DISPLAYUPDATE_PROGRESS(
"\rDecompress: %2u/%2u files. Current: ...%s : %.*f%s... ",
fCtx->currFileIdx+1, fCtx->nbFilesTotal, truncatedSrcFileName, hrs.precision, hrs.value, hrs.suffix);
} else {
DISPLAYUPDATE_PROGRESS("\rDecompress: %2u/%2u files. Current: %s : %.*f%s... ",
fCtx->currFileIdx+1, fCtx->nbFilesTotal, srcFileName, hrs.precision, hrs.value, hrs.suffix);
}
} else { } else {
DISPLAYUPDATE_PROGRESS("\r%-20.20s : %.*f%s... ", DISPLAYUPDATE_PROGRESS("\r%-20.20s : %.*f%s... ",
srcFName20, hrs.precision, hrs.value, hrs.suffix); srcFileName, hrs.precision, hrs.value, hrs.suffix);
} }
AIO_ReadPool_consumeBytes(ress->readCtx, inBuff.pos); AIO_ReadPool_consumeBytes(ress->readCtx, inBuff.pos);
+1 -1
View File
@@ -268,7 +268,7 @@ static void AIO_IOPool_destroy(IOPoolCtx_t* ctx) {
/* AIO_IOPool_acquireJob: /* AIO_IOPool_acquireJob:
* Returns an available io job to be used for a future io. */ * Returns an available io job to be used for a future io. */
static IOJob_t* AIO_IOPool_acquireJob(IOPoolCtx_t* ctx) { static IOJob_t* AIO_IOPool_acquireJob(IOPoolCtx_t* ctx) {
IOJob_t* job; IOJob_t *job;
assert(ctx->file != NULL || ctx->prefs->testMode); assert(ctx->file != NULL || ctx->prefs->testMode);
AIO_IOPool_lockJobsMutex(ctx); AIO_IOPool_lockJobsMutex(ctx);
assert(ctx->availableJobsCount > 0); assert(ctx->availableJobsCount > 0);
+9 -9
View File
@@ -224,9 +224,9 @@ roundTripCrash : $(ZSTD_OBJECTS) roundTripCrash.c
CLEAN += longmatch CLEAN += longmatch
longmatch : $(ZSTD_OBJECTS) longmatch.c longmatch : $(ZSTD_OBJECTS) longmatch.c
CLEAN += largeDictionary CLEAN += bigdict
largeDictionary: CFLAGS += $(MULTITHREAD) bigdict: CFLAGS += $(MULTITHREAD)
largeDictionary: $(ZSTDMT_OBJECTS) $(PRGDIR)/datagen.c largeDictionary.c bigdict: $(ZSTDMT_OBJECTS) $(PRGDIR)/datagen.c bigdict.c
CLEAN += invalidDictionaries CLEAN += invalidDictionaries
invalidDictionaries : $(ZSTD_OBJECTS) invalidDictionaries.c invalidDictionaries : $(ZSTD_OBJECTS) invalidDictionaries.c
@@ -271,8 +271,8 @@ clean:
#---------------------------------------------------------------------------------- #----------------------------------------------------------------------------------
# valgrind tests validated only for some posix platforms # valgrind tests validated only for some posix platforms
#---------------------------------------------------------------------------------- #----------------------------------------------------------------------------------
UNAME := $(shell sh -c 'MSYSTEM="MSYS" uname') UNAME := $(shell uname)
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS AIX CYGWIN_NT%,$(UNAME))) ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS AIX CYGWIN_NT))
HOST_OS = POSIX HOST_OS = POSIX
.PHONY: test-valgrind .PHONY: test-valgrind
@@ -300,10 +300,10 @@ endif
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# make tests validated only for below targets # make tests validated only for below targets
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
ifneq (,$(filter MSYS POSIX,$(HOST_OS))) ifneq (,$(filter $(HOST_OS),MSYS POSIX))
DIFF:=diff DIFF:=diff
ifneq (,$(filter SunOS,$(UNAME))) ifneq (,$(filter $(UNAME),SunOS))
DIFF:=gdiff DIFF:=gdiff
endif endif
@@ -391,8 +391,8 @@ test-zstream32: zstreamtest32
test-longmatch: longmatch test-longmatch: longmatch
$(QEMU_SYS) ./longmatch $(QEMU_SYS) ./longmatch
test-largeDictionary: largeDictionary test-bigdict: bigdict
$(QEMU_SYS) ./largeDictionary $(QEMU_SYS) ./bigdict
test-invalidDictionaries: invalidDictionaries test-invalidDictionaries: invalidDictionaries
$(QEMU_SYS) ./invalidDictionaries $(QEMU_SYS) ./invalidDictionaries
+3 -8
View File
@@ -70,14 +70,12 @@ int main(int argc, const char** argv)
char* buffer = (char*)malloc(bufferSize); char* buffer = (char*)malloc(bufferSize);
void* out = malloc(outSize); void* out = malloc(outSize);
void* roundtrip = malloc(dataSize); void* roundtrip = malloc(dataSize);
int _exit_code = 0;
(void)argc; (void)argc;
(void)argv; (void)argv;
if (!buffer || !out || !roundtrip || !cctx || !dctx) { if (!buffer || !out || !roundtrip || !cctx || !dctx) {
fprintf(stderr, "Allocation failure\n"); fprintf(stderr, "Allocation failure\n");
_exit_code = 1; return 1;
goto cleanup;
} }
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31))) if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
@@ -121,13 +119,10 @@ int main(int argc, const char** argv)
fprintf(stderr, "Success!\n"); fprintf(stderr, "Success!\n");
goto cleanup;
cleanup:
free(roundtrip); free(roundtrip);
free(out); free(out);
free(buffer); free(buffer);
ZSTD_freeCCtx(cctx);
ZSTD_freeDCtx(dctx); ZSTD_freeDCtx(dctx);
return _exit_code; ZSTD_freeCCtx(cctx);
return 0;
} }
+1
View File
@@ -18,6 +18,7 @@ esac
case "$UNAME" in case "$UNAME" in
Darwin) MD5SUM="md5 -r" ;; Darwin) MD5SUM="md5 -r" ;;
FreeBSD) MD5SUM="gmd5sum" ;;
NetBSD) MD5SUM="md5 -n" ;; NetBSD) MD5SUM="md5 -n" ;;
OpenBSD) MD5SUM="md5" ;; OpenBSD) MD5SUM="md5" ;;
*) MD5SUM="md5sum" ;; *) MD5SUM="md5sum" ;;
+1 -1
View File
@@ -17,7 +17,7 @@ LDFLAGS ?=
ARFLAGS ?= ARFLAGS ?=
LIB_FUZZING_ENGINE ?= libregression.a LIB_FUZZING_ENGINE ?= libregression.a
PYTHON ?= python PYTHON ?= python
ifeq ($(shell sh -c 'MSYSTEM="MSYS" uname') , Darwin) ifeq ($(shell uname), Darwin)
DOWNLOAD?=curl -L -o DOWNLOAD?=curl -L -o
else else
DOWNLOAD?=wget -O DOWNLOAD?=wget -O
+1
View File
@@ -408,6 +408,7 @@ def build(args):
mflags = shlex.split(args.mflags) mflags = shlex.split(args.mflags)
# Flags to be added to both cflags and cxxflags # Flags to be added to both cflags and cxxflags
common_flags = [ common_flags = [
'-Werror',
'-Wno-error=declaration-after-statement', '-Wno-error=declaration-after-statement',
'-Wno-error=c++-compat', '-Wno-error=c++-compat',
'-Wno-error=deprecated' # C files are sometimes compiled with CXX '-Wno-error=deprecated' # C files are sometimes compiled with CXX
+1 -1
View File
@@ -127,7 +127,7 @@ static size_t decodeSequences(void* dst, size_t nbSequences,
FUZZ_ASSERT(litPtr <= litEnd); FUZZ_ASSERT(litPtr <= litEnd);
if (mode == ZSTD_sf_noBlockDelimiters) { if (mode == ZSTD_sf_noBlockDelimiters) {
const uint32_t lastLLSize = (uint32_t)(litEnd - litPtr); const uint32_t lastLLSize = (uint32_t)(litEnd - litPtr);
if (lastLLSize <= (uint32_t)(oend - op)) { if (lastLLSize <= oend - op) {
memcpy(op, litPtr, lastLLSize); memcpy(op, litPtr, lastLLSize);
generatedSrcBufferSize += lastLLSize; generatedSrcBufferSize += lastLLSize;
} } } }
+1 -1
View File
@@ -36,7 +36,7 @@ clean:
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# validated only for Linux, macOS, Hurd and some BSD targets # validated only for Linux, macOS, Hurd and some BSD targets
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU FreeBSD DragonFly NetBSD,$(shell sh -c 'MSYSTEM="MSYS" uname') )) ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU FreeBSD DragonFly NetBSD))
test-%: zstd test-%: zstd
@./test-driver.sh --test-name $* --log-file $*.log --trs-file $*.trs --expect-failure "no" --color-tests "yes" --enable-hard-errors "yes" ./$*.sh @./test-driver.sh --test-name $* --log-file $*.log --trs-file $*.trs --expect-failure "no" --color-tests "yes" --enable-hard-errors "yes" ./$*.sh
-128
View File
@@ -1,128 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under both the BSD-style license (found in the
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
* in the COPYING file in the root directory of this source tree).
* You may select, at your option, one of the above-listed licenses.
*/
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include "datagen.h"
#include "mem.h"
#define ZSTD_STATIC_LINKING_ONLY
#include "zstd.h"
static int
compress(ZSTD_CCtx* cctx, ZSTD_DCtx* dctx,
void* dst, size_t dstCapacity,
void const* src, size_t srcSize,
void* roundtrip, ZSTD_EndDirective end)
{
ZSTD_inBuffer in = {src, srcSize, 0};
ZSTD_outBuffer out = {dst, dstCapacity, 0};
int ended = 0;
while (!ended && (in.pos < in.size || out.pos > 0)) {
size_t rc;
out.pos = 0;
rc = ZSTD_compressStream2(cctx, &out, &in, end);
if (ZSTD_isError(rc))
return 1;
if (end == ZSTD_e_end && rc == 0)
ended = 1;
{
ZSTD_inBuffer rtIn = {dst, out.pos, 0};
ZSTD_outBuffer rtOut = {roundtrip, srcSize, 0};
rc = 1;
while (rtIn.pos < rtIn.size || rtOut.pos > 0) {
rtOut.pos = 0;
rc = ZSTD_decompressStream(dctx, &rtOut, &rtIn);
if (ZSTD_isError(rc)) {
fprintf(stderr, "Decompression error: %s\n", ZSTD_getErrorName(rc));
return 1;
}
if (rc == 0)
break;
}
if (ended && rc != 0) {
fprintf(stderr, "Frame not finished!\n");
return 1;
}
}
}
return 0;
}
int main(int argc, const char** argv)
{
ZSTD_CCtx* cctx = ZSTD_createCCtx();
ZSTD_DCtx* dctx = ZSTD_createDCtx();
const size_t dataSize = (size_t)1 << 30;
const size_t outSize = ZSTD_compressBound(dataSize);
const size_t bufferSize = (size_t)1 << 31;
char* buffer = (char*)malloc(bufferSize);
void* out = malloc(outSize);
void* roundtrip = malloc(dataSize);
(void)argc;
(void)argv;
if (!buffer || !out || !roundtrip || !cctx || !dctx) {
fprintf(stderr, "Allocation failure\n");
return 1;
}
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10)))
return 1;
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10)))
return 1;
if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31)))
return 1;
RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
/* Compress 30 GB */
{
int i;
for (i = 0; i < 10; ++i) {
fprintf(stderr, "Compressing 1 GB\n");
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue))
return 1;
}
}
fprintf(stderr, "Compressing 1 GB\n");
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end))
return 1;
fprintf(stderr, "Success!\n");
free(roundtrip);
free(out);
free(buffer);
ZSTD_freeDCtx(dctx);
ZSTD_freeCCtx(cctx);
return 0;
}
+1
View File
@@ -1273,6 +1273,7 @@ static int createBuffers(buffers_t* buff, const char* const * const fileNamesTab
f = fopen(fileNamesTable[n], "rb"); f = fopen(fileNamesTable[n], "rb");
if (f==NULL) { if (f==NULL) {
DISPLAY("impossible to open file %s\n", fileNamesTable[n]); DISPLAY("impossible to open file %s\n", fileNamesTable[n]);
fclose(f);
ret = 10; ret = 10;
goto _cleanUp; goto _cleanUp;
} }
+1
View File
@@ -123,6 +123,7 @@ esac
case "$UNAME" in case "$UNAME" in
Darwin) MD5SUM="md5 -r" ;; Darwin) MD5SUM="md5 -r" ;;
FreeBSD) MD5SUM="gmd5sum" ;;
NetBSD) MD5SUM="md5 -n" ;; NetBSD) MD5SUM="md5 -n" ;;
OpenBSD) MD5SUM="md5" ;; OpenBSD) MD5SUM="md5" ;;
*) MD5SUM="md5sum" ;; *) MD5SUM="md5sum" ;;
-2
View File
@@ -24,7 +24,5 @@ char const* result_get_error_string(result_t result) {
return "decompression error"; return "decompression error";
case result_error_round_trip_error: case result_error_round_trip_error:
return "round trip error"; return "round trip error";
default:
return "unknown error - " + result_get_error(result);
} }
} }
+3 -62
View File
@@ -2356,7 +2356,7 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
} }
DISPLAYLEVEL(3, "OK \n"); DISPLAYLEVEL(3, "OK \n");
DISPLAYLEVEL(3, "test%3i : Testing external sequence producer with static CCtx (one-shot): ", testNb++); DISPLAYLEVEL(3, "test%3i : Testing external sequence producer with static CCtx: ", testNb++);
{ {
size_t const dstBufSize = ZSTD_compressBound(CNBufferSize); size_t const dstBufSize = ZSTD_compressBound(CNBufferSize);
BYTE* const dstBuf = (BYTE*)malloc(dstBufSize); BYTE* const dstBuf = (BYTE*)malloc(dstBufSize);
@@ -2375,7 +2375,7 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
size_t const cctxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params); size_t const cctxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params);
cctxBuf = malloc(cctxSize); cctxBuf = malloc(cctxSize);
staticCCtx = ZSTD_initStaticCCtx(cctxBuf, cctxSize); staticCCtx = ZSTD_initStaticCCtx(cctxBuf, cctxSize);
CHECK_Z(ZSTD_CCtx_setParametersUsingCCtxParams(staticCCtx, params)); ZSTD_CCtx_setParametersUsingCCtxParams(staticCCtx, params);
} }
// Check that compression with external sequence producer succeeds when expected // Check that compression with external sequence producer succeeds when expected
@@ -2408,65 +2408,6 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
} }
DISPLAYLEVEL(3, "OK \n"); DISPLAYLEVEL(3, "OK \n");
DISPLAYLEVEL(3, "test%3i : Testing external sequence producer with static CCtx (streaming): ", testNb++);
{
size_t const dstBufSize = ZSTD_compressBound(CNBufferSize);
BYTE* const dstBuf = (BYTE*)malloc(dstBufSize);
size_t const checkBufSize = CNBufferSize;
BYTE* const checkBuf = (BYTE*)malloc(checkBufSize);
ZSTD_CCtx_params* params = ZSTD_createCCtxParams();
ZSTD_CCtx* staticCCtx;
void* cctxBuf;
EMF_testCase seqProdState;
CHECK_Z(ZSTD_CCtxParams_setParameter(params, ZSTD_c_validateSequences, 1));
CHECK_Z(ZSTD_CCtxParams_setParameter(params, ZSTD_c_enableSeqProducerFallback, 0));
ZSTD_CCtxParams_registerSequenceProducer(params, &seqProdState, zstreamSequenceProducer);
{
size_t const cctxSize = ZSTD_estimateCStreamSize_usingCCtxParams(params);
cctxBuf = malloc(cctxSize);
staticCCtx = ZSTD_initStaticCCtx(cctxBuf, cctxSize);
CHECK_Z(ZSTD_CCtx_setParametersUsingCCtxParams(staticCCtx, params));
}
// Check that compression with external sequence producer succeeds when expected
seqProdState = EMF_LOTS_OF_SEQS;
{
ZSTD_inBuffer inBuf = { CNBuffer, CNBufferSize, 0 };
ZSTD_outBuffer outBuf = { dstBuf, dstBufSize, 0 };
size_t dResult;
CHECK_Z(ZSTD_compressStream(staticCCtx, &outBuf, &inBuf));
CHECK_Z(ZSTD_endStream(staticCCtx, &outBuf));
CHECK(inBuf.pos != inBuf.size, "EMF: inBuf.pos != inBuf.size");
dResult = ZSTD_decompress(checkBuf, checkBufSize, outBuf.dst, outBuf.pos);
CHECK(ZSTD_isError(dResult), "EMF: Decompression error: %s", ZSTD_getErrorName(dResult));
CHECK(dResult != CNBufferSize, "EMF: Corruption!");
CHECK(memcmp(CNBuffer, checkBuf, CNBufferSize) != 0, "EMF: Corruption!");
}
CHECK_Z(ZSTD_CCtx_reset(staticCCtx, ZSTD_reset_session_only));
// Check that compression with external sequence producer fails when expected
seqProdState = EMF_BIG_ERROR;
{
ZSTD_inBuffer inBuf = { CNBuffer, CNBufferSize, 0 };
ZSTD_outBuffer outBuf = { dstBuf, dstBufSize, 0 };
size_t const cResult = ZSTD_compressStream(staticCCtx, &outBuf, &inBuf);
CHECK(!ZSTD_isError(cResult), "EMF: Should have raised an error!");
CHECK(
ZSTD_getErrorCode(cResult) != ZSTD_error_sequenceProducer_failed,
"EMF: Wrong error code: %s", ZSTD_getErrorName(cResult)
);
}
free(dstBuf);
free(checkBuf);
free(cctxBuf);
ZSTD_freeCCtxParams(params);
}
DISPLAYLEVEL(3, "OK \n");
DISPLAYLEVEL(3, "test%3i : Decoder should reject invalid frame header on legacy frames: ", testNb++); DISPLAYLEVEL(3, "test%3i : Decoder should reject invalid frame header on legacy frames: ", testNb++);
{ {
const unsigned char compressed[] = { 0x26,0xb5,0x2f,0xfd,0x50,0x91,0xfd,0xd8,0xb5 }; const unsigned char compressed[] = { 0x26,0xb5,0x2f,0xfd,0x50,0x91,0xfd,0xd8,0xb5 };
@@ -2478,7 +2419,7 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
DISPLAYLEVEL(3, "test%3i : Test single-shot fallback for magicless mode: ", testNb++); DISPLAYLEVEL(3, "test%3i : Test single-shot fallback for magicless mode: ", testNb++);
{ {
// Acquire resources // Aquire resources
size_t const srcSize = COMPRESSIBLE_NOISE_LENGTH; size_t const srcSize = COMPRESSIBLE_NOISE_LENGTH;
void* src = malloc(srcSize); void* src = malloc(srcSize);
size_t const dstSize = ZSTD_compressBound(srcSize); size_t const dstSize = ZSTD_compressBound(srcSize);
+2 -2
View File
@@ -234,7 +234,7 @@ int gzwrite _Z_OF((gzFile, const void *, unsigned));
int gzwrite(gzFile gz, const void *buf, unsigned len) { int gzwrite(gzFile gz, const void *buf, unsigned len) {
z_stream *strm; z_stream *strm;
unsigned char out[BUFLEN] = { 0 }; unsigned char out[BUFLEN];
if (gz == NULL || !gz->write) if (gz == NULL || !gz->write)
return 0; return 0;
@@ -287,7 +287,7 @@ int gzclose _Z_OF((gzFile));
int gzclose(gzFile gz) { int gzclose(gzFile gz) {
z_stream *strm; z_stream *strm;
unsigned char out[BUFLEN] = { 0 }; unsigned char out[BUFLEN];
if (gz == NULL) if (gz == NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
+1 -2
View File
@@ -64,7 +64,6 @@ local int gz_init(gz_statep state) {
strm->next_out = state.state->out; strm->next_out = state.state->out;
state.state->x.next = strm->next_out; state.state->x.next = strm->next_out;
} }
return 0; return 0;
} }
@@ -224,7 +223,7 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
z_size_t n = (unsigned)-1; z_size_t n = (unsigned)-1;
if (n > len) if (n > len)
n = len; n = len;
state.state->strm.avail_in = (uInt)n; state.state->strm.avail_in = (z_uInt)n;
state.state->x.pos += n; state.state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;