refactor(compress): expose parameter policy leaves from Rust

Remove the C forwarding wrappers around compression-parameter policy leaves
that are now implemented directly under their caller-facing ABI symbols.
Keep the private C parameter construction and resource logic in C, while Rust
continues to own the pure row-matchfinder, block-splitter, LDM, external
sequence/repcode, dictionary-tagging, block-size, and overflow predicates.

Test Plan: Pending capped full verification after the companion CLI leaf commit.
This commit is contained in:
2026-07-20 11:00:57 +02:00
parent 5ccc6f89fb
commit 03ac61063d
3 changed files with 99 additions and 188 deletions
+41 -97
View File
@@ -798,8 +798,8 @@ typedef char ZSTD_rust_overflow_correct_state_layout[
void ZSTD_rust_copyCDictTableIntoCCtx(U32* dst, U32 const* src,
size_t tableSize, int tagged);
U64 ZSTD_rust_advanceHashSalt(U64 hashSalt, U64 hashSaltEntropy);
int ZSTD_rust_indexTooCloseToMax(size_t nextSrcBaseOffset);
int ZSTD_rust_dictTooBig(size_t loadedDictSize);
int ZSTD_indexTooCloseToMax(size_t nextSrcBaseOffset);
int ZSTD_dictTooBig(size_t loadedDictSize);
/* Match-state reset orchestration lives in Rust. The callbacks keep the
* workspace implementation, window representation, and private pointer
@@ -1964,20 +1964,20 @@ ZSTD_compressionParameters ZSTD_rust_params_getCParamsFromCCtxParams(
ZSTD_parameters ZSTD_rust_params_makeParams(ZSTD_compressionParameters cParams);
size_t ZSTD_rust_params_maxNbSeq(size_t blockSize, U32 minMatch,
int useSequenceProducer);
size_t ZSTD_rust_params_resolveMaxBlockSize(size_t maxBlockSize);
size_t ZSTD_resolveMaxBlockSize(size_t maxBlockSize);
size_t ZSTD_rust_params_getBlockSize(size_t maxBlockSize, U32 windowLog);
int ZSTD_rust_params_resolveExternalSequenceValidation(int mode);
int ZSTD_rust_params_rowMatchFinderSupported(int strategy);
int ZSTD_resolveExternalSequenceValidation(int mode);
int ZSTD_rowMatchFinderSupported(int strategy);
int ZSTD_rust_params_rowMatchFinderUsed(int strategy, int mode);
int ZSTD_rust_params_resolveRowMatchFinderMode(
int ZSTD_resolveRowMatchFinderMode(
int mode, ZSTD_compressionParameters cParams);
int ZSTD_rust_params_resolveBlockSplitterMode(
int ZSTD_resolveBlockSplitterMode(
int mode, ZSTD_compressionParameters cParams);
int ZSTD_rust_params_allocateChainTable(int strategy, int mode, int forDDSDict);
int ZSTD_rust_params_resolveEnableLdm(
int ZSTD_resolveEnableLdm(
int mode, ZSTD_compressionParameters cParams);
int ZSTD_rust_params_resolveExternalRepcodeSearch(int mode, int cLevel);
int ZSTD_rust_params_cdictIndicesAreTagged(ZSTD_compressionParameters cParams);
int ZSTD_resolveExternalRepcodeSearch(int mode, int cLevel);
int ZSTD_CDictIndicesAreTagged(ZSTD_compressionParameters cParams);
ZSTD_compressionParameters
ZSTD_rust_params_dedicatedDictSearch_revertCParams(ZSTD_compressionParameters cParams);
int ZSTD_rust_params_getCParamMode(int cdict_present, int cdict_strategy,
@@ -3565,54 +3565,8 @@ size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs)
/* private API call, for dictBuilder only */
const SeqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStore); }
/* Returns true if the strategy supports using a row based matchfinder */
static int ZSTD_rowMatchFinderSupported(const ZSTD_strategy strategy) {
return ZSTD_rust_params_rowMatchFinderSupported((int)strategy);
}
/* Returns row matchfinder usage given an initial mode and cParams */
static ZSTD_ParamSwitch_e ZSTD_resolveRowMatchFinderMode(ZSTD_ParamSwitch_e mode,
const ZSTD_compressionParameters* const cParams) {
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveRowMatchFinderMode(
(int)mode, *cParams);
}
/* Returns block splitter usage (generally speaking, when using slower/stronger compression modes) */
static ZSTD_ParamSwitch_e ZSTD_resolveBlockSplitterMode(ZSTD_ParamSwitch_e mode,
const ZSTD_compressionParameters* const cParams) {
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveBlockSplitterMode(
(int)mode, *cParams);
}
/* Returns ZSTD_ps_enable if compression parameters are such that we should
* enable long distance matching (wlog >= 27, strategy >= btopt).
* Returns ZSTD_ps_disable otherwise.
*/
static ZSTD_ParamSwitch_e ZSTD_resolveEnableLdm(ZSTD_ParamSwitch_e mode,
const ZSTD_compressionParameters* const cParams) {
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveEnableLdm(
(int)mode, *cParams);
}
static int ZSTD_resolveExternalSequenceValidation(int mode) {
return ZSTD_rust_params_resolveExternalSequenceValidation(mode);
}
/* Resolves maxBlockSize to the default if no value is present. */
static size_t ZSTD_resolveMaxBlockSize(size_t maxBlockSize) {
return ZSTD_rust_params_resolveMaxBlockSize(maxBlockSize);
}
static ZSTD_ParamSwitch_e ZSTD_resolveExternalRepcodeSearch(ZSTD_ParamSwitch_e value, int cLevel) {
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveExternalRepcodeSearch(
(int)value, cLevel);
}
/* Returns 1 if compression parameters are such that CDict hashtable and chaintable indices are tagged.
* If so, the tags need to be removed in ZSTD_resetCCtx_byCopyingCDict. */
static int ZSTD_CDictIndicesAreTagged(const ZSTD_compressionParameters* const cParams) {
return ZSTD_rust_params_cdictIndicesAreTagged(*cParams);
}
/* These pure policy leaves are implemented in Rust under their caller symbols.
* C retains the surrounding private-state and configuration-sensitive logic. */
static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
ZSTD_compressionParameters cParams)
@@ -4093,8 +4047,8 @@ size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
{
ZSTD_compressionParameters const cParams =
ZSTD_getCParamsFromCCtxParams(params, ZSTD_CONTENTSIZE_UNKNOWN, 0, ZSTD_cpm_noAttachDict);
ZSTD_ParamSwitch_e const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params->useRowMatchFinder,
&cParams);
ZSTD_ParamSwitch_e const useRowMatchFinder = (ZSTD_ParamSwitch_e)
ZSTD_resolveRowMatchFinderMode((int)params->useRowMatchFinder, cParams);
RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-threaded compression only.");
/* estimateCCtxSize is for one-shot compression. So no buffers should
@@ -4107,7 +4061,7 @@ size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams)
{
ZSTD_CCtx_params initialParams = ZSTD_makeCCtxParamsFromCParams(cParams);
if (ZSTD_rowMatchFinderSupported(cParams.strategy)) {
if (ZSTD_rowMatchFinderSupported((int)cParams.strategy)) {
/* Pick bigger of not using and using row-based matchfinder for greedy and lazy strategies */
size_t noRowCCtxSize;
size_t rowCCtxSize;
@@ -4171,7 +4125,9 @@ size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params)
size_t const outBuffSize = (params->outBufferMode == ZSTD_bm_buffered)
? ZSTD_compressBound(blockSize) + 1
: 0;
ZSTD_ParamSwitch_e const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params->useRowMatchFinder, &params->cParams);
ZSTD_ParamSwitch_e const useRowMatchFinder = (ZSTD_ParamSwitch_e)
ZSTD_resolveRowMatchFinderMode(
(int)params->useRowMatchFinder, params->cParams);
return ZSTD_estimateCCtxSize_usingCCtxParams_internal(
&cParams, &params->ldmParams, 1, useRowMatchFinder, inBuffSize, outBuffSize,
@@ -4182,7 +4138,7 @@ size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params)
size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams)
{
ZSTD_CCtx_params initialParams = ZSTD_makeCCtxParamsFromCParams(cParams);
if (ZSTD_rowMatchFinderSupported(cParams.strategy)) {
if (ZSTD_rowMatchFinderSupported((int)cParams.strategy)) {
/* Pick bigger of not using and using row-based matchfinder for greedy and lazy strategies */
size_t noRowCCtxSize;
size_t rowCCtxSize;
@@ -4501,28 +4457,8 @@ ZSTD_reset_matchState(ZSTD_MatchState_t* ms,
return ZSTD_rust_resetMatchState(&state);
}
/* ZSTD_indexTooCloseToMax() :
* minor optimization : prefer memset() rather than reduceIndex()
* which is measurably slow in some circumstances (reported for Visual Studio).
* Works when re-using a context for a lot of smallish inputs :
* if all inputs are smaller than ZSTD_INDEXOVERFLOW_MARGIN,
* memset() will be triggered before reduceIndex().
*/
#define ZSTD_INDEXOVERFLOW_MARGIN (16 MB)
static int ZSTD_indexTooCloseToMax(ZSTD_window_t w)
{
return ZSTD_rust_indexTooCloseToMax((size_t)(w.nextSrc - w.base));
}
/** ZSTD_dictTooBig():
* When dictionaries are larger than ZSTD_CHUNKSIZE_MAX they can't be loaded in
* one go generically. So we ensure that in that case we reset the tables to zero,
* so that we can load as much of the dictionary as possible.
*/
static int ZSTD_dictTooBig(size_t const loadedDictSize)
{
return ZSTD_rust_dictTooBig(loadedDictSize);
}
/* ZSTD_indexTooCloseToMax() and ZSTD_dictTooBig() are Rust-owned scalar policy
* leaves. C retains the window and dictionary state used to supply inputs. */
typedef struct {
ZSTD_CCtx* cctx;
@@ -4877,7 +4813,9 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
zbuff == ZSTDb_buffered && params->outBufferMode == ZSTD_bm_buffered;
resetState.useSequenceProducer = ZSTD_hasExtSeqProd(params);
resetState.initialized = zc->initialized != 0;
resetState.indexTooClose = ZSTD_indexTooCloseToMax(zc->blockState.matchState.window);
resetState.indexTooClose = ZSTD_indexTooCloseToMax((size_t)(
zc->blockState.matchState.window.nextSrc
- zc->blockState.matchState.window.base));
resetState.dictTooBig = ZSTD_dictTooBig(loadedDictSize);
resetState.pledgedSrcSize = pledgedSrcSize;
resetState.maxBlockSize = params->maxBlockSize;
@@ -5108,7 +5046,7 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
int const sourceStrategy = (int)cdict_cParams->strategy;
int const sourceUseRowMatchFinder = (int)cdict->useRowMatchFinder;
int const sourceIndicesTagged =
ZSTD_CDictIndicesAreTagged(cdict_cParams);
ZSTD_CDictIndicesAreTagged(*cdict_cParams);
ZSTD_rust_resetCCtxByCopyingCDictState state;
state.callbackContext = cctx;
state.cdict = cdict;
@@ -6404,7 +6342,7 @@ static size_t ZSTD_loadDictionaryContent_callback(
state.hashReadSize = HASH_READ_SIZE;
state.hashLog = cctxParams->cParams.hashLog;
state.chainLog = cctxParams->cParams.chainLog;
state.cdictIndicesTagged = ZSTD_CDictIndicesAreTagged(&cctxParams->cParams);
state.cdictIndicesTagged = ZSTD_CDictIndicesAreTagged(cctxParams->cParams);
state.ldmEnabled = cctxParams->ldmParams.enableLdm == ZSTD_ps_enable;
state.hasLdmState = ls != NULL;
state.forceWindow = cctxParams->forceWindow;
@@ -7374,7 +7312,8 @@ const ZSTD_CDict* ZSTD_initStaticCDict(
ZSTD_dictContentType_e dictContentType,
ZSTD_compressionParameters cParams)
{
ZSTD_ParamSwitch_e const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(ZSTD_ps_auto, &cParams);
ZSTD_ParamSwitch_e const useRowMatchFinder = (ZSTD_ParamSwitch_e)
ZSTD_resolveRowMatchFinderMode((int)ZSTD_ps_auto, cParams);
ZSTD_rustCDictSizing const sizing = {
sizeof(ZSTD_CDict),
HUF_WORKSPACE_SIZE,
@@ -8075,16 +8014,19 @@ static void ZSTD_rust_compressStreamInit_resolveParams(void* params, int operati
ZSTD_CCtx_params* const cctxParams = (ZSTD_CCtx_params*)params;
switch (operation) {
case ZSTD_RUST_INIT_RESOLVE_BLOCK_SPLITTER:
cctxParams->postBlockSplitter = ZSTD_resolveBlockSplitterMode(
cctxParams->postBlockSplitter, &cctxParams->cParams);
cctxParams->postBlockSplitter = (ZSTD_ParamSwitch_e)
ZSTD_resolveBlockSplitterMode(
(int)cctxParams->postBlockSplitter, cctxParams->cParams);
break;
case ZSTD_RUST_INIT_RESOLVE_LDM:
cctxParams->ldmParams.enableLdm = ZSTD_resolveEnableLdm(
cctxParams->ldmParams.enableLdm, &cctxParams->cParams);
cctxParams->ldmParams.enableLdm = (ZSTD_ParamSwitch_e)
ZSTD_resolveEnableLdm(
(int)cctxParams->ldmParams.enableLdm, cctxParams->cParams);
break;
case ZSTD_RUST_INIT_RESOLVE_ROW_MATCH_FINDER:
cctxParams->useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(
cctxParams->useRowMatchFinder, &cctxParams->cParams);
cctxParams->useRowMatchFinder = (ZSTD_ParamSwitch_e)
ZSTD_resolveRowMatchFinderMode(
(int)cctxParams->useRowMatchFinder, cctxParams->cParams);
break;
case ZSTD_RUST_INIT_RESOLVE_VALIDATE_SEQUENCES:
cctxParams->validateSequences = ZSTD_resolveExternalSequenceValidation(
@@ -8094,8 +8036,10 @@ static void ZSTD_rust_compressStreamInit_resolveParams(void* params, int operati
cctxParams->maxBlockSize = ZSTD_resolveMaxBlockSize(cctxParams->maxBlockSize);
break;
case ZSTD_RUST_INIT_RESOLVE_EXTERNAL_REPCODE_SEARCH:
cctxParams->searchForExternalRepcodes = ZSTD_resolveExternalRepcodeSearch(
cctxParams->searchForExternalRepcodes, cctxParams->compressionLevel);
cctxParams->searchForExternalRepcodes = (ZSTD_ParamSwitch_e)
ZSTD_resolveExternalRepcodeSearch(
(int)cctxParams->searchForExternalRepcodes,
cctxParams->compressionLevel);
break;
default:
assert(0);
+12 -13
View File
@@ -29,14 +29,13 @@ use crate::zstd_compress_frame::{
};
use crate::zstd_compress_literals::min_gain;
use crate::zstd_compress_params::{
ZSTD_compressionParameters, ZSTD_frameParameters, ZSTD_parameters, ZSTD_rustMatchStateSizing,
ZSTD_rust_params_adjustCParams, ZSTD_rust_params_allocateChainTable,
ZSTD_compressionParameters, ZSTD_frameParameters, ZSTD_parameters, ZSTD_resolveMaxBlockSize,
ZSTD_rustMatchStateSizing, ZSTD_rust_params_adjustCParams, ZSTD_rust_params_allocateChainTable,
ZSTD_rust_params_checkCParams, ZSTD_rust_params_defaultCLevel,
ZSTD_rust_params_estimateMatchStateSize, ZSTD_rust_params_getParamsInternal,
ZSTD_rust_params_maxNbSeq, ZSTD_rust_params_resolveMaxBlockSize,
ZSTD_rust_params_rowMatchFinderUsed, ZSTD_rust_params_selectBlockCompressor,
ZSTD_rust_params_selectCParams, ZSTD_RUST_CPM_NO_ATTACH_DICT, ZSTD_RUST_PS_AUTO,
ZSTD_RUST_PS_DISABLE, ZSTD_RUST_PS_ENABLE,
ZSTD_rust_params_maxNbSeq, ZSTD_rust_params_rowMatchFinderUsed,
ZSTD_rust_params_selectBlockCompressor, ZSTD_rust_params_selectCParams,
ZSTD_RUST_CPM_NO_ATTACH_DICT, ZSTD_RUST_PS_AUTO, ZSTD_RUST_PS_DISABLE, ZSTD_RUST_PS_ENABLE,
};
use crate::zstd_compress_params_api::{
ZSTD_CCtxParams_setParameter, ZSTD_CCtx_params, ZSTD_customMem, ZSTD_rust_isUpdateAuthorized,
@@ -7018,7 +7017,7 @@ fn index_too_close_to_max(next_src_base_offset: usize) -> bool {
/// Return whether a scalar C window offset is within the overflow margin.
#[no_mangle]
pub extern "C" fn ZSTD_rust_indexTooCloseToMax(next_src_base_offset: usize) -> c_int {
pub extern "C" fn ZSTD_indexTooCloseToMax(next_src_base_offset: usize) -> c_int {
index_too_close_to_max(next_src_base_offset) as c_int
}
@@ -7029,7 +7028,7 @@ fn dict_too_big(loaded_dict_size: usize) -> bool {
/// Return whether a dictionary exceeds the maximum loadable chunk size.
#[no_mangle]
pub extern "C" fn ZSTD_rust_dictTooBig(loaded_dict_size: usize) -> c_int {
pub extern "C" fn ZSTD_dictTooBig(loaded_dict_size: usize) -> c_int {
dict_too_big(loaded_dict_size) as c_int
}
@@ -7577,7 +7576,7 @@ pub unsafe extern "C" fn ZSTD_rust_estimateCCtxWorkspaceSize(
let sizing = unsafe { *sizing };
let window_limit = 1u64.checked_shl(cparams.windowLog).unwrap_or(u64::MAX);
let window_size = (window_limit.min(pledged_src_size).min(usize::MAX as u64) as usize).max(1);
let block_size = ZSTD_rust_params_resolveMaxBlockSize(max_block_size).min(window_size);
let block_size = ZSTD_resolveMaxBlockSize(max_block_size).min(window_size);
let max_nb_seq = ZSTD_rust_params_maxNbSeq(block_size, cparams.minMatch, use_sequence_producer);
let token_space = cctx_cwksp_alloc_size(
sizing.wildcopyOverlength.wrapping_add(block_size),
@@ -14157,8 +14156,8 @@ mod tests {
let threshold = ZSTD_CURRENT_MAX - ZSTD_INDEXOVERFLOW_MARGIN;
assert!(!index_too_close_to_max(threshold));
assert!(index_too_close_to_max(threshold + 1));
assert_eq!(ZSTD_rust_indexTooCloseToMax(threshold), 0);
assert_eq!(ZSTD_rust_indexTooCloseToMax(threshold + 1), 1);
assert_eq!(ZSTD_indexTooCloseToMax(threshold), 0);
assert_eq!(ZSTD_indexTooCloseToMax(threshold + 1), 1);
}
#[derive(Default)]
@@ -14373,8 +14372,8 @@ mod tests {
assert!(!dict_too_big(0));
assert!(!dict_too_big(ZSTD_CHUNKSIZE_MAX));
assert!(dict_too_big(ZSTD_CHUNKSIZE_MAX + 1));
assert_eq!(ZSTD_rust_dictTooBig(ZSTD_CHUNKSIZE_MAX), 0);
assert_eq!(ZSTD_rust_dictTooBig(ZSTD_CHUNKSIZE_MAX + 1), 1);
assert_eq!(ZSTD_dictTooBig(ZSTD_CHUNKSIZE_MAX), 0);
assert_eq!(ZSTD_dictTooBig(ZSTD_CHUNKSIZE_MAX + 1), 1);
}
#[test]
+46 -78
View File
@@ -5,9 +5,9 @@
//! Context-free compression-parameter selection and sizing leaves.
//!
//! The public `ZSTD_*` symbols remain C-owned thin adapters. Rust owns the
//! context-free getter policy behind scalar ABI functions. `zstd_compress.c`
//! still owns configuration-sensitive policy: private `ZSTD_CCtx_params`
//! The pure `ZSTD_*` policy leaves are exported directly from Rust under their
//! caller symbols. `zstd_compress.c` still owns configuration-sensitive
//! policy: private `ZSTD_CCtx_params`
//! layouts, the C-preprocessor construction of excluded block-compressor
//! bits, LDM workspace sizing, and ASAN workspace policy. The Rust policy
//! leaves receive those build values as explicit scalar inputs, retaining
@@ -428,7 +428,7 @@ fn row_match_finder_used(strategy: c_int, mode: c_int) -> bool {
/// C ABI for `ZSTD_rowMatchFinderSupported()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_rowMatchFinderSupported(strategy: c_int) -> c_int {
pub extern "C" fn ZSTD_rowMatchFinderSupported(strategy: c_int) -> c_int {
c_int::from(strategy_supports_row_match_finder(strategy))
}
@@ -471,7 +471,7 @@ fn resolve_row_match_finder(mode: c_int, cparams: ZSTD_compressionParameters) ->
/// C ABI for `ZSTD_resolveRowMatchFinderMode()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_resolveRowMatchFinderMode(
pub extern "C" fn ZSTD_resolveRowMatchFinderMode(
mode: c_int,
cparams: ZSTD_compressionParameters,
) -> c_int {
@@ -492,7 +492,7 @@ fn resolve_block_splitter(mode: c_int, cparams: ZSTD_compressionParameters) -> c
/// C ABI for `ZSTD_resolveBlockSplitterMode()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_resolveBlockSplitterMode(
pub extern "C" fn ZSTD_resolveBlockSplitterMode(
mode: c_int,
cparams: ZSTD_compressionParameters,
) -> c_int {
@@ -513,10 +513,7 @@ fn resolve_enable_ldm(mode: c_int, cparams: ZSTD_compressionParameters) -> c_int
/// C ABI for `ZSTD_resolveEnableLdm()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_resolveEnableLdm(
mode: c_int,
cparams: ZSTD_compressionParameters,
) -> c_int {
pub extern "C" fn ZSTD_resolveEnableLdm(mode: c_int, cparams: ZSTD_compressionParameters) -> c_int {
resolve_enable_ldm(mode, cparams)
}
@@ -534,7 +531,7 @@ fn resolve_external_repcode_search(mode: c_int, compression_level: c_int) -> c_i
/// C ABI for `ZSTD_resolveExternalRepcodeSearch()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_resolveExternalRepcodeSearch(
pub extern "C" fn ZSTD_resolveExternalRepcodeSearch(
mode: c_int,
compression_level: c_int,
) -> c_int {
@@ -548,7 +545,7 @@ fn resolve_external_sequence_validation(mode: c_int) -> c_int {
/// C ABI for `ZSTD_resolveExternalSequenceValidation()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_resolveExternalSequenceValidation(mode: c_int) -> c_int {
pub extern "C" fn ZSTD_resolveExternalSequenceValidation(mode: c_int) -> c_int {
resolve_external_sequence_validation(mode)
}
@@ -690,9 +687,7 @@ fn get_cparam_mode(
/// C ABI for `ZSTD_CDictIndicesAreTagged()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_cdictIndicesAreTagged(
cparams: ZSTD_compressionParameters,
) -> c_int {
pub extern "C" fn ZSTD_CDictIndicesAreTagged(cparams: ZSTD_compressionParameters) -> c_int {
c_int::from(cdict_indices_are_tagged(cparams))
}
@@ -1517,7 +1512,7 @@ pub extern "C" fn ZSTD_rust_params_maxNbSeq(
/// Pure leaf for private `ZSTD_resolveMaxBlockSize()`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_resolveMaxBlockSize(maxBlockSize: usize) -> usize {
pub extern "C" fn ZSTD_resolveMaxBlockSize(maxBlockSize: usize) -> usize {
if maxBlockSize == 0 {
ZSTD_BLOCKSIZE_MAX
} else {
@@ -1525,6 +1520,15 @@ pub extern "C" fn ZSTD_rust_params_resolveMaxBlockSize(maxBlockSize: usize) -> u
}
}
/* These crate-local aliases keep the parameter API modules outside this
* cleanup source-compatible. They are not `no_mangle` C exports. */
pub(crate) use ZSTD_resolveBlockSplitterMode as ZSTD_rust_params_resolveBlockSplitterMode;
pub(crate) use ZSTD_resolveEnableLdm as ZSTD_rust_params_resolveEnableLdm;
pub(crate) use ZSTD_resolveExternalRepcodeSearch as ZSTD_rust_params_resolveExternalRepcodeSearch;
pub(crate) use ZSTD_resolveExternalSequenceValidation as ZSTD_rust_params_resolveExternalSequenceValidation;
pub(crate) use ZSTD_resolveMaxBlockSize as ZSTD_rust_params_resolveMaxBlockSize;
pub(crate) use ZSTD_resolveRowMatchFinderMode as ZSTD_rust_params_resolveRowMatchFinderMode;
#[inline]
fn get_block_size(max_block_size: usize, window_log: u32) -> usize {
max_block_size.min(1usize << window_log)
@@ -1717,10 +1721,10 @@ mod tests {
#[test]
fn row_match_finder_policy_preserves_strategy_and_window_boundaries() {
assert_eq!(ZSTD_rust_params_rowMatchFinderSupported(ZSTD_FAST), 0);
assert_eq!(ZSTD_rust_params_rowMatchFinderSupported(ZSTD_GREEDY), 1);
assert_eq!(ZSTD_rust_params_rowMatchFinderSupported(ZSTD_LAZY2), 1);
assert_eq!(ZSTD_rust_params_rowMatchFinderSupported(ZSTD_BTLAZY2), 0);
assert_eq!(ZSTD_rowMatchFinderSupported(ZSTD_FAST), 0);
assert_eq!(ZSTD_rowMatchFinderSupported(ZSTD_GREEDY), 1);
assert_eq!(ZSTD_rowMatchFinderSupported(ZSTD_LAZY2), 1);
assert_eq!(ZSTD_rowMatchFinderSupported(ZSTD_BTLAZY2), 0);
assert_eq!(
ZSTD_rust_params_rowMatchFinderUsed(ZSTD_GREEDY, ZSTD_RUST_PS_ENABLE),
@@ -1736,31 +1740,19 @@ mod tests {
);
assert_eq!(
ZSTD_rust_params_resolveRowMatchFinderMode(
ZSTD_RUST_PS_AUTO,
policy_cparams(ZSTD_GREEDY, 14),
),
ZSTD_resolveRowMatchFinderMode(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_GREEDY, 14),),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveRowMatchFinderMode(
ZSTD_RUST_PS_AUTO,
policy_cparams(ZSTD_GREEDY, 15),
),
ZSTD_resolveRowMatchFinderMode(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_GREEDY, 15),),
ZSTD_RUST_PS_ENABLE
);
assert_eq!(
ZSTD_rust_params_resolveRowMatchFinderMode(
ZSTD_RUST_PS_AUTO,
policy_cparams(ZSTD_BTLAZY2, 31),
),
ZSTD_resolveRowMatchFinderMode(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTLAZY2, 31),),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveRowMatchFinderMode(
ZSTD_RUST_PS_ENABLE,
policy_cparams(ZSTD_FAST, 14),
),
ZSTD_resolveRowMatchFinderMode(ZSTD_RUST_PS_ENABLE, policy_cparams(ZSTD_FAST, 14),),
ZSTD_RUST_PS_ENABLE
);
}
@@ -1826,51 +1818,36 @@ mod tests {
#[test]
fn block_splitter_and_ldm_policy_match_window_boundaries() {
assert_eq!(
ZSTD_rust_params_resolveBlockSplitterMode(
ZSTD_RUST_PS_AUTO,
policy_cparams(ZSTD_BTOPT, 16),
),
ZSTD_resolveBlockSplitterMode(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTOPT, 16),),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveBlockSplitterMode(
ZSTD_RUST_PS_AUTO,
policy_cparams(ZSTD_BTOPT, 17),
),
ZSTD_resolveBlockSplitterMode(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTOPT, 17),),
ZSTD_RUST_PS_ENABLE
);
assert_eq!(
ZSTD_rust_params_resolveBlockSplitterMode(
ZSTD_RUST_PS_AUTO,
policy_cparams(ZSTD_BTLAZY2, 31),
),
ZSTD_resolveBlockSplitterMode(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTLAZY2, 31),),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveBlockSplitterMode(
ZSTD_RUST_PS_ENABLE,
policy_cparams(ZSTD_FAST, 1),
),
ZSTD_resolveBlockSplitterMode(ZSTD_RUST_PS_ENABLE, policy_cparams(ZSTD_FAST, 1),),
ZSTD_RUST_PS_ENABLE
);
assert_eq!(
ZSTD_rust_params_resolveEnableLdm(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTOPT, 26),),
ZSTD_resolveEnableLdm(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTOPT, 26),),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveEnableLdm(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTOPT, 27),),
ZSTD_resolveEnableLdm(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTOPT, 27),),
ZSTD_RUST_PS_ENABLE
);
assert_eq!(
ZSTD_rust_params_resolveEnableLdm(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTLAZY2, 31),),
ZSTD_resolveEnableLdm(ZSTD_RUST_PS_AUTO, policy_cparams(ZSTD_BTLAZY2, 31),),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveEnableLdm(
ZSTD_RUST_PS_DISABLE,
policy_cparams(ZSTD_BTULTRA2, 31),
),
ZSTD_resolveEnableLdm(ZSTD_RUST_PS_DISABLE, policy_cparams(ZSTD_BTULTRA2, 31),),
ZSTD_RUST_PS_DISABLE
);
}
@@ -1898,36 +1875,30 @@ mod tests {
#[test]
fn external_repcode_and_cdict_tagging_match_boundaries() {
assert_eq!(
ZSTD_rust_params_resolveExternalRepcodeSearch(ZSTD_RUST_PS_AUTO, 9),
ZSTD_resolveExternalRepcodeSearch(ZSTD_RUST_PS_AUTO, 9),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveExternalRepcodeSearch(ZSTD_RUST_PS_AUTO, 10),
ZSTD_resolveExternalRepcodeSearch(ZSTD_RUST_PS_AUTO, 10),
ZSTD_RUST_PS_ENABLE
);
assert_eq!(
ZSTD_rust_params_resolveExternalRepcodeSearch(ZSTD_RUST_PS_DISABLE, 100),
ZSTD_resolveExternalRepcodeSearch(ZSTD_RUST_PS_DISABLE, 100),
ZSTD_RUST_PS_DISABLE
);
assert_eq!(
ZSTD_rust_params_resolveExternalRepcodeSearch(ZSTD_RUST_PS_ENABLE, -100),
ZSTD_resolveExternalRepcodeSearch(ZSTD_RUST_PS_ENABLE, -100),
ZSTD_RUST_PS_ENABLE
);
assert_eq!(ZSTD_CDictIndicesAreTagged(policy_cparams(ZSTD_FAST, 1)), 1);
assert_eq!(ZSTD_CDictIndicesAreTagged(policy_cparams(ZSTD_DFAST, 1)), 1);
assert_eq!(
ZSTD_rust_params_cdictIndicesAreTagged(policy_cparams(ZSTD_FAST, 1)),
1
);
assert_eq!(
ZSTD_rust_params_cdictIndicesAreTagged(policy_cparams(ZSTD_DFAST, 1)),
1
);
assert_eq!(
ZSTD_rust_params_cdictIndicesAreTagged(policy_cparams(ZSTD_GREEDY, 1)),
ZSTD_CDictIndicesAreTagged(policy_cparams(ZSTD_GREEDY, 1)),
0
);
assert_eq!(
ZSTD_rust_params_cdictIndicesAreTagged(policy_cparams(ZSTD_BTULTRA2, 1)),
ZSTD_CDictIndicesAreTagged(policy_cparams(ZSTD_BTULTRA2, 1)),
0
);
}
@@ -2267,10 +2238,7 @@ mod tests {
#[test]
fn external_sequence_validation_preserves_its_int_mode() {
for mode in [c_int::MIN, -1, 0, 1, c_int::MAX] {
assert_eq!(
ZSTD_rust_params_resolveExternalSequenceValidation(mode),
mode
);
assert_eq!(ZSTD_resolveExternalSequenceValidation(mode), mode);
}
}
@@ -2838,7 +2806,7 @@ mod tests {
);
assert_eq!(ZSTD_rust_params_maxNbSeq(100, 3, 0), 33);
assert_eq!(ZSTD_rust_params_maxNbSeq(100, 4, 0), 25);
assert_eq!(ZSTD_rust_params_resolveMaxBlockSize(0), 128 * 1024);
assert_eq!(ZSTD_resolveMaxBlockSize(0), 128 * 1024);
}
#[test]