Compare commits

..
2 Commits
Author SHA1 Message Date
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
205 changed files with 777 additions and 1270 deletions
+27
View File
@@ -36,6 +36,33 @@ jobs:
make armbuild V=1; make clean make armbuild V=1; make clean
make -C tests test-legacy test-longmatch; make clean make -C tests test-legacy test-longmatch; make clean
make -C lib libzstd-nomt; make clean make -C lib libzstd-nomt; make clean
# This step is only run on release tags.
# It publishes the source tarball as artifacts and if the GITHUB_TOKEN
# environment variable is set it will publish the source tarball to the
# tagged release.
publish-github-release:
docker:
- image: fbopensource/zstd-circleci-primary:0.0.1
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
steps:
- checkout
- run:
name: Publish
command: |
export VERSION=$(echo $CIRCLE_TAG | tail -c +2)
export ZSTD_VERSION=zstd-$VERSION
git archive $CIRCLE_TAG --prefix $ZSTD_VERSION/ --format tar \
-o $ZSTD_VERSION.tar
sha256sum $ZSTD_VERSION.tar > $ZSTD_VERSION.tar.sha256
zstd -19 $ZSTD_VERSION.tar
sha256sum $ZSTD_VERSION.tar.zst > $ZSTD_VERSION.tar.zst.sha256
gzip -k -9 $ZSTD_VERSION.tar
sha256sum $ZSTD_VERSION.tar.gz > $ZSTD_VERSION.tar.gz.sha256
mkdir -p $CIRCLE_ARTIFACTS
cp $ZSTD_VERSION.tar* $CIRCLE_ARTIFACTS
- store_artifacts:
path: /tmp/circleci-artifacts
# This step should only be run in a cron job # This step should only be run in a cron job
regression-test: regression-test:
docker: docker:
+1 -1
View File
@@ -62,7 +62,7 @@ jobs:
# zbufftest-dll : test that a user program can link to multi-threaded libzstd without specifying -pthread # zbufftest-dll : test that a user program can link to multi-threaded libzstd without specifying -pthread
gcc-8-asan-ubsan-testzstd: gcc-8-asan-ubsan-testzstd:
runs-on: ubuntu-latest runs-on: ubuntu-16.04 # fails on 18.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: gcc-8 + ASan + UBSan + Test Zstd - name: gcc-8 + ASan + UBSan + Test Zstd
@@ -1,68 +0,0 @@
name: publish-release-artifacts
on:
release:
types:
- created
jobs:
publish-release-artifacts:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Archive
env:
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
RELEASE_SIGNING_KEY_PASSPHRASE: ${{ secrets.RELEASE_SIGNING_KEY_PASSPHRASE }}
run: |
# compute file name
export TAG="$(echo "$GITHUB_REF" | sed -n 's_^refs/tags/__p')"
if [ -z "$TAG" ]; then
echo "action must be run on a tag. GITHUB_REF is not a tag: $GITHUB_REF"
exit 1
fi
# Attempt to extract "1.2.3" from "v1.2.3" to maintain artifact name backwards compat.
# Otherwise, degrade to using full tag.
export VERSION="$(echo "$TAG" | sed 's_^v\([0-9]\+\.[0-9]\+\.[0-9]\+\)$_\1_')"
export ZSTD_VERSION="zstd-$VERSION"
# archive
git archive $TAG \
--prefix $ZSTD_VERSION/ \
--format tar \
-o $ZSTD_VERSION.tar
# Do the rest of the work in a sub-dir so we can glob everything we want to publish.
mkdir artifacts/
mv $ZSTD_VERSION.tar artifacts/
cd artifacts/
# compress
zstd -k -19 $ZSTD_VERSION.tar
gzip -k -9 $ZSTD_VERSION.tar
# we only publish the compressed tarballs
rm $ZSTD_VERSION.tar
# hash
sha256sum $ZSTD_VERSION.tar.zst > $ZSTD_VERSION.tar.zst.sha256
sha256sum $ZSTD_VERSION.tar.gz > $ZSTD_VERSION.tar.gz.sha256
# sign
if [ -n "$RELEASE_SIGNING_KEY" ]; then
export GPG_BATCH_OPTS="--batch --no-use-agent --pinentry-mode loopback --no-tty --yes"
echo "$RELEASE_SIGNING_KEY" | gpg $GPG_BATCH_OPTS --import
gpg $GPG_BATCH_OPTS --armor --sign --sign-with signing@zstd.net --detach-sig --passphrase "$RELEASE_SIGNING_KEY_PASSPHRASE" --output $ZSTD_VERSION.tar.zst.sig $ZSTD_VERSION.tar.zst
gpg $GPG_BATCH_OPTS --armor --sign --sign-with signing@zstd.net --detach-sig --passphrase "$RELEASE_SIGNING_KEY_PASSPHRASE" --output $ZSTD_VERSION.tar.gz.sig $ZSTD_VERSION.tar.gz
fi
- name: Publish
uses: skx/github-action-publish-binaries@release-1.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: artifacts/*
-1
View File
@@ -22,7 +22,6 @@ libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'),
join_paths(zstd_rootdir, 'lib/common/threading.c'), join_paths(zstd_rootdir, 'lib/common/threading.c'),
join_paths(zstd_rootdir, 'lib/common/pool.c'), join_paths(zstd_rootdir, 'lib/common/pool.c'),
join_paths(zstd_rootdir, 'lib/common/zstd_common.c'), join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
join_paths(zstd_rootdir, 'lib/common/zstd_trace.c'),
join_paths(zstd_rootdir, 'lib/common/error_private.c'), join_paths(zstd_rootdir, 'lib/common/error_private.c'),
join_paths(zstd_rootdir, 'lib/common/xxhash.c'), join_paths(zstd_rootdir, 'lib/common/xxhash.c'),
join_paths(zstd_rootdir, 'lib/compress/hist.c'), join_paths(zstd_rootdir, 'lib/compress/hist.c'),
+2 -55
View File
@@ -27,8 +27,6 @@ SKIPPED_FILES = [
"common/pool.h", "common/pool.h",
"common/threading.c", "common/threading.c",
"common/threading.h", "common/threading.h",
"common/zstd_trace.c",
"common/zstd_trace.h",
"compress/zstdmt_compress.h", "compress/zstdmt_compress.h",
"compress/zstdmt_compress.c", "compress/zstdmt_compress.c",
] ]
@@ -432,7 +430,7 @@ class Freestanding(object):
external_xxhash: bool, xxh64_state: Optional[str], external_xxhash: bool, xxh64_state: Optional[str],
xxh64_prefix: Optional[str], rewritten_includes: [(str, str)], xxh64_prefix: Optional[str], rewritten_includes: [(str, str)],
defs: [(str, Optional[str])], replaces: [(str, str)], defs: [(str, Optional[str])], replaces: [(str, str)],
undefs: [str], excludes: [str], seds: [str], undefs: [str], excludes: [str]
): ):
self._zstd_deps = zstd_deps self._zstd_deps = zstd_deps
self._mem = mem self._mem = mem
@@ -446,7 +444,6 @@ class Freestanding(object):
self._replaces = replaces self._replaces = replaces
self._undefs = undefs self._undefs = undefs
self._excludes = excludes self._excludes = excludes
self._seds = seds
def _dst_lib_file_paths(self): def _dst_lib_file_paths(self):
""" """
@@ -599,48 +596,6 @@ class Freestanding(object):
file.lines[i] = line file.lines[i] = line
file.write() file.write()
def _parse_sed(self, sed):
assert sed[0] == 's'
delim = sed[1]
match = re.fullmatch(f's{delim}(.+){delim}(.*){delim}(.*)', sed)
assert match is not None
regex = re.compile(match.group(1))
format_str = match.group(2)
is_global = match.group(3) == 'g'
return regex, format_str, is_global
def _process_sed(self, sed):
self._log(f"Processing sed: {sed}")
regex, format_str, is_global = self._parse_sed(sed)
for filepath in self._dst_lib_file_paths():
file = FileLines(filepath)
for i, line in enumerate(file.lines):
modified = False
while True:
match = regex.search(line)
if match is None:
break
replacement = format_str.format(match.groups(''), match.groupdict(''))
b = match.start()
e = match.end()
line = line[:b] + replacement + line[e:]
modified = True
if not is_global:
break
if modified:
self._log(f"\t- {file.lines[i][:-1]}")
self._log(f"\t+ {line[:-1]}")
file.lines[i] = line
file.write()
def _process_seds(self):
self._log("Processing seds")
for sed in self._seds:
self._process_sed(sed)
def go(self): def go(self):
self._copy_source_lib() self._copy_source_lib()
self._copy_zstd_deps() self._copy_zstd_deps()
@@ -649,7 +604,6 @@ class Freestanding(object):
self._remove_excludes() self._remove_excludes()
self._rewrite_includes() self._rewrite_includes()
self._replace_xxh64_prefix() self._replace_xxh64_prefix()
self._process_seds()
def parse_optional_pair(defines: [str]) -> [(str, Optional[str])]: def parse_optional_pair(defines: [str]) -> [(str, Optional[str])]:
@@ -687,7 +641,6 @@ def main(name, args):
parser.add_argument("--xxh64-state", default=None, help="Alternate XXH64 state type (excluding _) e.g. --xxh64-state='struct xxh64_state'") parser.add_argument("--xxh64-state", default=None, help="Alternate XXH64 state type (excluding _) e.g. --xxh64-state='struct xxh64_state'")
parser.add_argument("--xxh64-prefix", default=None, help="Alternate XXH64 function prefix (excluding _) e.g. --xxh64-prefix=xxh64") parser.add_argument("--xxh64-prefix", default=None, help="Alternate XXH64 function prefix (excluding _) e.g. --xxh64-prefix=xxh64")
parser.add_argument("--rewrite-include", default=[], dest="rewritten_includes", action="append", help="Rewrite an include REGEX=NEW (e.g. '<stddef\\.h>=<linux/types.h>')") parser.add_argument("--rewrite-include", default=[], dest="rewritten_includes", action="append", help="Rewrite an include REGEX=NEW (e.g. '<stddef\\.h>=<linux/types.h>')")
parser.add_argument("--sed", default=[], dest="seds", action="append", help="Apply a sed replacement. Format: `s/REGEX/FORMAT/[g]`. REGEX is a Python regex. FORMAT is a Python format string formatted by the regex dict.")
parser.add_argument("-D", "--define", default=[], dest="defs", action="append", help="Pre-define this macro (can be passed multiple times)") parser.add_argument("-D", "--define", default=[], dest="defs", action="append", help="Pre-define this macro (can be passed multiple times)")
parser.add_argument("-U", "--undefine", default=[], dest="undefs", action="append", help="Pre-undefine this macro (can be passed mutliple times)") parser.add_argument("-U", "--undefine", default=[], dest="undefs", action="append", help="Pre-undefine this macro (can be passed mutliple times)")
parser.add_argument("-R", "--replace", default=[], dest="replaces", action="append", help="Pre-define this macro and replace the first ifndef block with its definition") parser.add_argument("-R", "--replace", default=[], dest="replaces", action="append", help="Pre-define this macro and replace the first ifndef block with its definition")
@@ -703,11 +656,6 @@ def main(name, args):
if name in args.undefs: if name in args.undefs:
raise RuntimeError(f"{name} is both defined and undefined!") raise RuntimeError(f"{name} is both defined and undefined!")
# Always set tracing to 0
if "ZSTD_NO_TRACE" not in (arg[0] for arg in args.defs):
args.defs.append(("ZSTD_NO_TRACE", None))
args.defs.append(("ZSTD_TRACE", "0"))
args.replaces = parse_pair(args.replaces) args.replaces = parse_pair(args.replaces)
for name, _ in args.replaces: for name, _ in args.replaces:
if name in args.undefs or name in args.defs: if name in args.undefs or name in args.defs:
@@ -740,8 +688,7 @@ def main(name, args):
args.defs, args.defs,
args.replaces, args.replaces,
args.undefs, args.undefs,
args.excludes, args.excludes
args.seds,
).go() ).go()
if __name__ == "__main__": if __name__ == "__main__":
+4 -15
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2015-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
@@ -22,10 +22,6 @@ libzstd:
--xxh64-prefix 'xxh64' \ --xxh64-prefix 'xxh64' \
--rewrite-include '<limits\.h>=<linux/limits.h>' \ --rewrite-include '<limits\.h>=<linux/limits.h>' \
--rewrite-include '<stddef\.h>=<linux/types.h>' \ --rewrite-include '<stddef\.h>=<linux/types.h>' \
--rewrite-include '"\.\./zstd.h"=<linux/zstd.h>' \
--rewrite-include '"(\.\./common/)?zstd_errors.h"=<linux/zstd_errors.h>' \
--sed 's,/\*\*\*,/* *,g' \
--sed 's,/\*\*,/*,g' \
-DZSTD_NO_INTRINSICS \ -DZSTD_NO_INTRINSICS \
-DZSTD_NO_UNUSED_FUNCTIONS \ -DZSTD_NO_UNUSED_FUNCTIONS \
-DZSTD_LEGACY_SUPPORT=0 \ -DZSTD_LEGACY_SUPPORT=0 \
@@ -39,6 +35,7 @@ libzstd:
-DZSTD_ADDRESS_SANITIZER=0 \ -DZSTD_ADDRESS_SANITIZER=0 \
-DZSTD_MEMORY_SANITIZER=0 \ -DZSTD_MEMORY_SANITIZER=0 \
-DZSTD_COMPRESS_HEAPMODE=1 \ -DZSTD_COMPRESS_HEAPMODE=1 \
-UZSTD_NO_INLINE \
-UNO_PREFETCH \ -UNO_PREFETCH \
-U__cplusplus \ -U__cplusplus \
-UZSTD_DLL_EXPORT \ -UZSTD_DLL_EXPORT \
@@ -49,13 +46,8 @@ libzstd:
-U_WIN32 \ -U_WIN32 \
-RZSTDLIB_VISIBILITY= \ -RZSTDLIB_VISIBILITY= \
-RZSTDERRORLIB_VISIBILITY= \ -RZSTDERRORLIB_VISIBILITY= \
-RZSTD_FALLTHROUGH=fallthrough \
-DZSTD_HAVE_WEAK_SYMBOLS=0 \ -DZSTD_HAVE_WEAK_SYMBOLS=0 \
-DZSTD_TRACE=0 \ -DZSTD_TRACE=0
-DZSTD_NO_TRACE \
-DZSTD_LINUX_KERNEL
mv linux/lib/zstd/zstd.h linux/include/linux/zstd_lib.h
mv linux/lib/zstd/common/zstd_errors.h linux/include/linux/
cp linux_zstd.h linux/include/linux/zstd.h cp linux_zstd.h linux/include/linux/zstd.h
cp zstd_compress_module.c linux/lib/zstd cp zstd_compress_module.c linux/lib/zstd
cp zstd_decompress_module.c linux/lib/zstd cp zstd_decompress_module.c linux/lib/zstd
@@ -70,18 +62,15 @@ import: libzstd
rm -f $(LINUX)/include/linux/zstd_errors.h rm -f $(LINUX)/include/linux/zstd_errors.h
rm -rf $(LINUX)/lib/zstd rm -rf $(LINUX)/lib/zstd
cp linux/include/linux/zstd.h $(LINUX)/include/linux cp linux/include/linux/zstd.h $(LINUX)/include/linux
cp linux/include/linux/zstd_lib.h $(LINUX)/include/linux
cp linux/include/linux/zstd_errors.h $(LINUX)/include/linux
cp -r linux/lib/zstd $(LINUX)/lib cp -r linux/lib/zstd $(LINUX)/lib
import-upstream: import-upstream:
rm -rf $(LINUX)/lib/zstd rm -rf $(LINUX)/lib/zstd
mkdir $(LINUX)/lib/zstd mkdir $(LINUX)/lib/zstd
cp ../../lib/zstd.h $(LINUX)/include/linux/zstd_lib.h cp ../../lib/zstd.h $(LINUX)/lib/zstd
cp -r ../../lib/common $(LINUX)/lib/zstd cp -r ../../lib/common $(LINUX)/lib/zstd
cp -r ../../lib/compress $(LINUX)/lib/zstd cp -r ../../lib/compress $(LINUX)/lib/zstd
cp -r ../../lib/decompress $(LINUX)/lib/zstd cp -r ../../lib/decompress $(LINUX)/lib/zstd
mv $(LINUX)/lib/zstd/common/zstd_errors.h $(LINUX)/include/linux
rm $(LINUX)/lib/zstd/common/threading.* rm $(LINUX)/lib/zstd/common/threading.*
rm $(LINUX)/lib/zstd/common/pool.* rm $(LINUX)/lib/zstd/common/pool.*
rm $(LINUX)/lib/zstd/common/xxhash.* rm $(LINUX)/lib/zstd/common/xxhash.*
+1 -10
View File
@@ -1,13 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ /* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) Facebook, Inc.
* 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.
*/
/* /*
* This file includes every .c file needed for decompression. * This file includes every .c file needed for decompression.
+3 -10
View File
@@ -1,16 +1,9 @@
# SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause # SPDX-License-Identifier: GPL-2.0-only
# ################################################################
# Copyright (c) Facebook, Inc.
# 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.
# ################################################################
obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o
obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o
ccflags-y += -O3
zstd_compress-y := \ zstd_compress-y := \
zstd_compress_module.o \ zstd_compress_module.o \
common/debug.o \ common/debug.o \
+103 -91
View File
@@ -1,13 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ /* SPDX-License-Identifier: GPL-2.0-only */
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of https://github.com/facebook/zstd) and * LICENSE file in the root directory of https://github.com/facebook/zstd.
* the GPLv2 (found in the COPYING file in the root directory of * An additional grant of patent rights can be found in the PATENTS file in the
* https://github.com/facebook/zstd). You may select, at your option, one of the * same directory.
* above-listed licenses. *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation. This program is dual-licensed; you may select
* either version 2 of the GNU General Public License ("GPL") or BSD license
* ("BSD").
*/ */
#ifndef LINUX_ZSTD_H #ifndef LINUX_ZSTD_H
@@ -22,8 +27,6 @@
/* ====== Dependency ====== */ /* ====== Dependency ====== */
#include <linux/types.h> #include <linux/types.h>
#include <linux/zstd_errors.h>
#include <linux/zstd_lib.h>
/* ====== Helper Functions ====== */ /* ====== Helper Functions ====== */
/** /**
@@ -42,18 +45,13 @@ size_t zstd_compress_bound(size_t src_size);
*/ */
unsigned int zstd_is_error(size_t code); unsigned int zstd_is_error(size_t code);
/**
* enum zstd_error_code - zstd error codes
*/
typedef ZSTD_ErrorCode zstd_error_code;
/** /**
* zstd_get_error_code() - translates an error function result to an error code * zstd_get_error_code() - translates an error function result to an error code
* @code: The function result for which zstd_is_error(code) is true. * @code: The function result for which zstd_is_error(code) is true.
* *
* Return: A unique error code for this error. * Return: A unique error code for this error.
*/ */
zstd_error_code zstd_get_error_code(size_t code); int zstd_get_error_code(size_t code);
/** /**
* zstd_get_error_name() - translates an error function result to a string * zstd_get_error_name() - translates an error function result to a string
@@ -63,67 +61,76 @@ zstd_error_code zstd_get_error_code(size_t code);
*/ */
const char *zstd_get_error_name(size_t code); const char *zstd_get_error_name(size_t code);
/**
* zstd_min_clevel() - minimum allowed compression level
*
* Return: The minimum allowed compression level.
*/
int zstd_min_clevel(void);
/**
* zstd_max_clevel() - maximum allowed compression level
*
* Return: The maximum allowed compression level.
*/
int zstd_max_clevel(void);
/* ====== Parameter Selection ====== */ /* ====== Parameter Selection ====== */
/** /**
* enum zstd_strategy - zstd compression search strategy * enum zstd_strategy - zstd compression search strategy
* *
* From faster to stronger. See zstd_lib.h. * From faster to stronger.
*/ */
typedef ZSTD_strategy zstd_strategy; enum zstd_strategy {
zstd_fast = 1,
zstd_dfast = 2,
zstd_greedy = 3,
zstd_lazy = 4,
zstd_lazy2 = 5,
zstd_btlazy2 = 6,
zstd_btopt = 7,
zstd_btultra = 8,
zstd_btultra2 = 9
};
/** /**
* struct zstd_compression_parameters - zstd compression parameters * struct zstd_compression_parameters - zstd compression parameters
* @windowLog: Log of the largest match distance. Larger means more * @window_log: Log of the largest match distance. Larger means more
* compression, and more memory needed during decompression. * compression, and more memory needed during decompression.
* @chainLog: Fully searched segment. Larger means more compression, * @chain_log: Fully searched segment. Larger means more compression,
* slower, and more memory (useless for fast). * slower, and more memory (useless for fast).
* @hashLog: Dispatch table. Larger means more compression, * @hash_log: Dispatch table. Larger means more compression,
* slower, and more memory. * slower, and more memory.
* @searchLog: Number of searches. Larger means more compression and slower. * @search_log: Number of searches. Larger means more compression and slower.
* @searchLength: Match length searched. Larger means faster decompression, * @search_length: Match length searched. Larger means faster decompression,
* sometimes less compression. * sometimes less compression.
* @targetLength: Acceptable match size for optimal parser (only). Larger means * @target_length: Acceptable match size for optimal parser (only). Larger means
* more compression, and slower. * more compression, and slower.
* @strategy: The zstd compression strategy. * @strategy: The zstd compression strategy.
*
* See zstd_lib.h.
*/ */
typedef ZSTD_compressionParameters zstd_compression_parameters; struct zstd_compression_parameters {
unsigned int window_log;
unsigned int chain_log;
unsigned int hash_log;
unsigned int search_log;
unsigned int search_length;
unsigned int target_length;
enum zstd_strategy strategy;
};
/** /**
* struct zstd_frame_parameters - zstd frame parameters * struct zstd_frame_parameters - zstd frame parameters
* @contentSizeFlag: Controls whether content size will be present in the * @content_size_flag: Controls whether content size will be present in the
* frame header (when known). * frame header (when known).
* @checksumFlag: Controls whether a 32-bit checksum is generated at the * @checksum_flag: Controls whether a 32-bit checksum is generated at the
* end of the frame for error detection. * end of the frame for error detection.
* @noDictIDFlag: Controls whether dictID will be saved into the frame * @no_dict_id_flag: Controls whether dictID will be saved into the frame
* header when using dictionary compression. * header when using dictionary compression.
* *
* The default value is all fields set to 0. See zstd_lib.h. * The default value is all fields set to 0.
*/ */
typedef ZSTD_frameParameters zstd_frame_parameters; struct zstd_frame_parameters {
unsigned int content_size_flag;
unsigned int checksum_flag;
unsigned int no_dict_id_flag;
};
/** /**
* struct zstd_parameters - zstd parameters * struct zstd_parameters - zstd parameters
* @cParams: The compression parameters. * @cparams: The compression parameters.
* @fParams: The frame parameters. * @fparams: The frame parameters.
*/ */
typedef ZSTD_parameters zstd_parameters; struct zstd_parameters {
struct zstd_compression_parameters cparams;
struct zstd_frame_parameters fparams;
};
/** /**
* zstd_get_params() - returns zstd_parameters for selected level * zstd_get_params() - returns zstd_parameters for selected level
@@ -133,12 +140,12 @@ typedef ZSTD_parameters zstd_parameters;
* *
* Return: The selected zstd_parameters. * Return: The selected zstd_parameters.
*/ */
zstd_parameters zstd_get_params(int level, struct zstd_parameters zstd_get_params(int level,
unsigned long long estimated_src_size); unsigned long long estimated_src_size);
/* ====== Single-pass Compression ====== */ /* ====== Single-pass Compression ====== */
typedef ZSTD_CCtx zstd_cctx; typedef struct ZSTD_CCtx_s zstd_cctx;
/** /**
* zstd_cctx_workspace_bound() - max memory needed to initialize a zstd_cctx * zstd_cctx_workspace_bound() - max memory needed to initialize a zstd_cctx
@@ -151,7 +158,8 @@ typedef ZSTD_CCtx zstd_cctx;
* Return: A lower bound on the size of the workspace that is passed to * Return: A lower bound on the size of the workspace that is passed to
* zstd_init_cctx(). * zstd_init_cctx().
*/ */
size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters); size_t zstd_cctx_workspace_bound(
const struct zstd_compression_parameters *parameters);
/** /**
* zstd_init_cctx() - initialize a zstd compression context * zstd_init_cctx() - initialize a zstd compression context
@@ -178,11 +186,11 @@ zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size);
* zstd_is_error(). * zstd_is_error().
*/ */
size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity, size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity,
const void *src, size_t src_size, const zstd_parameters *parameters); const void *src, size_t src_size, const struct zstd_parameters *parameters);
/* ====== Single-pass Decompression ====== */ /* ====== Single-pass Decompression ====== */
typedef ZSTD_DCtx zstd_dctx; typedef struct ZSTD_DCtx_s zstd_dctx;
/** /**
* zstd_dctx_workspace_bound() - max memory needed to initialize a zstd_dctx * zstd_dctx_workspace_bound() - max memory needed to initialize a zstd_dctx
@@ -228,10 +236,12 @@ size_t zstd_decompress_dctx(zstd_dctx *dctx, void *dst, size_t dst_capacity,
* @size: Size of the input buffer. * @size: Size of the input buffer.
* @pos: Position where reading stopped. Will be updated. * @pos: Position where reading stopped. Will be updated.
* Necessarily 0 <= pos <= size. * Necessarily 0 <= pos <= size.
*
* See zstd_lib.h.
*/ */
typedef ZSTD_inBuffer zstd_in_buffer; struct zstd_in_buffer {
const void *src;
size_t size;
size_t pos;
};
/** /**
* struct zstd_out_buffer - output buffer for streaming * struct zstd_out_buffer - output buffer for streaming
@@ -239,14 +249,16 @@ typedef ZSTD_inBuffer zstd_in_buffer;
* @size: Size of the output buffer. * @size: Size of the output buffer.
* @pos: Position where writing stopped. Will be updated. * @pos: Position where writing stopped. Will be updated.
* Necessarily 0 <= pos <= size. * Necessarily 0 <= pos <= size.
*
* See zstd_lib.h.
*/ */
typedef ZSTD_outBuffer zstd_out_buffer; struct zstd_out_buffer {
void *dst;
size_t size;
size_t pos;
};
/* ====== Streaming Compression ====== */ /* ====== Streaming Compression ====== */
typedef ZSTD_CStream zstd_cstream; typedef struct ZSTD_CCtx_s zstd_cstream;
/** /**
* zstd_cstream_workspace_bound() - memory needed to initialize a zstd_cstream * zstd_cstream_workspace_bound() - memory needed to initialize a zstd_cstream
@@ -255,7 +267,8 @@ typedef ZSTD_CStream zstd_cstream;
* Return: A lower bound on the size of the workspace that is passed to * Return: A lower bound on the size of the workspace that is passed to
* zstd_init_cstream(). * zstd_init_cstream().
*/ */
size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams); size_t zstd_cstream_workspace_bound(
const struct zstd_compression_parameters *cparams);
/** /**
* zstd_init_cstream() - initialize a zstd streaming compression context * zstd_init_cstream() - initialize a zstd streaming compression context
@@ -272,7 +285,7 @@ size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams);
* *
* Return: The zstd streaming compression context or NULL on error. * Return: The zstd streaming compression context or NULL on error.
*/ */
zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters, zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters,
unsigned long long pledged_src_size, void *workspace, size_t workspace_size); unsigned long long pledged_src_size, void *workspace, size_t workspace_size);
/** /**
@@ -307,8 +320,8 @@ size_t zstd_reset_cstream(zstd_cstream *cstream,
* function call or an error, which can be checked using * function call or an error, which can be checked using
* zstd_is_error(). * zstd_is_error().
*/ */
size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output, size_t zstd_compress_stream(zstd_cstream *cstream,
zstd_in_buffer *input); struct zstd_out_buffer *output, struct zstd_in_buffer *input);
/** /**
* zstd_flush_stream() - flush internal buffers into output * zstd_flush_stream() - flush internal buffers into output
@@ -323,7 +336,7 @@ size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output,
* Return: The number of bytes still present within internal buffers or an * Return: The number of bytes still present within internal buffers or an
* error, which can be checked using zstd_is_error(). * error, which can be checked using zstd_is_error().
*/ */
size_t zstd_flush_stream(zstd_cstream *cstream, zstd_out_buffer *output); size_t zstd_flush_stream(zstd_cstream *cstream, struct zstd_out_buffer *output);
/** /**
* zstd_end_stream() - flush internal buffers into output and end the frame * zstd_end_stream() - flush internal buffers into output and end the frame
@@ -337,11 +350,11 @@ size_t zstd_flush_stream(zstd_cstream *cstream, zstd_out_buffer *output);
* Return: The number of bytes still present within internal buffers or an * Return: The number of bytes still present within internal buffers or an
* error, which can be checked using zstd_is_error(). * error, which can be checked using zstd_is_error().
*/ */
size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output); size_t zstd_end_stream(zstd_cstream *cstream, struct zstd_out_buffer *output);
/* ====== Streaming Decompression ====== */ /* ====== Streaming Decompression ====== */
typedef ZSTD_DStream zstd_dstream; typedef struct ZSTD_DCtx_s zstd_dstream;
/** /**
* zstd_dstream_workspace_bound() - memory needed to initialize a zstd_dstream * zstd_dstream_workspace_bound() - memory needed to initialize a zstd_dstream
@@ -398,8 +411,8 @@ size_t zstd_reset_dstream(zstd_dstream *dstream);
* using zstd_is_error(). The size hint will never load more than the * using zstd_is_error(). The size hint will never load more than the
* frame. * frame.
*/ */
size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output, size_t zstd_decompress_stream(zstd_dstream *dstream,
zstd_in_buffer *input); struct zstd_out_buffer *output, struct zstd_in_buffer *input);
/* ====== Frame Inspection Functions ====== */ /* ====== Frame Inspection Functions ====== */
@@ -418,21 +431,20 @@ size_t zstd_find_frame_compressed_size(const void *src, size_t src_size);
/** /**
* 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 * @frame_content_size: The frame content size, or 0 if not present.
* present. * @window_size: The window size, or 0 if the frame is a skippable frame.
* @windowSize: The window size, or 0 if the frame is a skippable frame. * @dict_id: The dictionary id, or 0 if not present.
* @blockSizeMax: The maximum block size. * @checksum_flag: Whether a checksum was used.
* @frameType: The frame type (zstd or skippable)
* @headerSize: The size of the frame header.
* @dictID: The dictionary id, or 0 if not present.
* @checksumFlag: Whether a checksum was used.
*
* See zstd_lib.h.
*/ */
typedef ZSTD_frameHeader zstd_frame_header; struct zstd_frame_params {
unsigned long long frame_content_size;
unsigned int window_size;
unsigned int dict_id;
unsigned int checksum_flag;
};
/** /**
* zstd_get_frame_header() - extracts parameters from a zstd or skippable frame * zstd_get_frame_params() - extracts parameters from a zstd or skippable frame
* @params: On success the frame parameters are written here. * @params: On success the frame parameters are written here.
* @src: The source buffer. It must point to a zstd or skippable frame. * @src: The source buffer. It must point to a zstd or skippable frame.
* @src_size: The size of the source buffer. * @src_size: The size of the source buffer.
@@ -441,7 +453,7 @@ typedef ZSTD_frameHeader zstd_frame_header;
* must be provided to make forward progress. Otherwise it returns * must be provided to make forward progress. Otherwise it returns
* an error, which can be checked using zstd_is_error(). * an error, which can be checked using zstd_is_error().
*/ */
size_t zstd_get_frame_header(zstd_frame_header *params, const void *src, size_t zstd_get_frame_params(struct zstd_frame_params *params, const void *src,
size_t src_size); size_t src_size);
#endif /* LINUX_ZSTD_H */ #endif /* LINUX_ZSTD_H */
+1 -2
View File
@@ -1,6 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
-10
View File
@@ -1,12 +1,3 @@
# ################################################################
# Copyright (c) Facebook, Inc.
# 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.
# ################################################################
LINUX := ../linux LINUX := ../linux
LINUX_ZSTDLIB := $(LINUX)/lib/zstd LINUX_ZSTDLIB := $(LINUX)/lib/zstd
@@ -38,7 +29,6 @@ run-test: test static_test
.PHONY: .PHONY:
clean: clean:
$(RM) -f $(LINUX_ZSTDLIB)/*.o
$(RM) -f $(LINUX_ZSTDLIB)/**/*.o $(RM) -f $(LINUX_ZSTDLIB)/**/*.o
$(RM) -f *.o *.a $(RM) -f *.o *.a
$(RM) -f test $(RM) -f test
@@ -4,23 +4,13 @@
#include <assert.h> #include <assert.h>
#include <linux/types.h> #include <linux/types.h>
#ifndef __LITTLE_ENDIAN #define _LITTLE_ENDIAN 1
# if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN__)
# define __LITTLE_ENDIAN 1
# endif
#endif
#ifdef __LITTLE_ENDIAN
# define _IS_LITTLE_ENDIAN 1
#else
# define _IS_LITTLE_ENDIAN 0
#endif
static unsigned _isLittleEndian(void) static unsigned _isLittleEndian(void)
{ {
const union { uint32_t u; uint8_t c[4]; } one = { 1 }; const union { uint32_t u; uint8_t c[4]; } one = { 1 };
assert(_IS_LITTLE_ENDIAN == one.c[0]); assert(_LITTLE_ENDIAN == one.c[0]);
return _IS_LITTLE_ENDIAN; return _LITTLE_ENDIAN;
} }
static uint16_t _swap16(uint16_t in) static uint16_t _swap16(uint16_t in)
@@ -175,7 +165,7 @@ extern void __bad_unaligned_access_size(void);
(void)0; \ (void)0; \
}) })
#if _IS_LITTLE_ENDIAN #if _LITTLE_ENDIAN
# define get_unaligned __get_unaligned_le # define get_unaligned __get_unaligned_le
# define put_unaligned __put_unaligned_le # define put_unaligned __put_unaligned_le
#else #else
@@ -14,12 +14,4 @@
#define inline __inline __attribute__((unused)) #define inline __inline __attribute__((unused))
#endif #endif
#ifndef noinline
#define noinline __attribute__((noinline))
#endif
#ifndef fallthrough
#define fallthrough __attribute__((__fallthrough__))
#endif
#endif #endif
@@ -12,8 +12,4 @@
#define WARN_ON(x) #define WARN_ON(x)
#define PTR_ALIGN(p, a) (typeof(p))ALIGN((unsigned long long)(p), (a))
#define ALIGN(x, a) ALIGN_MASK((x), (a) - 1)
#define ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#endif #endif
+1
View File
@@ -36,6 +36,7 @@ test_not_present "ZSTD_NO_INTRINSICS"
test_not_present "ZSTD_NO_UNUSED_FUNCTIONS" test_not_present "ZSTD_NO_UNUSED_FUNCTIONS"
test_not_present "ZSTD_LEGACY_SUPPORT" test_not_present "ZSTD_LEGACY_SUPPORT"
test_not_present "STATIC_BMI2" test_not_present "STATIC_BMI2"
test_not_present "ZSTD_NO_INLINE"
test_not_present "ZSTD_DLL_EXPORT" test_not_present "ZSTD_DLL_EXPORT"
test_not_present "ZSTD_DLL_IMPORT" test_not_present "ZSTD_DLL_IMPORT"
test_not_present "__ICCARM__" test_not_present "__ICCARM__"
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+11 -20
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 7-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -57,10 +57,10 @@ static void test_btrfs(test_data_t const *data) {
fprintf(stderr, "testing btrfs use cases... "); fprintf(stderr, "testing btrfs use cases... ");
size_t const size = MIN(data->dataSize, 128 * 1024); size_t const size = MIN(data->dataSize, 128 * 1024);
for (int level = -1; level < 16; ++level) { for (int level = -1; level < 16; ++level) {
zstd_parameters params = zstd_get_params(level, size); struct zstd_parameters params = zstd_get_params(level, size);
CONTROL(params.cParams.windowLog <= 17); CONTROL(params.cparams.window_log <= 17);
size_t const workspaceSize = size_t const workspaceSize =
MAX(zstd_cstream_workspace_bound(&params.cParams), MAX(zstd_cstream_workspace_bound(&params.cparams),
zstd_dstream_workspace_bound(size)); zstd_dstream_workspace_bound(size));
void *workspace = malloc(workspaceSize); void *workspace = malloc(workspaceSize);
CONTROL(workspace != NULL); CONTROL(workspace != NULL);
@@ -72,8 +72,8 @@ static void test_btrfs(test_data_t const *data) {
{ {
zstd_cstream *cctx = zstd_init_cstream(&params, size, workspace, workspaceSize); zstd_cstream *cctx = zstd_init_cstream(&params, size, workspace, workspaceSize);
CONTROL(cctx != NULL); CONTROL(cctx != NULL);
zstd_out_buffer out = {NULL, 0, 0}; struct zstd_out_buffer out = {NULL, 0, 0};
zstd_in_buffer in = {NULL, 0, 0}; struct zstd_in_buffer in = {NULL, 0, 0};
for (;;) { for (;;) {
if (in.pos == in.size) { if (in.pos == in.size) {
in.src = ip; in.src = ip;
@@ -107,10 +107,10 @@ static void test_btrfs(test_data_t const *data) {
op = data->data2; op = data->data2;
oend = op + size; oend = op + size;
{ {
zstd_dstream *dctx = zstd_init_dstream(1ULL << params.cParams.windowLog, workspace, workspaceSize); zstd_dstream *dctx = zstd_init_dstream(1ULL << params.cparams.window_log, workspace, workspaceSize);
CONTROL(dctx != NULL); CONTROL(dctx != NULL);
zstd_out_buffer out = {NULL, 0, 0}; struct zstd_out_buffer out = {NULL, 0, 0};
zstd_in_buffer in = {NULL, 0, 0}; struct zstd_in_buffer in = {NULL, 0, 0};
for (;;) { for (;;) {
if (in.pos == in.size) { if (in.pos == in.size) {
in.src = ip; in.src = ip;
@@ -144,8 +144,8 @@ static void test_decompress_unzstd(test_data_t const *data) {
fprintf(stderr, "Testing decompress unzstd... "); fprintf(stderr, "Testing decompress unzstd... ");
size_t cSize; size_t cSize;
{ {
zstd_parameters params = zstd_get_params(19, 0); struct zstd_parameters params = zstd_get_params(19, 0);
size_t const wkspSize = zstd_cctx_workspace_bound(&params.cParams); size_t const wkspSize = zstd_cctx_workspace_bound(&params.cparams);
void* wksp = malloc(wkspSize); void* wksp = malloc(wkspSize);
CONTROL(wksp != NULL); CONTROL(wksp != NULL);
zstd_cctx* cctx = zstd_init_cctx(wksp, wkspSize); zstd_cctx* cctx = zstd_init_cctx(wksp, wkspSize);
@@ -169,13 +169,6 @@ static void test_decompress_unzstd(test_data_t const *data) {
fprintf(stderr, "Ok\n"); fprintf(stderr, "Ok\n");
} }
static void test_f2fs() {
fprintf(stderr, "testing f2fs uses... ");
CONTROL(zstd_min_clevel() < 0);
CONTROL(zstd_max_clevel() == 22);
fprintf(stderr, "Ok\n");
}
static char *g_stack = NULL; static char *g_stack = NULL;
static void __attribute__((noinline)) use(void *x) { static void __attribute__((noinline)) use(void *x) {
@@ -202,7 +195,6 @@ static void __attribute__((noinline)) check_stack() {
static void test_stack_usage(test_data_t const *data) { static void test_stack_usage(test_data_t const *data) {
set_stack(); set_stack();
test_f2fs();
test_btrfs(data); test_btrfs(data);
test_decompress_unzstd(data); test_decompress_unzstd(data);
check_stack(); check_stack();
@@ -210,7 +202,6 @@ static void test_stack_usage(test_data_t const *data) {
int main(void) { int main(void) {
test_data_t data = create_test_data(); test_data_t data = create_test_data();
test_f2fs();
test_btrfs(&data); test_btrfs(&data);
test_decompress_unzstd(&data); test_decompress_unzstd(&data);
test_stack_usage(&data); test_stack_usage(&data);
+121 -75
View File
@@ -1,87 +1,102 @@
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause // SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) Facebook, Inc.
* 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 <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/zstd.h> #include <linux/zstd.h>
#include "zstd.h"
#include "common/zstd_deps.h" #include "common/zstd_deps.h"
#include "common/zstd_internal.h" #include "common/zstd_internal.h"
#define ZSTD_FORWARD_IF_ERR(ret) \ static void zstd_check_structs(void) {
do { \ /* Check that the structs have the same size. */
size_t const __ret = (ret); \ ZSTD_STATIC_ASSERT(sizeof(ZSTD_parameters) ==
if (ZSTD_isError(__ret)) \ sizeof(struct zstd_parameters));
return __ret; \ ZSTD_STATIC_ASSERT(sizeof(ZSTD_compressionParameters) ==
} while (0) sizeof(struct zstd_compression_parameters));
ZSTD_STATIC_ASSERT(sizeof(ZSTD_frameParameters) ==
static size_t zstd_cctx_init(zstd_cctx *cctx, const zstd_parameters *parameters, sizeof(struct zstd_frame_parameters));
unsigned long long pledged_src_size) /* Zstd guarantees that the layout of the structs never change. Verify it. */
{ ZSTD_STATIC_ASSERT(offsetof(ZSTD_parameters, cParams) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_reset( offsetof(struct zstd_parameters, cparams));
cctx, ZSTD_reset_session_and_parameters)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_parameters, fParams) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setPledgedSrcSize( offsetof(struct zstd_parameters, fparams));
cctx, pledged_src_size)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, windowLog) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, window_log));
cctx, ZSTD_c_windowLog, parameters->cParams.windowLog)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, chainLog) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, chain_log));
cctx, ZSTD_c_hashLog, parameters->cParams.hashLog)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, hashLog) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, hash_log));
cctx, ZSTD_c_chainLog, parameters->cParams.chainLog)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, searchLog) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, search_log));
cctx, ZSTD_c_searchLog, parameters->cParams.searchLog)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, minMatch) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, search_length));
cctx, ZSTD_c_minMatch, parameters->cParams.minMatch)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, targetLength) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, target_length));
cctx, ZSTD_c_targetLength, parameters->cParams.targetLength)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, strategy) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_compression_parameters, strategy));
cctx, ZSTD_c_strategy, parameters->cParams.strategy)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_frameParameters, contentSizeFlag) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_frame_parameters, content_size_flag));
cctx, ZSTD_c_contentSizeFlag, parameters->fParams.contentSizeFlag)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_frameParameters, checksumFlag) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_frame_parameters, checksum_flag));
cctx, ZSTD_c_checksumFlag, parameters->fParams.checksumFlag)); ZSTD_STATIC_ASSERT(offsetof(ZSTD_frameParameters, noDictIDFlag) ==
ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter( offsetof(struct zstd_frame_parameters, no_dict_id_flag));
cctx, ZSTD_c_dictIDFlag, !parameters->fParams.noDictIDFlag)); /* Check that the strategies are the same. This can change. */
return 0; ZSTD_STATIC_ASSERT((int)ZSTD_fast == (int)zstd_fast);
ZSTD_STATIC_ASSERT((int)ZSTD_dfast == (int)zstd_dfast);
ZSTD_STATIC_ASSERT((int)ZSTD_greedy == (int)zstd_greedy);
ZSTD_STATIC_ASSERT((int)ZSTD_lazy == (int)zstd_lazy);
ZSTD_STATIC_ASSERT((int)ZSTD_lazy2 == (int)zstd_lazy2);
ZSTD_STATIC_ASSERT((int)ZSTD_btlazy2 == (int)zstd_btlazy2);
ZSTD_STATIC_ASSERT((int)ZSTD_btopt == (int)zstd_btopt);
ZSTD_STATIC_ASSERT((int)ZSTD_btultra == (int)zstd_btultra);
ZSTD_STATIC_ASSERT((int)ZSTD_btultra2 == (int)zstd_btultra2);
/* Check input buffer */
ZSTD_STATIC_ASSERT(sizeof(ZSTD_inBuffer) == sizeof(struct zstd_in_buffer));
ZSTD_STATIC_ASSERT(offsetof(ZSTD_inBuffer, src) ==
offsetof(struct zstd_in_buffer, src));
ZSTD_STATIC_ASSERT(offsetof(ZSTD_inBuffer, size) ==
offsetof(struct zstd_in_buffer, size));
ZSTD_STATIC_ASSERT(offsetof(ZSTD_inBuffer, pos) ==
offsetof(struct zstd_in_buffer, pos));
/* Check output buffer */
ZSTD_STATIC_ASSERT(sizeof(ZSTD_outBuffer) ==
sizeof(struct zstd_out_buffer));
ZSTD_STATIC_ASSERT(offsetof(ZSTD_outBuffer, dst) ==
offsetof(struct zstd_out_buffer, dst));
ZSTD_STATIC_ASSERT(offsetof(ZSTD_outBuffer, size) ==
offsetof(struct zstd_out_buffer, size));
ZSTD_STATIC_ASSERT(offsetof(ZSTD_outBuffer, pos) ==
offsetof(struct zstd_out_buffer, pos));
} }
int zstd_min_clevel(void)
{
return ZSTD_minCLevel();
}
EXPORT_SYMBOL(zstd_min_clevel);
int zstd_max_clevel(void)
{
return ZSTD_maxCLevel();
}
EXPORT_SYMBOL(zstd_max_clevel);
size_t zstd_compress_bound(size_t src_size) size_t zstd_compress_bound(size_t src_size)
{ {
return ZSTD_compressBound(src_size); return ZSTD_compressBound(src_size);
} }
EXPORT_SYMBOL(zstd_compress_bound); EXPORT_SYMBOL(zstd_compress_bound);
zstd_parameters zstd_get_params(int level, struct zstd_parameters zstd_get_params(int level,
unsigned long long estimated_src_size) unsigned long long estimated_src_size)
{ {
return ZSTD_getParams(level, estimated_src_size, 0); const ZSTD_parameters params = ZSTD_getParams(level, estimated_src_size, 0);
struct zstd_parameters out;
/* no-op */
zstd_check_structs();
ZSTD_memcpy(&out, &params, sizeof(out));
return out;
} }
EXPORT_SYMBOL(zstd_get_params); EXPORT_SYMBOL(zstd_get_params);
size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *cparams) size_t zstd_cctx_workspace_bound(
const struct zstd_compression_parameters *cparams)
{ {
return ZSTD_estimateCCtxSize_usingCParams(*cparams); ZSTD_compressionParameters p;
ZSTD_memcpy(&p, cparams, sizeof(p));
return ZSTD_estimateCCtxSize_usingCParams(p);
} }
EXPORT_SYMBOL(zstd_cctx_workspace_bound); EXPORT_SYMBOL(zstd_cctx_workspace_bound);
@@ -94,23 +109,31 @@ zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size)
EXPORT_SYMBOL(zstd_init_cctx); EXPORT_SYMBOL(zstd_init_cctx);
size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity, size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity,
const void *src, size_t src_size, const zstd_parameters *parameters) const void *src, size_t src_size, const struct zstd_parameters *parameters)
{ {
ZSTD_FORWARD_IF_ERR(zstd_cctx_init(cctx, parameters, src_size)); ZSTD_parameters p;
return ZSTD_compress2(cctx, dst, dst_capacity, src, src_size);
ZSTD_memcpy(&p, parameters, sizeof(p));
return ZSTD_compress_advanced(cctx, dst, dst_capacity, src, src_size, NULL, 0, p);
} }
EXPORT_SYMBOL(zstd_compress_cctx); EXPORT_SYMBOL(zstd_compress_cctx);
size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams) size_t zstd_cstream_workspace_bound(
const struct zstd_compression_parameters *cparams)
{ {
return ZSTD_estimateCStreamSize_usingCParams(*cparams); ZSTD_compressionParameters p;
ZSTD_memcpy(&p, cparams, sizeof(p));
return ZSTD_estimateCStreamSize_usingCParams(p);
} }
EXPORT_SYMBOL(zstd_cstream_workspace_bound); EXPORT_SYMBOL(zstd_cstream_workspace_bound);
zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters, zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters,
unsigned long long pledged_src_size, void *workspace, size_t workspace_size) unsigned long long pledged_src_size, void *workspace, size_t workspace_size)
{ {
ZSTD_parameters p;
zstd_cstream *cstream; zstd_cstream *cstream;
size_t ret;
if (workspace == NULL) if (workspace == NULL)
return NULL; return NULL;
@@ -123,7 +146,9 @@ zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters,
if (pledged_src_size == 0) if (pledged_src_size == 0)
pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN; pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN;
if (ZSTD_isError(zstd_cctx_init(cstream, parameters, pledged_src_size))) ZSTD_memcpy(&p, parameters, sizeof(p));
ret = ZSTD_initCStream_advanced(cstream, NULL, 0, p, pledged_src_size);
if (ZSTD_isError(ret))
return NULL; return NULL;
return cstream; return cstream;
@@ -137,22 +162,43 @@ size_t zstd_reset_cstream(zstd_cstream *cstream,
} }
EXPORT_SYMBOL(zstd_reset_cstream); EXPORT_SYMBOL(zstd_reset_cstream);
size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output, size_t zstd_compress_stream(zstd_cstream *cstream,
zstd_in_buffer *input) struct zstd_out_buffer *output, struct zstd_in_buffer *input)
{ {
return ZSTD_compressStream(cstream, output, input); ZSTD_outBuffer o;
ZSTD_inBuffer i;
size_t ret;
ZSTD_memcpy(&o, output, sizeof(o));
ZSTD_memcpy(&i, input, sizeof(i));
ret = ZSTD_compressStream(cstream, &o, &i);
ZSTD_memcpy(output, &o, sizeof(o));
ZSTD_memcpy(input, &i, sizeof(i));
return ret;
} }
EXPORT_SYMBOL(zstd_compress_stream); EXPORT_SYMBOL(zstd_compress_stream);
size_t zstd_flush_stream(zstd_cstream *cstream, zstd_out_buffer *output) size_t zstd_flush_stream(zstd_cstream *cstream, struct zstd_out_buffer *output)
{ {
return ZSTD_flushStream(cstream, output); ZSTD_outBuffer o;
size_t ret;
ZSTD_memcpy(&o, output, sizeof(o));
ret = ZSTD_flushStream(cstream, &o);
ZSTD_memcpy(output, &o, sizeof(o));
return ret;
} }
EXPORT_SYMBOL(zstd_flush_stream); EXPORT_SYMBOL(zstd_flush_stream);
size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output) size_t zstd_end_stream(zstd_cstream *cstream, struct zstd_out_buffer *output)
{ {
return ZSTD_endStream(cstream, output); ZSTD_outBuffer o;
size_t ret;
ZSTD_memcpy(&o, output, sizeof(o));
ret = ZSTD_endStream(cstream, &o);
ZSTD_memcpy(output, &o, sizeof(o));
return ret;
} }
EXPORT_SYMBOL(zstd_end_stream); EXPORT_SYMBOL(zstd_end_stream);
+34 -17
View File
@@ -1,20 +1,13 @@
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause // SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) Facebook, Inc.
* 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 <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/zstd.h> #include <linux/zstd.h>
#include "zstd.h"
#include "common/zstd_deps.h" #include "common/zstd_deps.h"
#include "common/zstd_errors.h"
/* Common symbols. zstd_compress must depend on zstd_decompress. */ /* Common symbols. zstd_compress must depend on zstd_decompress. */
@@ -24,7 +17,7 @@ unsigned int zstd_is_error(size_t code)
} }
EXPORT_SYMBOL(zstd_is_error); EXPORT_SYMBOL(zstd_is_error);
zstd_error_code zstd_get_error_code(size_t code) int zstd_get_error_code(size_t code)
{ {
return ZSTD_getErrorCode(code); return ZSTD_getErrorCode(code);
} }
@@ -81,10 +74,19 @@ size_t zstd_reset_dstream(zstd_dstream *dstream)
} }
EXPORT_SYMBOL(zstd_reset_dstream); EXPORT_SYMBOL(zstd_reset_dstream);
size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output, size_t zstd_decompress_stream(zstd_dstream *dstream,
zstd_in_buffer *input) struct zstd_out_buffer *output, struct zstd_in_buffer *input)
{ {
return ZSTD_decompressStream(dstream, output, input); ZSTD_outBuffer o;
ZSTD_inBuffer i;
size_t ret;
ZSTD_memcpy(&o, output, sizeof(o));
ZSTD_memcpy(&i, input, sizeof(i));
ret = ZSTD_decompressStream(dstream, &o, &i);
ZSTD_memcpy(output, &o, sizeof(o));
ZSTD_memcpy(input, &i, sizeof(i));
return ret;
} }
EXPORT_SYMBOL(zstd_decompress_stream); EXPORT_SYMBOL(zstd_decompress_stream);
@@ -94,12 +96,27 @@ size_t zstd_find_frame_compressed_size(const void *src, size_t src_size)
} }
EXPORT_SYMBOL(zstd_find_frame_compressed_size); EXPORT_SYMBOL(zstd_find_frame_compressed_size);
size_t zstd_get_frame_header(zstd_frame_header *header, const void *src, size_t zstd_get_frame_params(struct zstd_frame_params *params, const void *src,
size_t src_size) size_t src_size)
{ {
return ZSTD_getFrameHeader(header, src, src_size); ZSTD_frameHeader h;
const size_t ret = ZSTD_getFrameHeader(&h, src, src_size);
if (ret != 0)
return ret;
if (h.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN)
params->frame_content_size = h.frameContentSize;
else
params->frame_content_size = 0;
params->window_size = h.windowSize;
params->dict_id = h.dictID;
params->checksum_flag = h.checksumFlag;
return ret;
} }
EXPORT_SYMBOL(zstd_get_frame_header); EXPORT_SYMBOL(zstd_get_frame_params);
MODULE_LICENSE("Dual BSD/GPL"); MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("Zstd Decompressor"); MODULE_DESCRIPTION("Zstd Decompressor");
+1 -2
View File
@@ -1,6 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+5 -5
View File
@@ -16,13 +16,13 @@ ZSTDLIB = $(ZSTDLIB_PATH)/$(ZSTDLIB_NAME)
CPPFLAGS += -I../ -I$(ZSTDLIB_PATH) -I$(ZSTDLIB_PATH)/common CPPFLAGS += -I../ -I$(ZSTDLIB_PATH) -I$(ZSTDLIB_PATH)/common
CFLAGS ?= -O3 CFLAGS ?= -O3
CFLAGS += -g -Wall -Wextra -Wcast-qual -Wcast-align -Wconversion \ CFLAGS += -g
-Wformat=2 -Wstrict-aliasing=1
SEEKABLE_OBJS = ../zstdseek_compress.c ../zstdseek_decompress.c $(ZSTDLIB) SEEKABLE_OBJS = ../zstdseek_compress.c ../zstdseek_decompress.c $(ZSTDLIB)
.PHONY: default clean test .PHONY: default clean test
default: test
default: seekable_tests
test: seekable_tests test: seekable_tests
./seekable_tests ./seekable_tests
@@ -30,9 +30,9 @@ test: seekable_tests
$(ZSTDLIB): $(ZSTDLIB):
$(MAKE) -C $(ZSTDLIB_PATH) $(ZSTDLIB_NAME) $(MAKE) -C $(ZSTDLIB_PATH) $(ZSTDLIB_NAME)
seekable_tests : $(SEEKABLE_OBJS) seekable_tests : seekable_tests.c $(SEEKABLE_OBJS)
clean: clean:
@$(RM) core *.o tmp* result* *.zst \ @rm -f core *.o tmp* result* *.zst \
seekable_tests seekable_tests
@echo Cleaning completed @echo Cleaning completed
+1 -134
View File
@@ -1,8 +1,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> // malloc
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include "zstd_seekable.h" #include "zstd_seekable.h"
@@ -10,83 +8,7 @@
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
unsigned testNb = 1; unsigned testNb = 1;
(void)argc; (void)argv;
printf("Beginning zstd seekable format tests...\n"); printf("Beginning zstd seekable format tests...\n");
printf("Test %u - simple round trip: ", testNb++);
{ size_t const inSize = 4000;
void* const inBuffer = malloc(inSize);
assert(inBuffer != NULL);
size_t const seekCapacity = 5000;
void* const seekBuffer = malloc(seekCapacity);
assert(seekBuffer != NULL);
size_t seekSize;
size_t const outCapacity = inSize;
void* const outBuffer = malloc(outCapacity);
assert(outBuffer != NULL);
ZSTD_seekable_CStream* const zscs = ZSTD_seekable_createCStream();
assert(zscs != NULL);
{ size_t const initStatus = ZSTD_seekable_initCStream(zscs, 9, 0 /* checksumFlag */, (unsigned)inSize /* maxFrameSize */);
assert(!ZSTD_isError(initStatus));
}
{ ZSTD_outBuffer outb = { .dst=seekBuffer, .pos=0, .size=seekCapacity };
ZSTD_inBuffer inb = { .src=inBuffer, .pos=0, .size=inSize };
size_t const cStatus = ZSTD_seekable_compressStream(zscs, &outb, &inb);
assert(!ZSTD_isError(cStatus));
assert(inb.pos == inb.size);
size_t const endStatus = ZSTD_seekable_endStream(zscs, &outb);
assert(!ZSTD_isError(endStatus));
seekSize = outb.pos;
}
ZSTD_seekable* const stream = ZSTD_seekable_create();
assert(stream != NULL);
{ size_t const initStatus = ZSTD_seekable_initBuff(stream, seekBuffer, seekSize);
assert(!ZSTD_isError(initStatus)); }
{ size_t const decStatus = ZSTD_seekable_decompress(stream, outBuffer, outCapacity, 0);
assert(decStatus == inSize); }
/* unit test ZSTD_seekTable functions */
ZSTD_seekTable* const zst = ZSTD_seekTable_create_fromSeekable(stream);
assert(zst != NULL);
unsigned const nbFrames = ZSTD_seekTable_getNumFrames(zst);
assert(nbFrames > 0);
unsigned long long const frame0Offset = ZSTD_seekTable_getFrameCompressedOffset(zst, 0);
assert(frame0Offset == 0);
unsigned long long const content0Offset = ZSTD_seekTable_getFrameDecompressedOffset(zst, 0);
assert(content0Offset == 0);
size_t const cSize = ZSTD_seekTable_getFrameCompressedSize(zst, 0);
assert(!ZSTD_isError(cSize));
assert(cSize <= seekCapacity);
size_t const origSize = ZSTD_seekTable_getFrameDecompressedSize(zst, 0);
assert(origSize == inSize);
unsigned const fo1idx = ZSTD_seekTable_offsetToFrameIndex(zst, 1);
assert(fo1idx == 0);
free(inBuffer);
free(seekBuffer);
free(outBuffer);
ZSTD_seekable_freeCStream(zscs);
ZSTD_seekTable_free(zst);
ZSTD_seekable_free(stream);
}
printf("Success!\n");
printf("Test %u - check that seekable decompress does not hang: ", testNb++); printf("Test %u - check that seekable decompress does not hang: ", testNb++);
{ /* Github issue #2335 */ { /* Github issue #2335 */
const size_t compressed_size = 17; const size_t compressed_size = 17;
@@ -103,7 +25,7 @@ int main(int argc, const char** argv)
'\x00', '\x00',
'\x00', '\x00',
'\x00', '\x00',
(uint8_t)('\x03'), ';',
(uint8_t)('\xb1'), (uint8_t)('\xb1'),
(uint8_t)('\xea'), (uint8_t)('\xea'),
(uint8_t)('\x92'), (uint8_t)('\x92'),
@@ -112,61 +34,6 @@ int main(int argc, const char** argv)
const size_t uncompressed_size = 32; const size_t uncompressed_size = 32;
uint8_t uncompressed_data[32]; uint8_t uncompressed_data[32];
ZSTD_seekable* const stream = ZSTD_seekable_create();
assert(stream != NULL);
{ size_t const status = ZSTD_seekable_initBuff(stream, compressed_data, compressed_size);
if (ZSTD_isError(status)) {
ZSTD_seekable_free(stream);
goto _test_error;
} }
/* Should return an error, but not hang */
{ const size_t offset = 2;
size_t const status = ZSTD_seekable_decompress(stream, uncompressed_data, uncompressed_size, offset);
if (!ZSTD_isError(status)) {
ZSTD_seekable_free(stream);
goto _test_error;
} }
ZSTD_seekable_free(stream);
}
printf("Success!\n");
printf("Test %u - check #2 that seekable decompress does not hang: ", testNb++);
{ /* Github issue #FIXME */
const size_t compressed_size = 27;
const uint8_t compressed_data[27] = {
(uint8_t)'\x28',
(uint8_t)'\xb5',
(uint8_t)'\x2f',
(uint8_t)'\xfd',
(uint8_t)'\x00',
(uint8_t)'\x32',
(uint8_t)'\x91',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x5e',
(uint8_t)'\x2a',
(uint8_t)'\x4d',
(uint8_t)'\x18',
(uint8_t)'\x09',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\x00',
(uint8_t)'\xb1',
(uint8_t)'\xea',
(uint8_t)'\x92',
(uint8_t)'\x8f',
};
const size_t uncompressed_size = 400;
uint8_t uncompressed_data[400];
ZSTD_seekable* stream = ZSTD_seekable_create(); ZSTD_seekable* stream = ZSTD_seekable_create();
size_t status = ZSTD_seekable_initBuff(stream, compressed_data, compressed_size); size_t status = ZSTD_seekable_initBuff(stream, compressed_data, compressed_size);
if (ZSTD_isError(status)) { if (ZSTD_isError(status)) {
+7 -38
View File
@@ -29,7 +29,6 @@ extern "C" {
typedef struct ZSTD_seekable_CStream_s ZSTD_seekable_CStream; typedef struct ZSTD_seekable_CStream_s ZSTD_seekable_CStream;
typedef struct ZSTD_seekable_s ZSTD_seekable; typedef struct ZSTD_seekable_s ZSTD_seekable;
typedef struct ZSTD_seekTable_s ZSTD_seekTable;
/*-**************************************************************************** /*-****************************************************************************
* Seekable compression - HowTo * Seekable compression - HowTo
@@ -108,7 +107,6 @@ ZSTDLIB_API size_t ZSTD_seekable_freeFrameLog(ZSTD_frameLog* fl);
ZSTDLIB_API size_t ZSTD_seekable_logFrame(ZSTD_frameLog* fl, unsigned compressedSize, unsigned decompressedSize, unsigned checksum); ZSTDLIB_API size_t ZSTD_seekable_logFrame(ZSTD_frameLog* fl, unsigned compressedSize, unsigned decompressedSize, unsigned checksum);
ZSTDLIB_API size_t ZSTD_seekable_writeSeekTable(ZSTD_frameLog* fl, ZSTD_outBuffer* output); ZSTDLIB_API size_t ZSTD_seekable_writeSeekTable(ZSTD_frameLog* fl, ZSTD_outBuffer* output);
/*-**************************************************************************** /*-****************************************************************************
* Seekable decompression - HowTo * Seekable decompression - HowTo
* A ZSTD_seekable object is required to tracking the seekTable. * A ZSTD_seekable object is required to tracking the seekTable.
@@ -163,42 +161,13 @@ ZSTDLIB_API size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t
ZSTDLIB_API size_t ZSTD_seekable_decompressFrame(ZSTD_seekable* zs, void* dst, size_t dstSize, unsigned frameIndex); ZSTDLIB_API size_t ZSTD_seekable_decompressFrame(ZSTD_seekable* zs, void* dst, size_t dstSize, unsigned frameIndex);
#define ZSTD_SEEKABLE_FRAMEINDEX_TOOLARGE (0ULL-2) #define ZSTD_SEEKABLE_FRAMEINDEX_TOOLARGE (0ULL-2)
/*===== Seekable seek table access functions =====*/ /*===== Seek Table access functions =====*/
ZSTDLIB_API unsigned ZSTD_seekable_getNumFrames(const ZSTD_seekable* zs); ZSTDLIB_API unsigned ZSTD_seekable_getNumFrames(ZSTD_seekable* const zs);
ZSTDLIB_API unsigned long long ZSTD_seekable_getFrameCompressedOffset(const ZSTD_seekable* zs, unsigned frameIndex); ZSTDLIB_API unsigned long long ZSTD_seekable_getFrameCompressedOffset(ZSTD_seekable* const zs, unsigned frameIndex);
ZSTDLIB_API unsigned long long ZSTD_seekable_getFrameDecompressedOffset(const ZSTD_seekable* zs, unsigned frameIndex); ZSTDLIB_API unsigned long long ZSTD_seekable_getFrameDecompressedOffset(ZSTD_seekable* const zs, unsigned frameIndex);
ZSTDLIB_API size_t ZSTD_seekable_getFrameCompressedSize(const ZSTD_seekable* zs, unsigned frameIndex); ZSTDLIB_API size_t ZSTD_seekable_getFrameCompressedSize(ZSTD_seekable* const zs, unsigned frameIndex);
ZSTDLIB_API size_t ZSTD_seekable_getFrameDecompressedSize(const ZSTD_seekable* zs, unsigned frameIndex); ZSTDLIB_API size_t ZSTD_seekable_getFrameDecompressedSize(ZSTD_seekable* const zs, unsigned frameIndex);
ZSTDLIB_API unsigned ZSTD_seekable_offsetToFrameIndex(const ZSTD_seekable* zs, unsigned long long offset); ZSTDLIB_API unsigned ZSTD_seekable_offsetToFrameIndex(ZSTD_seekable* const zs, unsigned long long offset);
/*-****************************************************************************
* Direct exploitation of the seekTable
*
* Memory constrained use cases that manage multiple archives
* benefit from retaining multiple archive seek tables
* without retaining a ZSTD_seekable instance for each.
*
* Below API allow the above-mentioned use cases
* to initialize a ZSTD_seekable, extract its (smaller) ZSTD_seekTable,
* then throw the ZSTD_seekable away to save memory.
*
* Standard ZSTD operations can then be used
* to decompress frames based on seek table offsets.
******************************************************************************/
/*===== Independent seek table management =====*/
ZSTDLIB_API ZSTD_seekTable* ZSTD_seekTable_create_fromSeekable(const ZSTD_seekable* zs);
ZSTDLIB_API size_t ZSTD_seekTable_free(ZSTD_seekTable* st);
/*===== Direct seek table access functions =====*/
ZSTDLIB_API unsigned ZSTD_seekTable_getNumFrames(const ZSTD_seekTable* st);
ZSTDLIB_API unsigned long long ZSTD_seekTable_getFrameCompressedOffset(const ZSTD_seekTable* st, unsigned frameIndex);
ZSTDLIB_API unsigned long long ZSTD_seekTable_getFrameDecompressedOffset(const ZSTD_seekTable* st, unsigned frameIndex);
ZSTDLIB_API size_t ZSTD_seekTable_getFrameCompressedSize(const ZSTD_seekTable* st, unsigned frameIndex);
ZSTDLIB_API size_t ZSTD_seekTable_getFrameDecompressedSize(const ZSTD_seekTable* st, unsigned frameIndex);
ZSTDLIB_API unsigned ZSTD_seekTable_offsetToFrameIndex(const ZSTD_seekTable* st, unsigned long long offset);
/*===== Seekable advanced I/O API =====*/ /*===== Seekable advanced I/O API =====*/
typedef int(ZSTD_seekable_read)(void* opaque, void* buffer, size_t n); typedef int(ZSTD_seekable_read)(void* opaque, void* buffer, size_t n);
+20 -15
View File
@@ -19,7 +19,6 @@
#include "zstd.h" #include "zstd.h"
#include "zstd_errors.h" #include "zstd_errors.h"
#include "mem.h" #include "mem.h"
#include "zstd_seekable.h" #include "zstd_seekable.h"
#define CHECK_Z(f) { size_t const ret = (f); if (ret != 0) return ret; } #define CHECK_Z(f) { size_t const ret = (f); if (ret != 0) return ret; }
@@ -64,18 +63,19 @@ struct ZSTD_seekable_CStream_s {
int writingSeekTable; int writingSeekTable;
}; };
static size_t ZSTD_seekable_frameLog_allocVec(ZSTD_frameLog* fl) size_t ZSTD_seekable_frameLog_allocVec(ZSTD_frameLog* fl)
{ {
/* allocate some initial space */ /* allocate some initial space */
size_t const FRAMELOG_STARTING_CAPACITY = 16; size_t const FRAMELOG_STARTING_CAPACITY = 16;
fl->entries = (framelogEntry_t*)malloc( fl->entries = (framelogEntry_t*)malloc(
sizeof(framelogEntry_t) * FRAMELOG_STARTING_CAPACITY); sizeof(framelogEntry_t) * FRAMELOG_STARTING_CAPACITY);
if (fl->entries == NULL) return ERROR(memory_allocation); if (fl->entries == NULL) return ERROR(memory_allocation);
fl->capacity = (U32)FRAMELOG_STARTING_CAPACITY; fl->capacity = FRAMELOG_STARTING_CAPACITY;
return 0; return 0;
} }
static size_t ZSTD_seekable_frameLog_freeVec(ZSTD_frameLog* fl) size_t ZSTD_seekable_frameLog_freeVec(ZSTD_frameLog* fl)
{ {
if (fl != NULL) free(fl->entries); if (fl != NULL) free(fl->entries);
return 0; return 0;
@@ -83,7 +83,7 @@ static size_t ZSTD_seekable_frameLog_freeVec(ZSTD_frameLog* fl)
ZSTD_frameLog* ZSTD_seekable_createFrameLog(int checksumFlag) ZSTD_frameLog* ZSTD_seekable_createFrameLog(int checksumFlag)
{ {
ZSTD_frameLog* const fl = malloc(sizeof(ZSTD_frameLog)); ZSTD_frameLog* fl = malloc(sizeof(ZSTD_frameLog));
if (fl == NULL) return NULL; if (fl == NULL) return NULL;
if (ZSTD_isError(ZSTD_seekable_frameLog_allocVec(fl))) { if (ZSTD_isError(ZSTD_seekable_frameLog_allocVec(fl))) {
@@ -106,9 +106,10 @@ size_t ZSTD_seekable_freeFrameLog(ZSTD_frameLog* fl)
return 0; return 0;
} }
ZSTD_seekable_CStream* ZSTD_seekable_createCStream(void) ZSTD_seekable_CStream* ZSTD_seekable_createCStream()
{ {
ZSTD_seekable_CStream* const zcs = malloc(sizeof(ZSTD_seekable_CStream)); ZSTD_seekable_CStream* zcs = malloc(sizeof(ZSTD_seekable_CStream));
if (zcs == NULL) return NULL; if (zcs == NULL) return NULL;
memset(zcs, 0, sizeof(*zcs)); memset(zcs, 0, sizeof(*zcs));
@@ -133,6 +134,7 @@ size_t ZSTD_seekable_freeCStream(ZSTD_seekable_CStream* zcs)
ZSTD_freeCStream(zcs->cstream); ZSTD_freeCStream(zcs->cstream);
ZSTD_seekable_frameLog_freeVec(&zcs->framelog); ZSTD_seekable_frameLog_freeVec(&zcs->framelog);
free(zcs); free(zcs);
return 0; return 0;
} }
@@ -150,8 +152,9 @@ size_t ZSTD_seekable_initCStream(ZSTD_seekable_CStream* zcs,
return ERROR(frameParameter_unsupported); return ERROR(frameParameter_unsupported);
} }
zcs->maxFrameSize = maxFrameSize ? zcs->maxFrameSize = maxFrameSize
maxFrameSize : ZSTD_SEEKABLE_MAX_FRAME_DECOMPRESSED_SIZE; ? maxFrameSize
: ZSTD_SEEKABLE_MAX_FRAME_DECOMPRESSED_SIZE;
zcs->framelog.checksumFlag = checksumFlag; zcs->framelog.checksumFlag = checksumFlag;
if (zcs->framelog.checksumFlag) { if (zcs->framelog.checksumFlag) {
@@ -201,7 +204,7 @@ size_t ZSTD_seekable_endFrame(ZSTD_seekable_CStream* zcs, ZSTD_outBuffer* output
/* end the frame */ /* end the frame */
size_t ret = ZSTD_endStream(zcs->cstream, output); size_t ret = ZSTD_endStream(zcs->cstream, output);
zcs->frameCSize += (U32)(output->pos - prevOutPos); zcs->frameCSize += output->pos - prevOutPos;
/* need to flush before doing the rest */ /* need to flush before doing the rest */
if (ret) return ret; if (ret) return ret;
@@ -221,7 +224,8 @@ size_t ZSTD_seekable_endFrame(ZSTD_seekable_CStream* zcs, ZSTD_outBuffer* output
zcs->frameDSize = 0; zcs->frameDSize = 0;
ZSTD_CCtx_reset(zcs->cstream, ZSTD_reset_session_only); ZSTD_CCtx_reset(zcs->cstream, ZSTD_reset_session_only);
if (zcs->framelog.checksumFlag) XXH64_reset(&zcs->xxhState, 0); if (zcs->framelog.checksumFlag)
XXH64_reset(&zcs->xxhState, 0);
return 0; return 0;
} }
@@ -244,8 +248,8 @@ size_t ZSTD_seekable_compressStream(ZSTD_seekable_CStream* zcs, ZSTD_outBuffer*
XXH64_update(&zcs->xxhState, inBase, inTmp.pos); XXH64_update(&zcs->xxhState, inBase, inTmp.pos);
} }
zcs->frameCSize += (U32)(output->pos - prevOutPos); zcs->frameCSize += output->pos - prevOutPos;
zcs->frameDSize += (U32)inTmp.pos; zcs->frameDSize += inTmp.pos;
input->pos += inTmp.pos; input->pos += inTmp.pos;
@@ -286,7 +290,7 @@ static inline size_t ZSTD_stwrite32(ZSTD_frameLog* fl,
memcpy((BYTE*)output->dst + output->pos, memcpy((BYTE*)output->dst + output->pos,
tmp + (fl->seekTablePos - offset), lenWrite); tmp + (fl->seekTablePos - offset), lenWrite);
output->pos += lenWrite; output->pos += lenWrite;
fl->seekTablePos += (U32)lenWrite; fl->seekTablePos += lenWrite;
if (lenWrite < 4) return ZSTD_seekable_seekTableSize(fl) - fl->seekTablePos; if (lenWrite < 4) return ZSTD_seekable_seekTableSize(fl) - fl->seekTablePos;
} }
@@ -335,7 +339,8 @@ size_t ZSTD_seekable_writeSeekTable(ZSTD_frameLog* fl, ZSTD_outBuffer* output)
if (output->size - output->pos < 1) return seekTableLen - fl->seekTablePos; if (output->size - output->pos < 1) return seekTableLen - fl->seekTablePos;
if (fl->seekTablePos < seekTableLen - 4) { if (fl->seekTablePos < seekTableLen - 4) {
BYTE const sfd = (BYTE)((fl->checksumFlag) << 7); BYTE sfd = 0;
sfd |= (fl->checksumFlag) << 7;
((BYTE*)output->dst)[output->pos] = sfd; ((BYTE*)output->dst)[output->pos] = sfd;
output->pos++; output->pos++;
+49 -108
View File
@@ -107,8 +107,7 @@ typedef struct {
static int ZSTD_seekable_read_buff(void* opaque, void* buffer, size_t n) static int ZSTD_seekable_read_buff(void* opaque, void* buffer, size_t n)
{ {
buffWrapper_t* const buff = (buffWrapper_t*)opaque; buffWrapper_t* buff = (buffWrapper_t*) opaque;
assert(buff != NULL);
if (buff->pos + n > buff->size) return -1; if (buff->pos + n > buff->size) return -1;
memcpy(buffer, (const BYTE*)buff->ptr + buff->pos, n); memcpy(buffer, (const BYTE*)buff->ptr + buff->pos, n);
buff->pos += n; buff->pos += n;
@@ -119,17 +118,15 @@ static int ZSTD_seekable_seek_buff(void* opaque, long long offset, int origin)
{ {
buffWrapper_t* const buff = (buffWrapper_t*) opaque; buffWrapper_t* const buff = (buffWrapper_t*) opaque;
unsigned long long newOffset; unsigned long long newOffset;
assert(buff != NULL);
switch (origin) { switch (origin) {
case SEEK_SET: case SEEK_SET:
assert(offset >= 0); newOffset = offset;
newOffset = (unsigned long long)offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
newOffset = (unsigned long long)((long long)buff->pos + offset); newOffset = (unsigned long long)buff->pos + offset;
break; break;
case SEEK_END: case SEEK_END:
newOffset = (unsigned long long)((long long)buff->size + offset); newOffset = (unsigned long long)buff->size + offset;
break; break;
default: default:
assert(0); /* not possible */ assert(0); /* not possible */
@@ -147,18 +144,18 @@ typedef struct {
U32 checksum; U32 checksum;
} seekEntry_t; } seekEntry_t;
struct ZSTD_seekTable_s { typedef struct {
seekEntry_t* entries; seekEntry_t* entries;
size_t tableLen; size_t tableLen;
int checksumFlag; int checksumFlag;
}; } seekTable_t;
#define SEEKABLE_BUFF_SIZE ZSTD_BLOCKSIZE_MAX #define SEEKABLE_BUFF_SIZE ZSTD_BLOCKSIZE_MAX
struct ZSTD_seekable_s { struct ZSTD_seekable_s {
ZSTD_DStream* dstream; ZSTD_DStream* dstream;
ZSTD_seekTable seekTable; seekTable_t seekTable;
ZSTD_seekable_customFile src; ZSTD_seekable_customFile src;
U64 decompressedOffset; U64 decompressedOffset;
@@ -176,7 +173,8 @@ struct ZSTD_seekable_s {
ZSTD_seekable* ZSTD_seekable_create(void) ZSTD_seekable* ZSTD_seekable_create(void)
{ {
ZSTD_seekable* const zs = malloc(sizeof(ZSTD_seekable)); ZSTD_seekable* zs = malloc(sizeof(ZSTD_seekable));
if (zs == NULL) return NULL; if (zs == NULL) return NULL;
/* also initializes stage to zsds_init */ /* also initializes stage to zsds_init */
@@ -197,35 +195,7 @@ size_t ZSTD_seekable_free(ZSTD_seekable* zs)
ZSTD_freeDStream(zs->dstream); ZSTD_freeDStream(zs->dstream);
free(zs->seekTable.entries); free(zs->seekTable.entries);
free(zs); free(zs);
return 0;
}
ZSTD_seekTable* ZSTD_seekTable_create_fromSeekable(const ZSTD_seekable* zs)
{
ZSTD_seekTable* const st = malloc(sizeof(ZSTD_seekTable));
if (st==NULL) return NULL;
st->checksumFlag = zs->seekTable.checksumFlag;
st->tableLen = zs->seekTable.tableLen;
/* Allocate an extra entry at the end to match logic of initial allocation */
size_t const entriesSize = sizeof(seekEntry_t) * (zs->seekTable.tableLen + 1);
seekEntry_t* const entries = (seekEntry_t*)malloc(entriesSize);
if (entries==NULL) {
free(st);
return NULL;
}
memcpy(entries, zs->seekTable.entries, entriesSize);
st->entries = entries;
return st;
}
size_t ZSTD_seekTable_free(ZSTD_seekTable* st)
{
if (st == NULL) return 0; /* support free on null */
free(st->entries);
free(st);
return 0; return 0;
} }
@@ -233,24 +203,19 @@ size_t ZSTD_seekTable_free(ZSTD_seekTable* st)
* Performs a binary search to find the last frame with a decompressed offset * Performs a binary search to find the last frame with a decompressed offset
* <= pos * <= pos
* @return : the frame's index */ * @return : the frame's index */
unsigned ZSTD_seekable_offsetToFrameIndex(const ZSTD_seekable* zs, unsigned long long pos) unsigned ZSTD_seekable_offsetToFrameIndex(ZSTD_seekable* const zs, unsigned long long pos)
{
return ZSTD_seekTable_offsetToFrameIndex(&zs->seekTable, pos);
}
unsigned ZSTD_seekTable_offsetToFrameIndex(const ZSTD_seekTable* st, unsigned long long pos)
{ {
U32 lo = 0; U32 lo = 0;
U32 hi = (U32)st->tableLen; U32 hi = (U32)zs->seekTable.tableLen;
assert(st->tableLen <= UINT_MAX); assert(zs->seekTable.tableLen <= UINT_MAX);
if (pos >= st->entries[st->tableLen].dOffset) { if (pos >= zs->seekTable.entries[zs->seekTable.tableLen].dOffset) {
return (unsigned)st->tableLen; return (U32)zs->seekTable.tableLen;
} }
while (lo + 1 < hi) { while (lo + 1 < hi) {
U32 const mid = lo + ((hi - lo) >> 1); U32 const mid = lo + ((hi - lo) >> 1);
if (st->entries[mid].dOffset <= pos) { if (zs->seekTable.entries[mid].dOffset <= pos) {
lo = mid; lo = mid;
} else { } else {
hi = mid; hi = mid;
@@ -259,61 +224,36 @@ unsigned ZSTD_seekTable_offsetToFrameIndex(const ZSTD_seekTable* st, unsigned lo
return lo; return lo;
} }
unsigned ZSTD_seekable_getNumFrames(const ZSTD_seekable* zs) unsigned ZSTD_seekable_getNumFrames(ZSTD_seekable* const zs)
{ {
return ZSTD_seekTable_getNumFrames(&zs->seekTable); assert(zs->seekTable.tableLen <= UINT_MAX);
return (unsigned)zs->seekTable.tableLen;
} }
unsigned ZSTD_seekTable_getNumFrames(const ZSTD_seekTable* st) unsigned long long ZSTD_seekable_getFrameCompressedOffset(ZSTD_seekable* const zs, unsigned frameIndex)
{ {
assert(st->tableLen <= UINT_MAX); if (frameIndex >= zs->seekTable.tableLen) return ZSTD_SEEKABLE_FRAMEINDEX_TOOLARGE;
return (unsigned)st->tableLen; return zs->seekTable.entries[frameIndex].cOffset;
} }
unsigned long long ZSTD_seekable_getFrameCompressedOffset(const ZSTD_seekable* zs, unsigned frameIndex) unsigned long long ZSTD_seekable_getFrameDecompressedOffset(ZSTD_seekable* const zs, unsigned frameIndex)
{ {
return ZSTD_seekTable_getFrameCompressedOffset(&zs->seekTable, frameIndex); if (frameIndex >= zs->seekTable.tableLen) return ZSTD_SEEKABLE_FRAMEINDEX_TOOLARGE;
return zs->seekTable.entries[frameIndex].dOffset;
} }
unsigned long long ZSTD_seekTable_getFrameCompressedOffset(const ZSTD_seekTable* st, unsigned frameIndex) size_t ZSTD_seekable_getFrameCompressedSize(ZSTD_seekable* const zs, unsigned frameIndex)
{ {
if (frameIndex >= st->tableLen) return ZSTD_SEEKABLE_FRAMEINDEX_TOOLARGE; if (frameIndex >= zs->seekTable.tableLen) return ERROR(frameIndex_tooLarge);
return st->entries[frameIndex].cOffset; return zs->seekTable.entries[frameIndex + 1].cOffset -
zs->seekTable.entries[frameIndex].cOffset;
} }
unsigned long long ZSTD_seekable_getFrameDecompressedOffset(const ZSTD_seekable* zs, unsigned frameIndex) size_t ZSTD_seekable_getFrameDecompressedSize(ZSTD_seekable* const zs, unsigned frameIndex)
{ {
return ZSTD_seekTable_getFrameDecompressedOffset(&zs->seekTable, frameIndex); if (frameIndex > zs->seekTable.tableLen) return ERROR(frameIndex_tooLarge);
} return zs->seekTable.entries[frameIndex + 1].dOffset -
zs->seekTable.entries[frameIndex].dOffset;
unsigned long long ZSTD_seekTable_getFrameDecompressedOffset(const ZSTD_seekTable* st, unsigned frameIndex)
{
if (frameIndex >= st->tableLen) return ZSTD_SEEKABLE_FRAMEINDEX_TOOLARGE;
return st->entries[frameIndex].dOffset;
}
size_t ZSTD_seekable_getFrameCompressedSize(const ZSTD_seekable* zs, unsigned frameIndex)
{
return ZSTD_seekTable_getFrameCompressedSize(&zs->seekTable, frameIndex);
}
size_t ZSTD_seekTable_getFrameCompressedSize(const ZSTD_seekTable* st, unsigned frameIndex)
{
if (frameIndex >= st->tableLen) return ERROR(frameIndex_tooLarge);
return st->entries[frameIndex + 1].cOffset -
st->entries[frameIndex].cOffset;
}
size_t ZSTD_seekable_getFrameDecompressedSize(const ZSTD_seekable* zs, unsigned frameIndex)
{
return ZSTD_seekTable_getFrameDecompressedSize(&zs->seekTable, frameIndex);
}
size_t ZSTD_seekTable_getFrameDecompressedSize(const ZSTD_seekTable* st, unsigned frameIndex)
{
if (frameIndex > st->tableLen) return ERROR(frameIndex_tooLarge);
return st->entries[frameIndex + 1].dOffset -
st->entries[frameIndex].dOffset;
} }
static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs) static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
@@ -332,9 +272,10 @@ static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
checksumFlag = sfd >> 7; checksumFlag = sfd >> 7;
/* check reserved bits */ /* check reserved bits */
if ((sfd >> 2) & 0x1f) { if ((checksumFlag >> 2) & 0x1f) {
return ERROR(corruption_detected); return ERROR(corruption_detected);
} } }
}
{ U32 const numFrames = MEM_readLE32(zs->inBuff); { U32 const numFrames = MEM_readLE32(zs->inBuff);
U32 const sizePerEntry = 8 + (checksumFlag?4:0); U32 const sizePerEntry = 8 + (checksumFlag?4:0);
@@ -342,9 +283,12 @@ static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
U32 const frameSize = tableSize + ZSTD_seekTableFooterSize + ZSTD_SKIPPABLEHEADERSIZE; U32 const frameSize = tableSize + ZSTD_seekTableFooterSize + ZSTD_SKIPPABLEHEADERSIZE;
U32 remaining = frameSize - ZSTD_seekTableFooterSize; /* don't need to re-read footer */ U32 remaining = frameSize - ZSTD_seekTableFooterSize; /* don't need to re-read footer */
{ U32 const toRead = MIN(remaining, SEEKABLE_BUFF_SIZE); {
U32 const toRead = MIN(remaining, SEEKABLE_BUFF_SIZE);
CHECK_IO(src.seek(src.opaque, -(S64)frameSize, SEEK_END)); CHECK_IO(src.seek(src.opaque, -(S64)frameSize, SEEK_END));
CHECK_IO(src.read(src.opaque, zs->inBuff, toRead)); CHECK_IO(src.read(src.opaque, zs->inBuff, toRead));
remaining -= toRead; remaining -= toRead;
} }
@@ -357,15 +301,19 @@ static size_t ZSTD_seekable_loadSeekTable(ZSTD_seekable* zs)
{ /* Allocate an extra entry at the end so that we can do size { /* Allocate an extra entry at the end so that we can do size
* computations on the last element without special case */ * computations on the last element without special case */
seekEntry_t* const entries = (seekEntry_t*)malloc(sizeof(seekEntry_t) * (numFrames + 1)); seekEntry_t* entries = (seekEntry_t*)malloc(sizeof(seekEntry_t) * (numFrames + 1));
U32 idx = 0; U32 idx = 0;
U32 pos = 8; U32 pos = 8;
U64 cOffset = 0; U64 cOffset = 0;
U64 dOffset = 0; U64 dOffset = 0;
if (entries == NULL) return ERROR(memory_allocation); if (!entries) {
free(entries);
return ERROR(memory_allocation);
}
/* compute cumulative positions */ /* compute cumulative positions */
for (; idx < numFrames; idx++) { for (; idx < numFrames; idx++) {
@@ -435,30 +383,24 @@ size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t len, unsign
{ {
U32 targetFrame = ZSTD_seekable_offsetToFrameIndex(zs, offset); U32 targetFrame = ZSTD_seekable_offsetToFrameIndex(zs, offset);
U32 noOutputProgressCount = 0; U32 noOutputProgressCount = 0;
size_t srcBytesRead = 0;
do { do {
/* check if we can continue from a previous decompress job */ /* check if we can continue from a previous decompress job */
if (targetFrame != zs->curFrame || offset != zs->decompressedOffset) { if (targetFrame != zs->curFrame || offset != zs->decompressedOffset) {
zs->decompressedOffset = zs->seekTable.entries[targetFrame].dOffset; zs->decompressedOffset = zs->seekTable.entries[targetFrame].dOffset;
zs->curFrame = targetFrame; zs->curFrame = targetFrame;
assert(zs->seekTable.entries[targetFrame].cOffset < LLONG_MAX);
CHECK_IO(zs->src.seek(zs->src.opaque, CHECK_IO(zs->src.seek(zs->src.opaque,
(long long)zs->seekTable.entries[targetFrame].cOffset, zs->seekTable.entries[targetFrame].cOffset,
SEEK_SET)); SEEK_SET));
zs->in = (ZSTD_inBuffer){zs->inBuff, 0, 0}; zs->in = (ZSTD_inBuffer){zs->inBuff, 0, 0};
XXH64_reset(&zs->xxhState, 0); XXH64_reset(&zs->xxhState, 0);
ZSTD_DCtx_reset(zs->dstream, ZSTD_reset_session_only); ZSTD_DCtx_reset(zs->dstream, ZSTD_reset_session_only);
if (srcBytesRead > zs->buffWrapper.size) {
return ERROR(seekableIO);
}
} }
while (zs->decompressedOffset < offset + len) { while (zs->decompressedOffset < offset + len) {
size_t toRead; size_t toRead;
ZSTD_outBuffer outTmp; ZSTD_outBuffer outTmp;
size_t prevOutPos; size_t prevOutPos;
size_t prevInPos;
size_t forwardProgress; size_t forwardProgress;
if (zs->decompressedOffset < offset) { if (zs->decompressedOffset < offset) {
/* dummy decompressions until we get to the target offset */ /* dummy decompressions until we get to the target offset */
@@ -468,7 +410,6 @@ size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t len, unsign
} }
prevOutPos = outTmp.pos; prevOutPos = outTmp.pos;
prevInPos = zs->in.pos;
toRead = ZSTD_decompressStream(zs->dstream, &outTmp, &zs->in); toRead = ZSTD_decompressStream(zs->dstream, &outTmp, &zs->in);
if (ZSTD_isError(toRead)) { if (ZSTD_isError(toRead)) {
return toRead; return toRead;
@@ -487,7 +428,6 @@ size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t len, unsign
noOutputProgressCount = 0; noOutputProgressCount = 0;
} }
zs->decompressedOffset += forwardProgress; zs->decompressedOffset += forwardProgress;
srcBytesRead += zs->in.pos - prevInPos;
if (toRead == 0) { if (toRead == 0) {
/* frame complete */ /* frame complete */
@@ -513,7 +453,7 @@ size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t len, unsign
zs->in.size = toRead; zs->in.size = toRead;
zs->in.pos = 0; zs->in.pos = 0;
} }
} /* while (zs->decompressedOffset < offset + len) */ }
} while (zs->decompressedOffset != offset + len); } while (zs->decompressedOffset != offset + len);
return len; return len;
@@ -525,7 +465,8 @@ size_t ZSTD_seekable_decompressFrame(ZSTD_seekable* zs, void* dst, size_t dstSiz
return ERROR(frameIndex_tooLarge); return ERROR(frameIndex_tooLarge);
} }
{ size_t const decompressedSize = {
size_t const decompressedSize =
zs->seekTable.entries[frameIndex + 1].dOffset - zs->seekTable.entries[frameIndex + 1].dOffset -
zs->seekTable.entries[frameIndex].dOffset; zs->seekTable.entries[frameIndex].dOffset;
if (dstSize < decompressedSize) { if (dstSize < decompressedSize) {
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2017-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2017-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021 Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Martin Liska, SUSE, Facebook, Inc. * Copyright (c) 2021, Martin Liska, SUSE, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2017-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+7 -7
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* bitstream * bitstream
* Part of FSE library * Part of FSE library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -293,22 +293,22 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
switch(srcSize) switch(srcSize)
{ {
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
ZSTD_FALLTHROUGH; /* fall-through */
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
ZSTD_FALLTHROUGH; /* fall-through */
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
ZSTD_FALLTHROUGH; /* fall-through */
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24; case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
ZSTD_FALLTHROUGH; /* fall-through */
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16; case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
ZSTD_FALLTHROUGH; /* fall-through */
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8; case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
ZSTD_FALLTHROUGH; /* fall-through */
default: break; default: break;
} }
+1 -34
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -207,39 +207,6 @@
# define __has_feature(x) 0 # define __has_feature(x) 0
#endif #endif
/* C-language Attributes are added in C23. */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute)
# define ZSTD_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
#else
# define ZSTD_HAS_C_ATTRIBUTE(x) 0
#endif
/* Only use C++ attributes in C++. Some compilers report support for C++
* attributes when compiling with C.
*/
#if defined(__cplusplus) && defined(__has_cpp_attribute)
# define ZSTD_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
#else
# define ZSTD_HAS_CPP_ATTRIBUTE(x) 0
#endif
/* Define ZSTD_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute.
* - C23: https://en.cppreference.com/w/c/language/attributes/fallthrough
* - CPP17: https://en.cppreference.com/w/cpp/language/attributes/fallthrough
* - Else: __attribute__((__fallthrough__))
*/
#ifndef ZSTD_FALLTHROUGH
# if ZSTD_HAS_C_ATTRIBUTE(fallthrough)
# define ZSTD_FALLTHROUGH [[fallthrough]]
# elif ZSTD_HAS_CPP_ATTRIBUTE(fallthrough)
# define ZSTD_FALLTHROUGH [[fallthrough]]
# elif __has_attribute(__fallthrough__)
# define ZSTD_FALLTHROUGH __attribute__((__fallthrough__))
# else
# define ZSTD_FALLTHROUGH
# endif
#endif
/* detects whether we are being compiled under msan */ /* detects whether we are being compiled under msan */
#ifndef ZSTD_MEMORY_SANITIZER #ifndef ZSTD_MEMORY_SANITIZER
# if __has_feature(memory_sanitizer) # if __has_feature(memory_sanitizer)
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2018-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* debug * debug
* Part of FSE library * Part of FSE library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
+1 -1
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* debug * debug
* Part of FSE library * Part of FSE library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
+1 -1
View File
@@ -1,6 +1,6 @@
/* ****************************************************************** /* ******************************************************************
* Common functions of New Generation Entropy library * Common functions of New Generation Entropy library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+2 -2
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* FSE : Finite State Entropy codec * FSE : Finite State Entropy codec
* Public Prototypes declaration * Public Prototypes declaration
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -352,7 +352,7 @@ size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits);
size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue); size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
/**< build a fake FSE_DTable, designed to always generate the same symbolValue */ /**< build a fake FSE_DTable, designed to always generate the same symbolValue */
#define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) + (FSE_MAX_SYMBOL_VALUE + 1) / 2 + 1) #define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue))
#define FSE_DECOMPRESS_WKSP_SIZE(maxTableLog, maxSymbolValue) (FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(unsigned)) #define FSE_DECOMPRESS_WKSP_SIZE(maxTableLog, maxSymbolValue) (FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(unsigned))
size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize); size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize);
/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DECOMPRESS_WKSP_SIZE_U32(maxLog, maxSymbolValue)` */ /**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DECOMPRESS_WKSP_SIZE_U32(maxLog, maxSymbolValue)` */
+15 -25
View File
@@ -1,6 +1,6 @@
/* ****************************************************************** /* ******************************************************************
* FSE : Finite State Entropy decoder * FSE : Finite State Entropy decoder
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -310,12 +310,6 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size
return FSE_decompress_wksp_bmi2(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, /* bmi2 */ 0); return FSE_decompress_wksp_bmi2(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, /* bmi2 */ 0);
} }
typedef struct {
short ncount[FSE_MAX_SYMBOL_VALUE + 1];
FSE_DTable dtable[1]; /* Dynamically sized */
} FSE_DecompressWksp;
FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body( FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
void* dst, size_t dstCapacity, void* dst, size_t dstCapacity,
const void* cSrc, size_t cSrcSize, const void* cSrc, size_t cSrcSize,
@@ -324,37 +318,33 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
{ {
const BYTE* const istart = (const BYTE*)cSrc; const BYTE* const istart = (const BYTE*)cSrc;
const BYTE* ip = istart; const BYTE* ip = istart;
short counting[FSE_MAX_SYMBOL_VALUE+1];
unsigned tableLog; unsigned tableLog;
unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE; unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
FSE_DecompressWksp* const wksp = (FSE_DecompressWksp*)workSpace; FSE_DTable* const dtable = (FSE_DTable*)workSpace;
DEBUG_STATIC_ASSERT((FSE_MAX_SYMBOL_VALUE + 1) % 2 == 0);
if (wkspSize < sizeof(*wksp)) return ERROR(GENERIC);
/* normal FSE decoding mode */ /* normal FSE decoding mode */
{ size_t const NCountLength = FSE_readNCount_bmi2(counting, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
size_t const NCountLength = FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2); if (FSE_isError(NCountLength)) return NCountLength;
if (FSE_isError(NCountLength)) return NCountLength; if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
if (tableLog > maxLog) return ERROR(tableLog_tooLarge); assert(NCountLength <= cSrcSize);
assert(NCountLength <= cSrcSize); ip += NCountLength;
ip += NCountLength; cSrcSize -= NCountLength;
cSrcSize -= NCountLength;
}
if (FSE_DECOMPRESS_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(tableLog_tooLarge); if (FSE_DECOMPRESS_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(tableLog_tooLarge);
workSpace = wksp->dtable + FSE_DTABLE_SIZE_U32(tableLog); workSpace = dtable + FSE_DTABLE_SIZE_U32(tableLog);
wkspSize -= sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog); wkspSize -= FSE_DTABLE_SIZE(tableLog);
CHECK_F( FSE_buildDTable_internal(wksp->dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize) ); CHECK_F( FSE_buildDTable_internal(dtable, counting, maxSymbolValue, tableLog, workSpace, wkspSize) );
{ {
const void* ptr = wksp->dtable; const void* ptr = dtable;
const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr; const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
const U32 fastMode = DTableH->fastMode; const U32 fastMode = DTableH->fastMode;
/* select fast mode (static) */ /* select fast mode (static) */
if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 1); if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 1);
return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 0); return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 0);
} }
} }
+2 -3
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* huff0 huffman codec, * huff0 huffman codec,
* part of Finite State Entropy library * part of Finite State Entropy library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -192,7 +192,6 @@ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */ size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog); size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog, void* workspace, size_t workspaceSize);
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue); size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue); int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
@@ -279,7 +278,7 @@ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
* a required workspace size greater than that specified in the following * a required workspace size greater than that specified in the following
* macro. * macro.
*/ */
#define HUF_DECOMPRESS_WORKSPACE_SIZE ((2 << 10) + (1 << 9)) #define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10)
#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32)) #define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
#ifndef HUF_FORCE_DECOMPRESS_X2 #ifndef HUF_FORCE_DECOMPRESS_X2
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -308,7 +308,7 @@ MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
MEM_STATIC U32 MEM_readLE24(const void* memPtr) MEM_STATIC U32 MEM_readLE24(const void* memPtr)
{ {
return (U32)MEM_readLE16(memPtr) + ((U32)(((const BYTE*)memPtr)[2]) << 16); return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16);
} }
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val) MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,6 +1,6 @@
/* /*
* xxHash - Fast Hash algorithm * xxHash - Fast Hash algorithm
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2012-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - xxHash homepage: http://www.xxhash.com * - xxHash homepage: http://www.xxhash.com
+1 -1
View File
@@ -1,7 +1,7 @@
/* /*
* xxHash - Extremely Fast Hash algorithm * xxHash - Extremely Fast Hash algorithm
* Header File * Header File
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2012-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - xxHash source repository : https://github.com/Cyan4973/xxHash * - xxHash source repository : https://github.com/Cyan4973/xxHash
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -36,11 +36,6 @@
# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
#endif #endif
#include "xxhash.h" /* XXH_reset, update, digest */ #include "xxhash.h" /* XXH_reset, update, digest */
#ifndef ZSTD_NO_TRACE
# include "zstd_trace.h"
#else
# define ZSTD_TRACE 0
#endif
#if defined (__cplusplus) #if defined (__cplusplus)
extern "C" { extern "C" {
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,6 +1,6 @@
/* ****************************************************************** /* ******************************************************************
* FSE : Finite State Entropy encoder * FSE : Finite State Entropy encoder
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
+1 -1
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* hist : Histogram functions * hist : Histogram functions
* part of Finite State Entropy project * part of Finite State Entropy project
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
+1 -1
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* hist : Histogram functions * hist : Histogram functions
* part of Finite State Entropy project * part of Finite State Entropy project
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
+38 -64
View File
@@ -1,6 +1,6 @@
/* ****************************************************************** /* ******************************************************************
* Huffman encoder, part of New Generation Entropy library * Huffman encoder, part of New Generation Entropy library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -59,15 +59,7 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
* Note : all elements within weightTable are supposed to be <= HUF_TABLELOG_MAX. * Note : all elements within weightTable are supposed to be <= HUF_TABLELOG_MAX.
*/ */
#define MAX_FSE_TABLELOG_FOR_HUFF_HEADER 6 #define MAX_FSE_TABLELOG_FOR_HUFF_HEADER 6
static size_t HUF_compressWeights (void* dst, size_t dstSize, const void* weightTable, size_t wtSize)
typedef struct {
FSE_CTable CTable[FSE_CTABLE_SIZE_U32(MAX_FSE_TABLELOG_FOR_HUFF_HEADER, HUF_TABLELOG_MAX)];
U32 scratchBuffer[FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(HUF_TABLELOG_MAX, MAX_FSE_TABLELOG_FOR_HUFF_HEADER)];
unsigned count[HUF_TABLELOG_MAX+1];
S16 norm[HUF_TABLELOG_MAX+1];
} HUF_CompressWeightsWksp;
static size_t HUF_compressWeights(void* dst, size_t dstSize, const void* weightTable, size_t wtSize, void* workspace, size_t workspaceSize)
{ {
BYTE* const ostart = (BYTE*) dst; BYTE* const ostart = (BYTE*) dst;
BYTE* op = ostart; BYTE* op = ostart;
@@ -75,30 +67,33 @@ static size_t HUF_compressWeights(void* dst, size_t dstSize, const void* weightT
unsigned maxSymbolValue = HUF_TABLELOG_MAX; unsigned maxSymbolValue = HUF_TABLELOG_MAX;
U32 tableLog = MAX_FSE_TABLELOG_FOR_HUFF_HEADER; U32 tableLog = MAX_FSE_TABLELOG_FOR_HUFF_HEADER;
HUF_CompressWeightsWksp* wksp = (HUF_CompressWeightsWksp*)workspace;
if (workspaceSize < sizeof(HUF_CompressWeightsWksp)) return ERROR(GENERIC); FSE_CTable CTable[FSE_CTABLE_SIZE_U32(MAX_FSE_TABLELOG_FOR_HUFF_HEADER, HUF_TABLELOG_MAX)];
U32 scratchBuffer[FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(HUF_TABLELOG_MAX, MAX_FSE_TABLELOG_FOR_HUFF_HEADER)];
unsigned count[HUF_TABLELOG_MAX+1];
S16 norm[HUF_TABLELOG_MAX+1];
/* init conditions */ /* init conditions */
if (wtSize <= 1) return 0; /* Not compressible */ if (wtSize <= 1) return 0; /* Not compressible */
/* Scan input and build symbol stats */ /* Scan input and build symbol stats */
{ unsigned const maxCount = HIST_count_simple(wksp->count, &maxSymbolValue, weightTable, wtSize); /* never fails */ { unsigned const maxCount = HIST_count_simple(count, &maxSymbolValue, weightTable, wtSize); /* never fails */
if (maxCount == wtSize) return 1; /* only a single symbol in src : rle */ if (maxCount == wtSize) return 1; /* only a single symbol in src : rle */
if (maxCount == 1) return 0; /* each symbol present maximum once => not compressible */ if (maxCount == 1) return 0; /* each symbol present maximum once => not compressible */
} }
tableLog = FSE_optimalTableLog(tableLog, wtSize, maxSymbolValue); tableLog = FSE_optimalTableLog(tableLog, wtSize, maxSymbolValue);
CHECK_F( FSE_normalizeCount(wksp->norm, tableLog, wksp->count, wtSize, maxSymbolValue, /* useLowProbCount */ 0) ); CHECK_F( FSE_normalizeCount(norm, tableLog, count, wtSize, maxSymbolValue, /* useLowProbCount */ 0) );
/* Write table description header */ /* Write table description header */
{ CHECK_V_F(hSize, FSE_writeNCount(op, (size_t)(oend-op), wksp->norm, maxSymbolValue, tableLog) ); { CHECK_V_F(hSize, FSE_writeNCount(op, (size_t)(oend-op), norm, maxSymbolValue, tableLog) );
op += hSize; op += hSize;
} }
/* Compress */ /* Compress */
CHECK_F( FSE_buildCTable_wksp(wksp->CTable, wksp->norm, maxSymbolValue, tableLog, wksp->scratchBuffer, sizeof(wksp->scratchBuffer)) ); CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, sizeof(scratchBuffer)) );
{ CHECK_V_F(cSize, FSE_compress_usingCTable(op, (size_t)(oend - op), weightTable, wtSize, wksp->CTable) ); { CHECK_V_F(cSize, FSE_compress_usingCTable(op, (size_t)(oend - op), weightTable, wtSize, CTable) );
if (cSize == 0) return 0; /* not enough space for compressed data */ if (cSize == 0) return 0; /* not enough space for compressed data */
op += cSize; op += cSize;
} }
@@ -107,33 +102,29 @@ static size_t HUF_compressWeights(void* dst, size_t dstSize, const void* weightT
} }
typedef struct { /*! HUF_writeCTable() :
HUF_CompressWeightsWksp wksp; `CTable` : Huffman tree to save, using huf representation.
@return : size of saved CTable */
size_t HUF_writeCTable (void* dst, size_t maxDstSize,
const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog)
{
BYTE bitsToWeight[HUF_TABLELOG_MAX + 1]; /* precomputed conversion table */ BYTE bitsToWeight[HUF_TABLELOG_MAX + 1]; /* precomputed conversion table */
BYTE huffWeight[HUF_SYMBOLVALUE_MAX]; BYTE huffWeight[HUF_SYMBOLVALUE_MAX];
} HUF_WriteCTableWksp;
size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize,
const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog,
void* workspace, size_t workspaceSize)
{
BYTE* op = (BYTE*)dst; BYTE* op = (BYTE*)dst;
U32 n; U32 n;
HUF_WriteCTableWksp* wksp = (HUF_WriteCTableWksp*)workspace;
/* check conditions */ /* check conditions */
if (workspaceSize < sizeof(HUF_WriteCTableWksp)) return ERROR(GENERIC);
if (maxSymbolValue > HUF_SYMBOLVALUE_MAX) return ERROR(maxSymbolValue_tooLarge); if (maxSymbolValue > HUF_SYMBOLVALUE_MAX) return ERROR(maxSymbolValue_tooLarge);
/* convert to weight */ /* convert to weight */
wksp->bitsToWeight[0] = 0; bitsToWeight[0] = 0;
for (n=1; n<huffLog+1; n++) for (n=1; n<huffLog+1; n++)
wksp->bitsToWeight[n] = (BYTE)(huffLog + 1 - n); bitsToWeight[n] = (BYTE)(huffLog + 1 - n);
for (n=0; n<maxSymbolValue; n++) for (n=0; n<maxSymbolValue; n++)
wksp->huffWeight[n] = wksp->bitsToWeight[CTable[n].nbBits]; huffWeight[n] = bitsToWeight[CTable[n].nbBits];
/* attempt weights compression by FSE */ /* attempt weights compression by FSE */
{ CHECK_V_F(hSize, HUF_compressWeights(op+1, maxDstSize-1, wksp->huffWeight, maxSymbolValue, &wksp->wksp, sizeof(wksp->wksp)) ); { CHECK_V_F(hSize, HUF_compressWeights(op+1, maxDstSize-1, huffWeight, maxSymbolValue) );
if ((hSize>1) & (hSize < maxSymbolValue/2)) { /* FSE compressed */ if ((hSize>1) & (hSize < maxSymbolValue/2)) { /* FSE compressed */
op[0] = (BYTE)hSize; op[0] = (BYTE)hSize;
return hSize+1; return hSize+1;
@@ -143,22 +134,12 @@ size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize,
if (maxSymbolValue > (256-128)) return ERROR(GENERIC); /* should not happen : likely means source cannot be compressed */ if (maxSymbolValue > (256-128)) return ERROR(GENERIC); /* should not happen : likely means source cannot be compressed */
if (((maxSymbolValue+1)/2) + 1 > maxDstSize) return ERROR(dstSize_tooSmall); /* not enough space within dst buffer */ if (((maxSymbolValue+1)/2) + 1 > maxDstSize) return ERROR(dstSize_tooSmall); /* not enough space within dst buffer */
op[0] = (BYTE)(128 /*special case*/ + (maxSymbolValue-1)); op[0] = (BYTE)(128 /*special case*/ + (maxSymbolValue-1));
wksp->huffWeight[maxSymbolValue] = 0; /* to be sure it doesn't cause msan issue in final combination */ huffWeight[maxSymbolValue] = 0; /* to be sure it doesn't cause msan issue in final combination */
for (n=0; n<maxSymbolValue; n+=2) for (n=0; n<maxSymbolValue; n+=2)
op[(n/2)+1] = (BYTE)((wksp->huffWeight[n] << 4) + wksp->huffWeight[n+1]); op[(n/2)+1] = (BYTE)((huffWeight[n] << 4) + huffWeight[n+1]);
return ((maxSymbolValue+1)/2) + 1; return ((maxSymbolValue+1)/2) + 1;
} }
/*! HUF_writeCTable() :
`CTable` : Huffman tree to save, using huf representation.
@return : size of saved CTable */
size_t HUF_writeCTable (void* dst, size_t maxDstSize,
const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog)
{
HUF_WriteCTableWksp wksp;
return HUF_writeCTable_wksp(dst, maxDstSize, CTable, maxSymbolValue, huffLog, &wksp, sizeof(wksp));
}
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* hasZeroWeights) size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* hasZeroWeights)
{ {
@@ -596,19 +577,16 @@ HUF_compress1X_usingCTable_internal_body(void* dst, size_t dstSize,
n = srcSize & ~3; /* join to mod 4 */ n = srcSize & ~3; /* join to mod 4 */
switch (srcSize & 3) switch (srcSize & 3)
{ {
case 3: case 3 : HUF_encodeSymbol(&bitC, ip[n+ 2], CTable);
HUF_encodeSymbol(&bitC, ip[n+ 2], CTable); HUF_FLUSHBITS_2(&bitC);
HUF_FLUSHBITS_2(&bitC); /* fall-through */
ZSTD_FALLTHROUGH; case 2 : HUF_encodeSymbol(&bitC, ip[n+ 1], CTable);
case 2: HUF_FLUSHBITS_1(&bitC);
HUF_encodeSymbol(&bitC, ip[n+ 1], CTable); /* fall-through */
HUF_FLUSHBITS_1(&bitC); case 1 : HUF_encodeSymbol(&bitC, ip[n+ 0], CTable);
ZSTD_FALLTHROUGH; HUF_FLUSHBITS(&bitC);
case 1: /* fall-through */
HUF_encodeSymbol(&bitC, ip[n+ 0], CTable); case 0 : /* fall-through */
HUF_FLUSHBITS(&bitC);
ZSTD_FALLTHROUGH;
case 0: ZSTD_FALLTHROUGH;
default: break; default: break;
} }
@@ -754,10 +732,7 @@ static size_t HUF_compressCTable_internal(
typedef struct { typedef struct {
unsigned count[HUF_SYMBOLVALUE_MAX + 1]; unsigned count[HUF_SYMBOLVALUE_MAX + 1];
HUF_CElt CTable[HUF_SYMBOLVALUE_MAX + 1]; HUF_CElt CTable[HUF_SYMBOLVALUE_MAX + 1];
union { HUF_buildCTable_wksp_tables buildCTable_wksp;
HUF_buildCTable_wksp_tables buildCTable_wksp;
HUF_WriteCTableWksp writeCTable_wksp;
} wksps;
} HUF_compress_tables_t; } HUF_compress_tables_t;
/* HUF_compress_internal() : /* HUF_compress_internal() :
@@ -820,7 +795,7 @@ HUF_compress_internal (void* dst, size_t dstSize,
huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue); huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue);
{ size_t const maxBits = HUF_buildCTable_wksp(table->CTable, table->count, { size_t const maxBits = HUF_buildCTable_wksp(table->CTable, table->count,
maxSymbolValue, huffLog, maxSymbolValue, huffLog,
&table->wksps.buildCTable_wksp, sizeof(table->wksps.buildCTable_wksp)); &table->buildCTable_wksp, sizeof(table->buildCTable_wksp));
CHECK_F(maxBits); CHECK_F(maxBits);
huffLog = (U32)maxBits; huffLog = (U32)maxBits;
/* Zero unused symbols in CTable, so we can check it for validity */ /* Zero unused symbols in CTable, so we can check it for validity */
@@ -829,8 +804,7 @@ HUF_compress_internal (void* dst, size_t dstSize,
} }
/* Write table description header */ /* Write table description header */
{ CHECK_V_F(hSize, HUF_writeCTable_wksp(op, dstSize, table->CTable, maxSymbolValue, huffLog, { CHECK_V_F(hSize, HUF_writeCTable (op, dstSize, table->CTable, maxSymbolValue, huffLog) );
&table->wksps.writeCTable_wksp, sizeof(table->wksps.writeCTable_wksp)) );
/* Check if using previous huffman table is beneficial */ /* Check if using previous huffman table is beneficial */
if (repeat && *repeat != HUF_repeat_none) { if (repeat && *repeat != HUF_repeat_none) {
size_t const oldSize = HUF_estimateCompressedSize(oldHufTable, table->count, maxSymbolValue); size_t const oldSize = HUF_estimateCompressedSize(oldHufTable, table->count, maxSymbolValue);
+10 -24
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -14,6 +14,7 @@
#include "../common/zstd_deps.h" /* INT_MAX, ZSTD_memset, ZSTD_memcpy */ #include "../common/zstd_deps.h" /* INT_MAX, ZSTD_memset, ZSTD_memcpy */
#include "../common/cpu.h" #include "../common/cpu.h"
#include "../common/mem.h" #include "../common/mem.h"
#include "../common/zstd_trace.h"
#include "hist.h" /* HIST_countFast_wksp */ #include "hist.h" /* HIST_countFast_wksp */
#define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */ #define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */
#include "../common/fse.h" #include "../common/fse.h"
@@ -772,8 +773,8 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams,
return CCtxParams->ldmParams.bucketSizeLog; return CCtxParams->ldmParams.bucketSizeLog;
case ZSTD_c_ldmHashRateLog : case ZSTD_c_ldmHashRateLog :
if (value!=0) /* 0 ==> default */ RETURN_ERROR_IF(value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN,
BOUNDCHECK(ZSTD_c_ldmHashRateLog, value); parameter_outOfBound, "Param out of bounds!");
CCtxParams->ldmParams.hashRateLog = value; CCtxParams->ldmParams.hashRateLog = value;
return CCtxParams->ldmParams.hashRateLog; return CCtxParams->ldmParams.hashRateLog;
@@ -1389,15 +1390,8 @@ size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams)
static size_t ZSTD_estimateCCtxSize_internal(int compressionLevel) static size_t ZSTD_estimateCCtxSize_internal(int compressionLevel)
{ {
int tier = 0; ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
size_t largestSize = 0; return ZSTD_estimateCCtxSize_usingCParams(cParams);
static const unsigned long long srcSizeTiers[4] = {16 KB, 128 KB, 256 KB, ZSTD_CONTENTSIZE_UNKNOWN};
for (; tier < 4; ++tier) {
/* Choose the set of cParams for a given level across all srcSizes that give the largest cctxSize */
ZSTD_compressionParameters const cParams = ZSTD_getCParams_internal(compressionLevel, srcSizeTiers[tier], 0, ZSTD_cpm_noAttachDict);
largestSize = MAX(ZSTD_estimateCCtxSize_usingCParams(cParams), largestSize);
}
return largestSize;
} }
size_t ZSTD_estimateCCtxSize(int compressionLevel) size_t ZSTD_estimateCCtxSize(int compressionLevel)
@@ -1405,7 +1399,6 @@ size_t ZSTD_estimateCCtxSize(int compressionLevel)
int level; int level;
size_t memBudget = 0; size_t memBudget = 0;
for (level=MIN(compressionLevel, 1); level<=compressionLevel; level++) { for (level=MIN(compressionLevel, 1); level<=compressionLevel; level++) {
/* Ensure monotonically increasing memory usage as compression level increases */
size_t const newMB = ZSTD_estimateCCtxSize_internal(level); size_t const newMB = ZSTD_estimateCCtxSize_internal(level);
if (newMB > memBudget) memBudget = newMB; if (newMB > memBudget) memBudget = newMB;
} }
@@ -2977,9 +2970,7 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
if (!singleSegment) op[pos++] = windowLogByte; if (!singleSegment) op[pos++] = windowLogByte;
switch(dictIDSizeCode) switch(dictIDSizeCode)
{ {
default: default: assert(0); /* impossible */
assert(0); /* impossible */
ZSTD_FALLTHROUGH;
case 0 : break; case 0 : break;
case 1 : op[pos] = (BYTE)(dictID); pos++; break; case 1 : op[pos] = (BYTE)(dictID); pos++; break;
case 2 : MEM_writeLE16(op+pos, (U16)dictID); pos+=2; break; case 2 : MEM_writeLE16(op+pos, (U16)dictID); pos+=2; break;
@@ -2987,9 +2978,7 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
} }
switch(fcsCode) switch(fcsCode)
{ {
default: default: assert(0); /* impossible */
assert(0); /* impossible */
ZSTD_FALLTHROUGH;
case 0 : if (singleSegment) op[pos++] = (BYTE)(pledgedSrcSize); break; case 0 : if (singleSegment) op[pos++] = (BYTE)(pledgedSrcSize); break;
case 1 : MEM_writeLE16(op+pos, (U16)(pledgedSrcSize-256)); pos+=2; break; case 1 : MEM_writeLE16(op+pos, (U16)(pledgedSrcSize-256)); pos+=2; break;
case 2 : MEM_writeLE32(op+pos, (U32)(pledgedSrcSize)); pos+=4; break; case 2 : MEM_writeLE32(op+pos, (U32)(pledgedSrcSize)); pos+=4; break;
@@ -4336,7 +4325,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
zcs->outBuffFlushedSize = 0; zcs->outBuffFlushedSize = 0;
zcs->streamStage = zcss_flush; /* pass-through to flush stage */ zcs->streamStage = zcss_flush; /* pass-through to flush stage */
} }
ZSTD_FALLTHROUGH; /* fall-through */
case zcss_flush: case zcss_flush:
DEBUGLOG(5, "flush stage"); DEBUGLOG(5, "flush stage");
assert(zcs->appliedParams.outBufferMode == ZSTD_bm_buffered); assert(zcs->appliedParams.outBufferMode == ZSTD_bm_buffered);
@@ -5197,10 +5186,7 @@ static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(int const
static int ZSTD_dedicatedDictSearch_isSupported( static int ZSTD_dedicatedDictSearch_isSupported(
ZSTD_compressionParameters const* cParams) ZSTD_compressionParameters const* cParams)
{ {
return (cParams->strategy >= ZSTD_greedy) return (cParams->strategy >= ZSTD_greedy) && (cParams->strategy <= ZSTD_lazy2);
&& (cParams->strategy <= ZSTD_lazy2)
&& (cParams->hashLog >= cParams->chainLog)
&& (cParams->chainLog <= 24);
} }
/** /**
+3 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -19,6 +19,7 @@
* Dependencies * Dependencies
***************************************/ ***************************************/
#include "../common/zstd_internal.h" #include "../common/zstd_internal.h"
#include "../common/zstd_trace.h" /* ZSTD_TraceCtx */
#include "zstd_cwksp.h" #include "zstd_cwksp.h"
#ifdef ZSTD_MULTITHREAD #ifdef ZSTD_MULTITHREAD
# include "zstdmt_compress.h" # include "zstdmt_compress.h"
@@ -486,7 +487,7 @@ MEM_STATIC int ZSTD_disableLiteralsCompression(const ZSTD_CCtx_params* cctxParam
return 1; return 1;
default: default:
assert(0 /* impossible: pre-validated */); assert(0 /* impossible: pre-validated */);
ZSTD_FALLTHROUGH; /* fall-through */
case ZSTD_lcm_auto: case ZSTD_lcm_auto:
return (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0); return (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0);
} }
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+6 -12
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -232,11 +232,6 @@ ZSTD_selectEncodingType(
return set_compressed; return set_compressed;
} }
typedef struct {
S16 norm[MaxSeq + 1];
U32 wksp[FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(MaxSeq, MaxFSELog)];
} ZSTD_BuildCTableWksp;
size_t size_t
ZSTD_buildCTable(void* dst, size_t dstCapacity, ZSTD_buildCTable(void* dst, size_t dstCapacity,
FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type, FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type,
@@ -263,7 +258,7 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, entropyWorkspace, entropyWorkspaceSize), ""); /* note : could be pre-calculated */ FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, entropyWorkspace, entropyWorkspaceSize), ""); /* note : could be pre-calculated */
return 0; return 0;
case set_compressed: { case set_compressed: {
ZSTD_BuildCTableWksp* wksp = (ZSTD_BuildCTableWksp*)entropyWorkspace; S16 norm[MaxSeq + 1];
size_t nbSeq_1 = nbSeq; size_t nbSeq_1 = nbSeq;
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max); const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
if (count[codeTable[nbSeq-1]] > 1) { if (count[codeTable[nbSeq-1]] > 1) {
@@ -271,12 +266,11 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
nbSeq_1--; nbSeq_1--;
} }
assert(nbSeq_1 > 1); assert(nbSeq_1 > 1);
assert(entropyWorkspaceSize >= sizeof(ZSTD_BuildCTableWksp)); assert(entropyWorkspaceSize >= FSE_BUILD_CTABLE_WORKSPACE_SIZE(MaxSeq, MaxFSELog));
(void)entropyWorkspaceSize; FORWARD_IF_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max, ZSTD_useLowProbCount(nbSeq_1)), "");
FORWARD_IF_ERROR(FSE_normalizeCount(wksp->norm, tableLog, count, nbSeq_1, max, ZSTD_useLowProbCount(nbSeq_1)), ""); { size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */
{ size_t const NCountSize = FSE_writeNCount(op, oend - op, wksp->norm, max, tableLog); /* overflow protected */
FORWARD_IF_ERROR(NCountSize, "FSE_writeNCount failed"); FORWARD_IF_ERROR(NCountSize, "FSE_writeNCount failed");
FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, wksp->norm, max, tableLog, wksp->wksp, sizeof(wksp->wksp)), ""); FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, norm, max, tableLog, entropyWorkspace, entropyWorkspaceSize), "");
return NCountSize; return NCountSize;
} }
} }
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+3 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -128,10 +128,9 @@ static size_t ZSTD_buildSuperBlockEntropy_literal(void* const src, size_t srcSiz
{ /* Build and write the CTable */ { /* Build and write the CTable */
size_t const newCSize = HUF_estimateCompressedSize( size_t const newCSize = HUF_estimateCompressedSize(
(HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue); (HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue);
size_t const hSize = HUF_writeCTable_wksp( size_t const hSize = HUF_writeCTable(
hufMetadata->hufDesBuffer, sizeof(hufMetadata->hufDesBuffer), hufMetadata->hufDesBuffer, sizeof(hufMetadata->hufDesBuffer),
(HUF_CElt*)nextHuf->CTable, maxSymbolValue, huffLog, (HUF_CElt*)nextHuf->CTable, maxSymbolValue, huffLog);
nodeWksp, nodeWkspSize);
/* Check against repeating the previous CTable */ /* Check against repeating the previous CTable */
if (repeat != HUF_repeat_none) { if (repeat != HUF_repeat_none) {
size_t const oldCSize = HUF_estimateCompressedSize( size_t const oldCSize = HUF_estimateCompressedSize(
@@ -411,8 +410,6 @@ static size_t ZSTD_seqDecompressedSize(seqStore_t const* seqStore, const seqDef*
const seqDef* sp = sstart; const seqDef* sp = sstart;
size_t matchLengthSum = 0; size_t matchLengthSum = 0;
size_t litLengthSum = 0; size_t litLengthSum = 0;
/* Only used by assert(), suppress unused variable warnings in production. */
(void)litLengthSum;
while (send-sp > 0) { while (send-sp > 0) {
ZSTD_sequenceLength const seqLen = ZSTD_getSequenceLength(seqStore, sp); ZSTD_sequenceLength const seqLen = ZSTD_getSequenceLength(seqStore, sp);
litLengthSum += seqLen.litLength; litLengthSum += seqLen.litLength;
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+3 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -244,6 +244,8 @@ _search_next_long:
while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */ while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
} }
/* fall-through */
_match_found: _match_found:
offset_2 = offset_1; offset_2 = offset_1;
offset_1 = offset; offset_1 = offset;
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+5 -7
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -93,7 +93,7 @@ ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
assert(curr >= btLow); assert(curr >= btLow);
assert(ip < iend); /* condition for ZSTD_count */ assert(ip < iend); /* condition for ZSTD_count */
for (; nbCompares && (matchIndex > windowLow); --nbCompares) { while (nbCompares-- && (matchIndex > windowLow)) {
U32* const nextPtr = bt + 2*(matchIndex & btMask); U32* const nextPtr = bt + 2*(matchIndex & btMask);
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
assert(matchIndex < curr); assert(matchIndex < curr);
@@ -185,7 +185,7 @@ ZSTD_DUBT_findBetterDictMatch (
(void)dictMode; (void)dictMode;
assert(dictMode == ZSTD_dictMatchState); assert(dictMode == ZSTD_dictMatchState);
for (; nbCompares && (dictMatchIndex > dictLowLimit); --nbCompares) { while (nbCompares-- && (dictMatchIndex > dictLowLimit)) {
U32* const nextPtr = dictBt + 2*(dictMatchIndex & btMask); U32* const nextPtr = dictBt + 2*(dictMatchIndex & btMask);
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
const BYTE* match = dictBase + dictMatchIndex; const BYTE* match = dictBase + dictMatchIndex;
@@ -309,7 +309,7 @@ ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
matchIndex = hashTable[h]; matchIndex = hashTable[h];
hashTable[h] = curr; /* Update Hash Table */ hashTable[h] = curr; /* Update Hash Table */
for (; nbCompares && (matchIndex > windowLow); --nbCompares) { while (nbCompares-- && (matchIndex > windowLow)) {
U32* const nextPtr = bt + 2*(matchIndex & btMask); U32* const nextPtr = bt + 2*(matchIndex & btMask);
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
const BYTE* match; const BYTE* match;
@@ -357,7 +357,6 @@ ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
*smallerPtr = *largerPtr = 0; *smallerPtr = *largerPtr = 0;
assert(nbCompares <= (1U << ZSTD_SEARCHLOG_MAX)); /* Check we haven't underflowed. */
if (dictMode == ZSTD_dictMatchState && nbCompares) { if (dictMode == ZSTD_dictMatchState && nbCompares) {
bestLength = ZSTD_DUBT_findBetterDictMatch( bestLength = ZSTD_DUBT_findBetterDictMatch(
ms, ip, iend, ms, ip, iend,
@@ -661,7 +660,6 @@ size_t ZSTD_HcFindBestMatch_generic (
matchIndex = NEXT_IN_CHAIN(matchIndex, chainMask); matchIndex = NEXT_IN_CHAIN(matchIndex, chainMask);
} }
assert(nbAttempts <= (1U << ZSTD_SEARCHLOG_MAX)); /* Check we haven't underflowed. */
if (dictMode == ZSTD_dedicatedDictSearch) { if (dictMode == ZSTD_dedicatedDictSearch) {
const U32 ddsLowestIndex = dms->window.dictLimit; const U32 ddsLowestIndex = dms->window.dictLimit;
const BYTE* const ddsBase = dms->window.base; const BYTE* const ddsBase = dms->window.base;
@@ -1266,7 +1264,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
matchLength = ml2, start = ip, offset=offsetFound; matchLength = ml2, start = ip, offset=offsetFound;
} }
if (matchLength < 4) { if (matchLength < 4) {
ip += ((ip-anchor) >> kSearchStrength) + 1; /* jump faster over incompressible sections */ ip += ((ip-anchor) >> kSearchStrength) + 1; /* jump faster over incompressible sections */
continue; continue;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+4 -19
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Przemyslaw Skibinski, Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -8,20 +8,6 @@
* You may select, at your option, one of the above-listed licenses. * You may select, at your option, one of the above-listed licenses.
*/ */
/**
* Disable inlining for the optimal parser for the kernel build.
* It is unlikely to be used in the kernel, and where it is used
* latency shouldn't matter because it is very slow to begin with.
* We prefer a ~180KB binary size win over faster optimal parsing.
*
* TODO(https://github.com/facebook/zstd/issues/2862):
* Improve the code size of the optimal parser in general, so we
* don't need this hack for the kernel build.
*/
#ifdef ZSTD_LINUX_KERNEL
#define ZSTD_NO_INLINE 1
#endif
#include "zstd_compress_internal.h" #include "zstd_compress_internal.h"
#include "hist.h" #include "hist.h"
#include "zstd_opt.h" #include "zstd_opt.h"
@@ -422,7 +408,7 @@ static U32 ZSTD_insertBt1(
hashTable[h] = curr; /* Update Hash Table */ hashTable[h] = curr; /* Update Hash Table */
assert(windowLow > 0); assert(windowLow > 0);
for (; nbCompares && (matchIndex >= windowLow); --nbCompares) { while (nbCompares-- && (matchIndex >= windowLow)) {
U32* const nextPtr = bt + 2*(matchIndex & btMask); U32* const nextPtr = bt + 2*(matchIndex & btMask);
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
assert(matchIndex < curr); assert(matchIndex < curr);
@@ -653,7 +639,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
hashTable[h] = curr; /* Update Hash Table */ hashTable[h] = curr; /* Update Hash Table */
for (; nbCompares && (matchIndex >= matchLow); --nbCompares) { while (nbCompares-- && (matchIndex >= matchLow)) {
U32* const nextPtr = bt + 2*(matchIndex & btMask); U32* const nextPtr = bt + 2*(matchIndex & btMask);
const BYTE* match; const BYTE* match;
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
@@ -706,13 +692,12 @@ U32 ZSTD_insertBtAndGetAllMatches (
*smallerPtr = *largerPtr = 0; *smallerPtr = *largerPtr = 0;
assert(nbCompares <= (1U << ZSTD_SEARCHLOG_MAX)); /* Check we haven't underflowed. */
if (dictMode == ZSTD_dictMatchState && nbCompares) { if (dictMode == ZSTD_dictMatchState && nbCompares) {
size_t const dmsH = ZSTD_hashPtr(ip, dmsHashLog, mls); size_t const dmsH = ZSTD_hashPtr(ip, dmsHashLog, mls);
U32 dictMatchIndex = dms->hashTable[dmsH]; U32 dictMatchIndex = dms->hashTable[dmsH];
const U32* const dmsBt = dms->chainTable; const U32* const dmsBt = dms->chainTable;
commonLengthSmaller = commonLengthLarger = 0; commonLengthSmaller = commonLengthLarger = 0;
for (; nbCompares && (dictMatchIndex > dmsLowLimit); --nbCompares) { while (nbCompares-- && (dictMatchIndex > dmsLowLimit)) {
const U32* const nextPtr = dmsBt + 2*(dictMatchIndex & dmsBtMask); const U32* const nextPtr = dmsBt + 2*(dictMatchIndex & dmsBtMask);
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
const BYTE* match = dmsBase + dictMatchIndex; const BYTE* match = dmsBase + dictMatchIndex;
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+41 -42
View File
@@ -1,7 +1,7 @@
/* ****************************************************************** /* ******************************************************************
* huff0 huffman decoder, * huff0 huffman decoder,
* part of Finite State Entropy library * part of Finite State Entropy library
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
* *
* You can contact the author at : * You can contact the author at :
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy * - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -528,15 +528,13 @@ typedef rankValCol_t rankVal_t[HUF_TABLELOG_MAX];
static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 consumed, static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 consumed,
const U32* rankValOrigin, const int minWeight, const U32* rankValOrigin, const int minWeight,
const sortedSymbol_t* sortedSymbols, const U32 sortedListSize, const sortedSymbol_t* sortedSymbols, const U32 sortedListSize,
U32 nbBitsBaseline, U16 baseSeq, U32* wksp, size_t wkspSize) U32 nbBitsBaseline, U16 baseSeq)
{ {
HUF_DEltX2 DElt; HUF_DEltX2 DElt;
U32* rankVal = wksp; U32 rankVal[HUF_TABLELOG_MAX + 1];
assert(wkspSize >= HUF_TABLELOG_MAX + 1);
(void)wkspSize;
/* get pre-calculated rankVal */ /* get pre-calculated rankVal */
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1)); ZSTD_memcpy(rankVal, rankValOrigin, sizeof(rankVal));
/* fill skipped values */ /* fill skipped values */
if (minWeight>1) { if (minWeight>1) {
@@ -571,18 +569,14 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 co
static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
const sortedSymbol_t* sortedList, const U32 sortedListSize, const sortedSymbol_t* sortedList, const U32 sortedListSize,
const U32* rankStart, rankVal_t rankValOrigin, const U32 maxWeight, const U32* rankStart, rankVal_t rankValOrigin, const U32 maxWeight,
const U32 nbBitsBaseline, U32* wksp, size_t wkspSize) const U32 nbBitsBaseline)
{ {
U32* rankVal = wksp; U32 rankVal[HUF_TABLELOG_MAX + 1];
const int scaleLog = nbBitsBaseline - targetLog; /* note : targetLog >= srcLog, hence scaleLog <= 1 */ const int scaleLog = nbBitsBaseline - targetLog; /* note : targetLog >= srcLog, hence scaleLog <= 1 */
const U32 minBits = nbBitsBaseline - maxWeight; const U32 minBits = nbBitsBaseline - maxWeight;
U32 s; U32 s;
assert(wkspSize >= HUF_TABLELOG_MAX + 1); ZSTD_memcpy(rankVal, rankValOrigin, sizeof(rankVal));
wksp += HUF_TABLELOG_MAX + 1;
wkspSize -= HUF_TABLELOG_MAX + 1;
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(U32) * (HUF_TABLELOG_MAX + 1));
/* fill DTable */ /* fill DTable */
for (s=0; s<sortedListSize; s++) { for (s=0; s<sortedListSize; s++) {
@@ -600,7 +594,7 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits, HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits,
rankValOrigin[nbBits], minWeight, rankValOrigin[nbBits], minWeight,
sortedList+sortedRank, sortedListSize-sortedRank, sortedList+sortedRank, sortedListSize-sortedRank,
nbBitsBaseline, symbol, wksp, wkspSize); nbBitsBaseline, symbol);
} else { } else {
HUF_DEltX2 DElt; HUF_DEltX2 DElt;
MEM_writeLE16(&(DElt.sequence), symbol); MEM_writeLE16(&(DElt.sequence), symbol);
@@ -614,15 +608,6 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
} }
} }
typedef struct {
rankValCol_t rankVal[HUF_TABLELOG_MAX];
U32 rankStats[HUF_TABLELOG_MAX + 1];
U32 rankStart0[HUF_TABLELOG_MAX + 2];
sortedSymbol_t sortedSymbol[HUF_SYMBOLVALUE_MAX + 1];
BYTE weightList[HUF_SYMBOLVALUE_MAX + 1];
U32 calleeWksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
} HUF_ReadDTableX2_Workspace;
size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
const void* src, size_t srcSize, const void* src, size_t srcSize,
void* workSpace, size_t wkspSize) void* workSpace, size_t wkspSize)
@@ -635,32 +620,47 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
HUF_DEltX2* const dt = (HUF_DEltX2*)dtPtr; HUF_DEltX2* const dt = (HUF_DEltX2*)dtPtr;
U32 *rankStart; U32 *rankStart;
HUF_ReadDTableX2_Workspace* const wksp = (HUF_ReadDTableX2_Workspace*)workSpace; rankValCol_t* rankVal;
U32* rankStats;
U32* rankStart0;
sortedSymbol_t* sortedSymbol;
BYTE* weightList;
size_t spaceUsed32 = 0;
if (sizeof(*wksp) > wkspSize) return ERROR(GENERIC); rankVal = (rankValCol_t *)((U32 *)workSpace + spaceUsed32);
spaceUsed32 += (sizeof(rankValCol_t) * HUF_TABLELOG_MAX) >> 2;
rankStats = (U32 *)workSpace + spaceUsed32;
spaceUsed32 += HUF_TABLELOG_MAX + 1;
rankStart0 = (U32 *)workSpace + spaceUsed32;
spaceUsed32 += HUF_TABLELOG_MAX + 2;
sortedSymbol = (sortedSymbol_t *)workSpace + (spaceUsed32 * sizeof(U32)) / sizeof(sortedSymbol_t);
spaceUsed32 += HUF_ALIGN(sizeof(sortedSymbol_t) * (HUF_SYMBOLVALUE_MAX + 1), sizeof(U32)) >> 2;
weightList = (BYTE *)((U32 *)workSpace + spaceUsed32);
spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2;
rankStart = wksp->rankStart0 + 1; if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge);
ZSTD_memset(wksp->rankStats, 0, sizeof(wksp->rankStats));
ZSTD_memset(wksp->rankStart0, 0, sizeof(wksp->rankStart0)); rankStart = rankStart0 + 1;
ZSTD_memset(rankStats, 0, sizeof(U32) * (2 * HUF_TABLELOG_MAX + 2 + 1));
DEBUG_STATIC_ASSERT(sizeof(HUF_DEltX2) == sizeof(HUF_DTable)); /* if compiler fails here, assertion is wrong */ DEBUG_STATIC_ASSERT(sizeof(HUF_DEltX2) == sizeof(HUF_DTable)); /* if compiler fails here, assertion is wrong */
if (maxTableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge); if (maxTableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
/* ZSTD_memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */ /* ZSTD_memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
iSize = HUF_readStats_wksp(wksp->weightList, HUF_SYMBOLVALUE_MAX + 1, wksp->rankStats, &nbSymbols, &tableLog, src, srcSize, wksp->calleeWksp, sizeof(wksp->calleeWksp), /* bmi2 */ 0); iSize = HUF_readStats(weightList, HUF_SYMBOLVALUE_MAX + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
if (HUF_isError(iSize)) return iSize; if (HUF_isError(iSize)) return iSize;
/* check result */ /* check result */
if (tableLog > maxTableLog) return ERROR(tableLog_tooLarge); /* DTable can't fit code depth */ if (tableLog > maxTableLog) return ERROR(tableLog_tooLarge); /* DTable can't fit code depth */
/* find maxWeight */ /* find maxWeight */
for (maxW = tableLog; wksp->rankStats[maxW]==0; maxW--) {} /* necessarily finds a solution before 0 */ for (maxW = tableLog; rankStats[maxW]==0; maxW--) {} /* necessarily finds a solution before 0 */
/* Get start index of each weight */ /* Get start index of each weight */
{ U32 w, nextRankStart = 0; { U32 w, nextRankStart = 0;
for (w=1; w<maxW+1; w++) { for (w=1; w<maxW+1; w++) {
U32 curr = nextRankStart; U32 curr = nextRankStart;
nextRankStart += wksp->rankStats[w]; nextRankStart += rankStats[w];
rankStart[w] = curr; rankStart[w] = curr;
} }
rankStart[0] = nextRankStart; /* put all 0w symbols at the end of sorted list*/ rankStart[0] = nextRankStart; /* put all 0w symbols at the end of sorted list*/
@@ -670,38 +670,37 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
/* sort symbols by weight */ /* sort symbols by weight */
{ U32 s; { U32 s;
for (s=0; s<nbSymbols; s++) { for (s=0; s<nbSymbols; s++) {
U32 const w = wksp->weightList[s]; U32 const w = weightList[s];
U32 const r = rankStart[w]++; U32 const r = rankStart[w]++;
wksp->sortedSymbol[r].symbol = (BYTE)s; sortedSymbol[r].symbol = (BYTE)s;
wksp->sortedSymbol[r].weight = (BYTE)w; sortedSymbol[r].weight = (BYTE)w;
} }
rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */ rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */
} }
/* Build rankVal */ /* Build rankVal */
{ U32* const rankVal0 = wksp->rankVal[0]; { U32* const rankVal0 = rankVal[0];
{ int const rescale = (maxTableLog-tableLog) - 1; /* tableLog <= maxTableLog */ { int const rescale = (maxTableLog-tableLog) - 1; /* tableLog <= maxTableLog */
U32 nextRankVal = 0; U32 nextRankVal = 0;
U32 w; U32 w;
for (w=1; w<maxW+1; w++) { for (w=1; w<maxW+1; w++) {
U32 curr = nextRankVal; U32 curr = nextRankVal;
nextRankVal += wksp->rankStats[w] << (w+rescale); nextRankVal += rankStats[w] << (w+rescale);
rankVal0[w] = curr; rankVal0[w] = curr;
} } } }
{ U32 const minBits = tableLog+1 - maxW; { U32 const minBits = tableLog+1 - maxW;
U32 consumed; U32 consumed;
for (consumed = minBits; consumed < maxTableLog - minBits + 1; consumed++) { for (consumed = minBits; consumed < maxTableLog - minBits + 1; consumed++) {
U32* const rankValPtr = wksp->rankVal[consumed]; U32* const rankValPtr = rankVal[consumed];
U32 w; U32 w;
for (w = 1; w < maxW+1; w++) { for (w = 1; w < maxW+1; w++) {
rankValPtr[w] = rankVal0[w] >> consumed; rankValPtr[w] = rankVal0[w] >> consumed;
} } } } } } } }
HUF_fillDTableX2(dt, maxTableLog, HUF_fillDTableX2(dt, maxTableLog,
wksp->sortedSymbol, sizeOfSort, sortedSymbol, sizeOfSort,
wksp->rankStart0, wksp->rankVal, maxW, rankStart0, rankVal, maxW,
tableLog+1, tableLog+1);
wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32));
dtd.tableLog = (BYTE)maxTableLog; dtd.tableLog = (BYTE)maxTableLog;
dtd.tableType = 1; dtd.tableType = 1;
@@ -886,7 +885,7 @@ HUF_decompress4X2_usingDTable_internal_body(
HUF_DECODE_SYMBOLX2_0(op2, &bitD2); HUF_DECODE_SYMBOLX2_0(op2, &bitD2);
HUF_DECODE_SYMBOLX2_0(op3, &bitD3); HUF_DECODE_SYMBOLX2_0(op3, &bitD3);
HUF_DECODE_SYMBOLX2_0(op4, &bitD4); HUF_DECODE_SYMBOLX2_0(op4, &bitD4);
endSignal = (U32)LIKELY((U32) endSignal = (U32)LIKELY(
(BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished) (BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished)
& (BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished) & (BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished)
& (BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished) & (BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished)
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+11 -20
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -58,6 +58,7 @@
#include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */ #include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
#include "../common/cpu.h" /* bmi2 */ #include "../common/cpu.h" /* bmi2 */
#include "../common/mem.h" /* low level memory routines */ #include "../common/mem.h" /* low level memory routines */
#include "../common/zstd_trace.h"
#define FSE_STATIC_LINKING_ONLY #define FSE_STATIC_LINKING_ONLY
#include "../common/fse.h" #include "../common/fse.h"
#define HUF_STATIC_LINKING_ONLY #define HUF_STATIC_LINKING_ONLY
@@ -177,15 +178,12 @@ static const ZSTD_DDict* ZSTD_DDictHashSet_getDDict(ZSTD_DDictHashSet* hashSet,
static ZSTD_DDictHashSet* ZSTD_createDDictHashSet(ZSTD_customMem customMem) { static ZSTD_DDictHashSet* ZSTD_createDDictHashSet(ZSTD_customMem customMem) {
ZSTD_DDictHashSet* ret = (ZSTD_DDictHashSet*)ZSTD_customMalloc(sizeof(ZSTD_DDictHashSet), customMem); ZSTD_DDictHashSet* ret = (ZSTD_DDictHashSet*)ZSTD_customMalloc(sizeof(ZSTD_DDictHashSet), customMem);
DEBUGLOG(4, "Allocating new hash set"); DEBUGLOG(4, "Allocating new hash set");
if (!ret)
return NULL;
ret->ddictPtrTable = (const ZSTD_DDict**)ZSTD_customCalloc(DDICT_HASHSET_TABLE_BASE_SIZE * sizeof(ZSTD_DDict*), customMem); ret->ddictPtrTable = (const ZSTD_DDict**)ZSTD_customCalloc(DDICT_HASHSET_TABLE_BASE_SIZE * sizeof(ZSTD_DDict*), customMem);
if (!ret->ddictPtrTable) {
ZSTD_customFree(ret, customMem);
return NULL;
}
ret->ddictPtrTableSize = DDICT_HASHSET_TABLE_BASE_SIZE; ret->ddictPtrTableSize = DDICT_HASHSET_TABLE_BASE_SIZE;
ret->ddictPtrCount = 0; ret->ddictPtrCount = 0;
if (!ret || !ret->ddictPtrTable) {
return NULL;
}
return ret; return ret;
} }
@@ -469,9 +467,7 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
} }
switch(dictIDSizeCode) switch(dictIDSizeCode)
{ {
default: default: assert(0); /* impossible */
assert(0); /* impossible */
ZSTD_FALLTHROUGH;
case 0 : break; case 0 : break;
case 1 : dictID = ip[pos]; pos++; break; case 1 : dictID = ip[pos]; pos++; break;
case 2 : dictID = MEM_readLE16(ip+pos); pos+=2; break; case 2 : dictID = MEM_readLE16(ip+pos); pos+=2; break;
@@ -479,9 +475,7 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
} }
switch(fcsID) switch(fcsID)
{ {
default: default: assert(0); /* impossible */
assert(0); /* impossible */
ZSTD_FALLTHROUGH;
case 0 : if (singleSegment) frameContentSize = ip[pos]; break; case 0 : if (singleSegment) frameContentSize = ip[pos]; break;
case 1 : frameContentSize = MEM_readLE16(ip+pos)+256; break; case 1 : frameContentSize = MEM_readLE16(ip+pos)+256; break;
case 2 : frameContentSize = MEM_readLE32(ip+pos); break; case 2 : frameContentSize = MEM_readLE32(ip+pos); break;
@@ -1016,7 +1010,7 @@ static ZSTD_DDict const* ZSTD_getDDict(ZSTD_DCtx* dctx)
switch (dctx->dictUses) { switch (dctx->dictUses) {
default: default:
assert(0 /* Impossible */); assert(0 /* Impossible */);
ZSTD_FALLTHROUGH; /* fall-through */
case ZSTD_dont_use: case ZSTD_dont_use:
ZSTD_clearDict(dctx); ZSTD_clearDict(dctx);
return NULL; return NULL;
@@ -1080,9 +1074,7 @@ ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx) {
{ {
default: /* should not happen */ default: /* should not happen */
assert(0); assert(0);
ZSTD_FALLTHROUGH;
case ZSTDds_getFrameHeaderSize: case ZSTDds_getFrameHeaderSize:
ZSTD_FALLTHROUGH;
case ZSTDds_decodeFrameHeader: case ZSTDds_decodeFrameHeader:
return ZSTDnit_frameHeader; return ZSTDnit_frameHeader;
case ZSTDds_decodeBlockHeader: case ZSTDds_decodeBlockHeader:
@@ -1094,7 +1086,6 @@ ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx) {
case ZSTDds_checkChecksum: case ZSTDds_checkChecksum:
return ZSTDnit_checksum; return ZSTDnit_checksum;
case ZSTDds_decodeSkippableHeader: case ZSTDds_decodeSkippableHeader:
ZSTD_FALLTHROUGH;
case ZSTDds_skipFrame: case ZSTDds_skipFrame:
return ZSTDnit_skippableFrame; return ZSTDnit_skippableFrame;
} }
@@ -1910,7 +1901,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
zds->legacyVersion = 0; zds->legacyVersion = 0;
zds->hostageByte = 0; zds->hostageByte = 0;
zds->expectedOutBuffer = *output; zds->expectedOutBuffer = *output;
ZSTD_FALLTHROUGH; /* fall-through */
case zdss_loadHeader : case zdss_loadHeader :
DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip)); DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip));
@@ -2048,7 +2039,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
zds->outBuffSize = neededOutBuffSize; zds->outBuffSize = neededOutBuffSize;
} } } } } }
zds->streamStage = zdss_read; zds->streamStage = zdss_read;
ZSTD_FALLTHROUGH; /* fall-through */
case zdss_read: case zdss_read:
DEBUGLOG(5, "stage zdss_read"); DEBUGLOG(5, "stage zdss_read");
@@ -2067,7 +2058,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
} } } }
if (ip==iend) { someMoreWork = 0; break; } /* no more input */ if (ip==iend) { someMoreWork = 0; break; } /* no more input */
zds->streamStage = zdss_load; zds->streamStage = zdss_load;
ZSTD_FALLTHROUGH; /* fall-through */
case zdss_load: case zdss_load:
{ size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds); { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -90,7 +90,7 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
case set_repeat: case set_repeat:
DEBUGLOG(5, "set_repeat flag : re-using stats from previous compressed literals block"); DEBUGLOG(5, "set_repeat flag : re-using stats from previous compressed literals block");
RETURN_ERROR_IF(dctx->litEntropy==0, dictionary_corrupted, ""); RETURN_ERROR_IF(dctx->litEntropy==0, dictionary_corrupted, "");
ZSTD_FALLTHROUGH; /* fall-through */
case set_compressed: case set_compressed:
RETURN_ERROR_IF(srcSize < 5, corruption_detected, "srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for case 3"); RETURN_ERROR_IF(srcSize < 5, corruption_detected, "srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for case 3");
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+2 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -21,6 +21,7 @@
*********************************************************/ *********************************************************/
#include "../common/mem.h" /* BYTE, U16, U32 */ #include "../common/mem.h" /* BYTE, U16, U32 */
#include "../common/zstd_internal.h" /* ZSTD_seqSymbol */ #include "../common/zstd_internal.h" /* ZSTD_seqSymbol */
#include "../common/zstd_trace.h" /* ZSTD_TraceCtx */
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2017-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2018-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+12 -14
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -72,7 +72,7 @@ extern "C" {
/*------ Version ------*/ /*------ Version ------*/
#define ZSTD_VERSION_MAJOR 1 #define ZSTD_VERSION_MAJOR 1
#define ZSTD_VERSION_MINOR 4 #define ZSTD_VERSION_MINOR 4
#define ZSTD_VERSION_RELEASE 10 #define ZSTD_VERSION_RELEASE 9
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
/*! ZSTD_versionNumber() : /*! ZSTD_versionNumber() :
@@ -199,7 +199,7 @@ ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compres
*/ */
typedef struct ZSTD_CCtx_s ZSTD_CCtx; typedef struct ZSTD_CCtx_s ZSTD_CCtx;
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */ ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
/*! ZSTD_compressCCtx() : /*! ZSTD_compressCCtx() :
* Same as ZSTD_compress(), using an explicit ZSTD_CCtx. * Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
@@ -222,7 +222,7 @@ ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
* Use one context per thread for parallel execution. */ * Use one context per thread for parallel execution. */
typedef struct ZSTD_DCtx_s ZSTD_DCtx; typedef struct ZSTD_DCtx_s ZSTD_DCtx;
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */ ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);
/*! ZSTD_decompressDCtx() : /*! ZSTD_decompressDCtx() :
* Same as ZSTD_decompress(), * Same as ZSTD_decompress(),
@@ -667,7 +667,7 @@ typedef ZSTD_CCtx ZSTD_CStream; /**< CCtx and CStream are now effectively same
/* Continue to distinguish them for compatibility with older versions <= v1.2.0 */ /* Continue to distinguish them for compatibility with older versions <= v1.2.0 */
/*===== ZSTD_CStream management functions =====*/ /*===== ZSTD_CStream management functions =====*/
ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void);
ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); /* accept NULL pointer */ ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
/*===== Streaming compression functions =====*/ /*===== Streaming compression functions =====*/
typedef enum { typedef enum {
@@ -788,7 +788,7 @@ typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same
/* For compatibility with versions <= v1.2.0, prefer differentiating them. */ /* For compatibility with versions <= v1.2.0, prefer differentiating them. */
/*===== ZSTD_DStream management functions =====*/ /*===== ZSTD_DStream management functions =====*/
ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void);
ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer */ ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds);
/*===== Streaming decompression functions =====*/ /*===== Streaming decompression functions =====*/
@@ -854,8 +854,7 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize
int compressionLevel); int compressionLevel);
/*! ZSTD_freeCDict() : /*! ZSTD_freeCDict() :
* Function frees memory allocated by ZSTD_createCDict(). * Function frees memory allocated by ZSTD_createCDict(). */
* If a NULL pointer is passed, no operation is performed. */
ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
/*! ZSTD_compress_usingCDict() : /*! ZSTD_compress_usingCDict() :
@@ -877,8 +876,7 @@ typedef struct ZSTD_DDict_s ZSTD_DDict;
ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize); ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
/*! ZSTD_freeDDict() : /*! ZSTD_freeDDict() :
* Function frees memory allocated with ZSTD_createDDict() * Function frees memory allocated with ZSTD_createDDict() */
* If a NULL pointer is passed, no operation is performed. */
ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
/*! ZSTD_decompress_usingDDict() : /*! ZSTD_decompress_usingDDict() :
@@ -1540,11 +1538,11 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictS
* Note that the lifetime of such pool must exist while being used. * Note that the lifetime of such pool must exist while being used.
* ZSTD_CCtx_refThreadPool assigns a thread pool to a context (use NULL argument value * ZSTD_CCtx_refThreadPool assigns a thread pool to a context (use NULL argument value
* to use an internal thread pool). * to use an internal thread pool).
* ZSTD_freeThreadPool frees a thread pool, accepts NULL pointer. * ZSTD_freeThreadPool frees a thread pool.
*/ */
typedef struct POOL_ctx_s ZSTD_threadPool; typedef struct POOL_ctx_s ZSTD_threadPool;
ZSTDLIB_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads); ZSTDLIB_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
ZSTDLIB_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool); /* accept NULL pointer */ ZSTDLIB_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool);
ZSTDLIB_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool); ZSTDLIB_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool);
@@ -1854,13 +1852,13 @@ ZSTDLIB_API size_t ZSTD_CCtx_getParameter(const ZSTD_CCtx* cctx, ZSTD_cParameter
* These parameters will be applied to * These parameters will be applied to
* all subsequent frames. * all subsequent frames.
* - ZSTD_compressStream2() : Do compression using the CCtx. * - ZSTD_compressStream2() : Do compression using the CCtx.
* - ZSTD_freeCCtxParams() : Free the memory, accept NULL pointer. * - ZSTD_freeCCtxParams() : Free the memory.
* *
* This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams() * This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
* for static allocation of CCtx for single-threaded compression. * for static allocation of CCtx for single-threaded compression.
*/ */
ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void); ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); /* accept NULL pointer */ ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
/*! ZSTD_CCtxParams_reset() : /*! ZSTD_CCtxParams_reset() :
* Reset params to default values. * Reset params to default values.
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -1509,7 +1509,7 @@ FIO_compressFilename_internal(FIO_ctx_t* const fCtx,
U64 readsize = 0; U64 readsize = 0;
U64 compressedfilesize = 0; U64 compressedfilesize = 0;
U64 const fileSize = UTIL_getFileSize(srcFileName); U64 const fileSize = UTIL_getFileSize(srcFileName);
DISPLAYLEVEL(5, "%s: %llu bytes \n", srcFileName, (unsigned long long)fileSize); DISPLAYLEVEL(5, "%s: %u bytes \n", srcFileName, (unsigned)fileSize);
/* compression format selection */ /* compression format selection */
switch (prefs->compressionType) { switch (prefs->compressionType) {
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Przemyslaw Skibinski, Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2019-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+3 -8
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Przemyslaw Skibinski, Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -1212,17 +1212,12 @@ int UTIL_countPhysicalCores(void)
/* fall back on the sysconf value */ /* fall back on the sysconf value */
goto failed; goto failed;
} } } }
if (siblings && cpu_cores && siblings > cpu_cores) { if (siblings && cpu_cores) {
ratio = siblings / cpu_cores; ratio = siblings / cpu_cores;
} }
if (ratio && numPhysicalCores > ratio) {
numPhysicalCores = numPhysicalCores / ratio;
}
failed: failed:
fclose(cpuinfo); fclose(cpuinfo);
return numPhysicalCores; return numPhysicalCores = numPhysicalCores / ratio;
} }
} }
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Przemyslaw Skibinski, Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -2,7 +2,7 @@
# THIS BENCHMARK IS BEING REPLACED BY automated-bencmarking.py # THIS BENCHMARK IS BEING REPLACED BY automated-bencmarking.py
# ################################################################ # ################################################################
# Copyright (c) Przemyslaw Skibinski, Yann Collet, Facebook, Inc. # Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2021-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2017-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2018-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2017-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2016-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/** /**
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/** /**
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2016-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -43
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
@@ -3181,48 +3181,6 @@ static int basicUnitTests(U32 const seed, double compressibility)
} }
DISPLAYLEVEL(3, "OK \n"); DISPLAYLEVEL(3, "OK \n");
DISPLAYLEVEL(3, "test%3i : check compression mem usage monotonicity over levels for estimateCCtxSize() : ", testNb++);
{
int level = 1;
size_t prevSize = 0;
for (; level < ZSTD_maxCLevel(); ++level) {
size_t const currSize = ZSTD_estimateCCtxSize(level);
if (prevSize > currSize) {
DISPLAYLEVEL(3, "Error! previous cctx size: %zu at level: %d is larger than current cctx size: %zu at level: %d",
prevSize, level-1, currSize, level);
goto _output_error;
}
prevSize = currSize;
}
}
DISPLAYLEVEL(3, "OK \n");
DISPLAYLEVEL(3, "test%3i : check estimateCCtxSize() always larger or equal to ZSTD_estimateCCtxSize_usingCParams() : ", testNb++);
{
size_t const kSizeIncrement = 2 KB;
int level = -3;
for (; level <= ZSTD_maxCLevel(); ++level) {
size_t dictSize = 0;
for (; dictSize <= 256 KB; dictSize += 8 * kSizeIncrement) {
size_t srcSize = 2 KB;
for (; srcSize < 300 KB; srcSize += kSizeIncrement) {
ZSTD_compressionParameters const cParams = ZSTD_getCParams(level, srcSize, dictSize);
size_t const cctxSizeUsingCParams = ZSTD_estimateCCtxSize_usingCParams(cParams);
size_t const cctxSizeUsingLevel = ZSTD_estimateCCtxSize(level);
if (cctxSizeUsingLevel < cctxSizeUsingCParams
|| ZSTD_isError(cctxSizeUsingCParams)
|| ZSTD_isError(cctxSizeUsingLevel)) {
DISPLAYLEVEL(3, "error! l: %d dict: %zu srcSize: %zu cctx size cpar: %zu, cctx size level: %zu\n",
level, dictSize, srcSize, cctxSizeUsingCParams, cctxSizeUsingLevel);
goto _output_error;
}
}
}
}
}
DISPLAYLEVEL(3, "OK \n");
#endif #endif
_end: _end:
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2017-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2017-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
-2
View File
@@ -805,8 +805,6 @@ println "- Dictionary compression roundtrip"
zstd -f tmp -D tmpDict zstd -f tmp -D tmpDict
zstd -d tmp.zst -D tmpDict -fo result zstd -d tmp.zst -D tmpDict -fo result
$DIFF "$TESTFILE" result $DIFF "$TESTFILE" result
println "- Dictionary compression with hlog < clog"
zstd -6f tmp -D tmpDict --zstd=clog=25,hlog=23
println "- Dictionary compression with btlazy2 strategy" println "- Dictionary compression with btlazy2 strategy"
zstd -f tmp -D tmpDict --zstd=strategy=6 zstd -f tmp -D tmpDict --zstd=strategy=6
zstd -d tmp.zst -D tmpDict -fo result zstd -d tmp.zst -D tmpDict -fo result
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2018-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2015-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+6 -6
View File
@@ -171,7 +171,7 @@ github, level 7 with dict, zstdcli,
github, level 9, zstdcli, 137122 github, level 9, zstdcli, 137122
github, level 9 with dict, zstdcli, 41332 github, level 9 with dict, zstdcli, 41332
github, level 13, zstdcli, 136064 github, level 13, zstdcli, 136064
github, level 13 with dict, zstdcli, 41900 github, level 13 with dict, zstdcli, 41743
github, level 16, zstdcli, 136064 github, level 16, zstdcli, 136064
github, level 16 with dict, zstdcli, 39577 github, level 16 with dict, zstdcli, 39577
github, level 19, zstdcli, 136064 github, level 19, zstdcli, 136064
@@ -303,7 +303,7 @@ github, level 7 with dict, advanced
github, level 9, advanced one pass, 135122 github, level 9, advanced one pass, 135122
github, level 9 with dict, advanced one pass, 39332 github, level 9 with dict, advanced one pass, 39332
github, level 13, advanced one pass, 134064 github, level 13, advanced one pass, 134064
github, level 13 with dict, advanced one pass, 39900 github, level 13 with dict, advanced one pass, 39743
github, level 16, advanced one pass, 134064 github, level 16, advanced one pass, 134064
github, level 16 with dict, advanced one pass, 37577 github, level 16 with dict, advanced one pass, 37577
github, level 19, advanced one pass, 134064 github, level 19, advanced one pass, 134064
@@ -437,7 +437,7 @@ github, level 7 with dict, advanced
github, level 9, advanced one pass small out, 135122 github, level 9, advanced one pass small out, 135122
github, level 9 with dict, advanced one pass small out, 39332 github, level 9 with dict, advanced one pass small out, 39332
github, level 13, advanced one pass small out, 134064 github, level 13, advanced one pass small out, 134064
github, level 13 with dict, advanced one pass small out, 39900 github, level 13 with dict, advanced one pass small out, 39743
github, level 16, advanced one pass small out, 134064 github, level 16, advanced one pass small out, 134064
github, level 16 with dict, advanced one pass small out, 37577 github, level 16 with dict, advanced one pass small out, 37577
github, level 19, advanced one pass small out, 134064 github, level 19, advanced one pass small out, 134064
@@ -571,7 +571,7 @@ github, level 7 with dict, advanced
github, level 9, advanced streaming, 135122 github, level 9, advanced streaming, 135122
github, level 9 with dict, advanced streaming, 39332 github, level 9 with dict, advanced streaming, 39332
github, level 13, advanced streaming, 134064 github, level 13, advanced streaming, 134064
github, level 13 with dict, advanced streaming, 39900 github, level 13 with dict, advanced streaming, 39743
github, level 16, advanced streaming, 134064 github, level 16, advanced streaming, 134064
github, level 16 with dict, advanced streaming, 37577 github, level 16 with dict, advanced streaming, 37577
github, level 19, advanced streaming, 134064 github, level 19, advanced streaming, 134064
@@ -689,7 +689,7 @@ github, level 7 with dict, old stre
github, level 9, old streaming, 135122 github, level 9, old streaming, 135122
github, level 9 with dict, old streaming, 39332 github, level 9 with dict, old streaming, 39332
github, level 13, old streaming, 134064 github, level 13, old streaming, 134064
github, level 13 with dict, old streaming, 39900 github, level 13 with dict, old streaming, 39743
github, level 16, old streaming, 134064 github, level 16, old streaming, 134064
github, level 16 with dict, old streaming, 37577 github, level 16 with dict, old streaming, 37577
github, level 19, old streaming, 134064 github, level 19, old streaming, 134064
@@ -877,7 +877,7 @@ github, level 5 with dict, old stre
github, level 6 with dict, old streaming cdcit, 38632 github, level 6 with dict, old streaming cdcit, 38632
github, level 7 with dict, old streaming cdcit, 38771 github, level 7 with dict, old streaming cdcit, 38771
github, level 9 with dict, old streaming cdcit, 39332 github, level 9 with dict, old streaming cdcit, 39332
github, level 13 with dict, old streaming cdcit, 39900 github, level 13 with dict, old streaming cdcit, 39743
github, level 16 with dict, old streaming cdcit, 37577 github, level 16 with dict, old streaming cdcit, 37577
github, level 19 with dict, old streaming cdcit, 37576 github, level 19 with dict, old streaming cdcit, 37576
github, no source size with dict, old streaming cdcit, 40654 github, no source size with dict, old streaming cdcit, 40654
1 Data Config Method Total compressed size
171 github level 9 zstdcli 137122
172 github level 9 with dict zstdcli 41332
173 github level 13 zstdcli 136064
174 github level 13 with dict zstdcli 41900 41743
175 github level 16 zstdcli 136064
176 github level 16 with dict zstdcli 39577
177 github level 19 zstdcli 136064
303 github level 9 advanced one pass 135122
304 github level 9 with dict advanced one pass 39332
305 github level 13 advanced one pass 134064
306 github level 13 with dict advanced one pass 39900 39743
307 github level 16 advanced one pass 134064
308 github level 16 with dict advanced one pass 37577
309 github level 19 advanced one pass 134064
437 github level 9 advanced one pass small out 135122
438 github level 9 with dict advanced one pass small out 39332
439 github level 13 advanced one pass small out 134064
440 github level 13 with dict advanced one pass small out 39900 39743
441 github level 16 advanced one pass small out 134064
442 github level 16 with dict advanced one pass small out 37577
443 github level 19 advanced one pass small out 134064
571 github level 9 advanced streaming 135122
572 github level 9 with dict advanced streaming 39332
573 github level 13 advanced streaming 134064
574 github level 13 with dict advanced streaming 39900 39743
575 github level 16 advanced streaming 134064
576 github level 16 with dict advanced streaming 37577
577 github level 19 advanced streaming 134064
689 github level 9 old streaming 135122
690 github level 9 with dict old streaming 39332
691 github level 13 old streaming 134064
692 github level 13 with dict old streaming 39900 39743
693 github level 16 old streaming 134064
694 github level 16 with dict old streaming 37577
695 github level 19 old streaming 134064
877 github level 6 with dict old streaming cdcit 38632
878 github level 7 with dict old streaming cdcit 38771
879 github level 9 with dict old streaming cdcit 39332
880 github level 13 with dict old streaming cdcit 39900 39743
881 github level 16 with dict old streaming cdcit 37577
882 github level 19 with dict old streaming cdcit 37576
883 github no source size with dict old streaming cdcit 40654
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2016-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2017-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Facebook, Inc. * Copyright (c) 2017-2021, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+28 -42
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# ################################################################ # ################################################################
# Copyright (c) Facebook, Inc. # Copyright (c) 2016-2021, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
@@ -10,12 +10,16 @@
# You may select, at your option, one of the above-listed licenses. # You may select, at your option, one of the above-listed licenses.
# ################################################################ # ################################################################
import datetime
import enum import enum
import glob import glob
import os import os
import re
import sys import sys
YEAR = datetime.datetime.now().year
YEAR_STR = str(YEAR)
ROOT = os.path.join(os.path.dirname(__file__), "..") ROOT = os.path.join(os.path.dirname(__file__), "..")
RELDIRS = [ RELDIRS = [
@@ -24,26 +28,22 @@ RELDIRS = [
"lib", "lib",
"programs", "programs",
"tests", "tests",
"contrib/linux-kernel",
] ]
REL_EXCLUDES = [ DIRS = [os.path.join(ROOT, d) for d in RELDIRS]
"contrib/linux-kernel/test/include",
]
def to_abs(d): class File(enum.Enum):
return os.path.normpath(os.path.join(ROOT, d)) + "/" C = 1
H = 2
MAKE = 3
PY = 4
DIRS = [to_abs(d) for d in RELDIRS] SUFFIX = {
EXCLUDES = [to_abs(d) for d in REL_EXCLUDES] File.C: ".c",
File.H: ".h",
SUFFIXES = [ File.MAKE: "Makefile",
".c", File.PY: ".py",
".h", }
"Makefile",
".mk",
".py",
]
# License should certainly be in the first 10 KB. # License should certainly be in the first 10 KB.
MAX_BYTES = 10000 MAX_BYTES = 10000
@@ -69,13 +69,10 @@ LICENSE_EXCEPTIONS = {
# From divsufsort # From divsufsort
"divsufsort.c", "divsufsort.c",
"divsufsort.h", "divsufsort.h",
# License is slightly different because it references GitHub
"linux_zstd.h",
} }
def valid_copyright(lines): def valid_copyright(lines):
YEAR_REGEX = re.compile("\d\d\d\d|present")
for line in lines: for line in lines:
line = line.strip() line = line.strip()
if "Copyright" not in line: if "Copyright" not in line:
@@ -84,9 +81,8 @@ def valid_copyright(lines):
return (False, f"Copyright line '{line}' contains 'present'!") return (False, f"Copyright line '{line}' contains 'present'!")
if "Facebook, Inc" not in line: if "Facebook, Inc" not in line:
return (False, f"Copyright line '{line}' does not contain 'Facebook, Inc'") return (False, f"Copyright line '{line}' does not contain 'Facebook, Inc'")
year = YEAR_REGEX.search(line) if YEAR_STR not in line:
if year is not None: return (False, f"Copyright line '{line}' does not contain {YEAR}")
return (False, f"Copyright line '{line}' contains {year.group(0)}; it should be yearless")
if " (c) " not in line: if " (c) " not in line:
return (False, f"Copyright line '{line}' does not contain ' (c) '!") return (False, f"Copyright line '{line}' does not contain ' (c) '!")
return (True, "") return (True, "")
@@ -116,40 +112,30 @@ def valid_file(filename):
if os.path.basename(filename) not in COPYRIGHT_EXCEPTIONS: if os.path.basename(filename) not in COPYRIGHT_EXCEPTIONS:
c_ok, c_msg = valid_copyright(lines) c_ok, c_msg = valid_copyright(lines)
if not c_ok: if not c_ok:
print(f"{filename}: {c_msg}", file=sys.stderr) print(f"{filename}: {c_msg}")
ok = False ok = False
if os.path.basename(filename) not in LICENSE_EXCEPTIONS: if os.path.basename(filename) not in LICENSE_EXCEPTIONS:
l_ok, l_msg = valid_license(lines) l_ok, l_msg = valid_license(lines)
if not l_ok: if not l_ok:
print(f"{filename}: {l_msg}", file=sys.stderr) print(f"{filename}: {l_msg}")
ok = False ok = False
return ok return ok
def exclude(filename):
for x in EXCLUDES:
if filename.startswith(x):
return True
return False
def main(): def main():
invalid_files = [] invalid_files = []
for directory in DIRS: for directory in DIRS:
for suffix in SUFFIXES: for suffix in SUFFIX.values():
files = set(glob.glob(f"{directory}/**/*{suffix}", recursive=True)) files = set(glob.glob(f"{directory}/*{suffix}"))
files |= set(glob.glob(f"{directory}/**/*{suffix}"))
for filename in files: for filename in files:
if exclude(filename):
continue
if not valid_file(filename): if not valid_file(filename):
invalid_files.append(filename) invalid_files.append(filename)
if len(invalid_files) > 0: if len(invalid_files) > 0:
print("Fail!", file=sys.stderr) print(f"Invalid files: {invalid_files}")
for f in invalid_files:
print(f)
return 1
else: else:
print("Pass!", file=sys.stderr) print("Pass!")
return 0 return len(invalid_files)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())
+1 -1
View File
@@ -2,7 +2,7 @@
"""Test zstd interoperability between versions""" """Test zstd interoperability between versions"""
# ################################################################ # ################################################################
# Copyright (c) Yann Collet, Facebook, Inc. # Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
# All rights reserved. # All rights reserved.
# #
# This source code is licensed under both the BSD-style license (found in the # This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) Yann Collet, Facebook, Inc. * Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the BSD-style license (found in the * This source code is licensed under both the BSD-style license (found in the