feat(compress): move CParamMode policy to Rust

Keep C responsible for extracting the cdict and CCtx scalar fields while
moving the attach-versus-copy mode decision into the Rust parameter module.
The Rust ABI short-circuits absent cdicts and reuses the established
attachment predicate, preserving unknown-size, force-attach, force-copy, and
force-window behavior.

Test Plan:
- cargo test --manifest-path rust/Cargo.toml --no-default-features
  --features compression
  cparam_mode_preserves_cdict_presence_and_attachment_policy -- passed
- make -B -C lib -j2 lib -- passed
- make -C tests -j2 fuzzer -- passed
- ./tests/fuzzer -s4560 -t47 -i48 -v -- passed
- Required clippy normal/benches/tests, nightly fmt, and diff checks -- passed
This commit is contained in:
2026-07-18 09:42:58 +02:00
parent 527cf01031
commit 3c51a97814
2 changed files with 108 additions and 4 deletions
+15 -4
View File
@@ -134,6 +134,11 @@ U32 ZSTD_rust_params_dedicatedDictSearch_revertHashLog(U32 hashLog);
int ZSTD_rust_params_shouldAttachDict(int strategy, int dedicatedDictSearch,
U64 pledgedSrcSize, int attachDictPref,
int forceWindow);
int ZSTD_rust_params_getCParamMode(int cdict_present, int cdict_strategy,
int cdict_dedicated_search,
U64 pledgedSrcSize,
int params_attachDictPref,
int params_forceWindow);
/* CCtx parameter state is mirrored by rust/src/zstd_compress_params_api.rs.
* Rust owns parameter bounds and clamping; C exposes only the
@@ -4400,10 +4405,16 @@ size_t ZSTD_CStreamOutSize(void)
static ZSTD_CParamMode_e ZSTD_getCParamMode(ZSTD_CDict const* cdict, ZSTD_CCtx_params const* params, U64 pledgedSrcSize)
{
if (cdict != NULL && ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize))
return ZSTD_cpm_attachDict;
else
return ZSTD_cpm_noAttachDict;
int const cdict_present = cdict != NULL;
int const cdict_strategy = cdict_present ? cdict->matchState.cParams.strategy : 0;
int const cdict_dedicated_search = cdict_present ? cdict->matchState.dedicatedDictSearch : 0;
return (ZSTD_CParamMode_e)ZSTD_rust_params_getCParamMode(
cdict_present,
cdict_strategy,
cdict_dedicated_search,
pledgedSrcSize,
(int)params->attachDictPref,
params->forceWindow);
}
/* ZSTD_resetCStream():