refactor(cdict): move match-state reset policy to Rust

CDict initialization still hard-coded the match-state reset policies in its
C callback, even though Rust already owned the surrounding content branch,
workspace reservation, and callback ordering. That left the reset target and
cleanup policy split across the language boundary and made the intended CDict
reset contract implicit.

Extend the existing repr(C) reset callback with the three private enum values.
Rust now selects make-clean, index-reset, and the CDict reset target before
calling the opaque C operation. C retains the private ZSTD_CDict, workspace,
and match-state layouts and only casts the projected values for
ZSTD_reset_matchState(). Focused by-reference and by-copy probes record the
values and preserve reserve, reset, and insert ordering.

Test Plan:
- `rustfmt --check --edition 2021 rust/src/zstd_compress_dictionary.rs` -- passed.
- GCC and Clang syntax-only checks for `lib/compress/zstd_compress.c` under
  `ulimit -v 41943040` -- passed.
- `cargo check --manifest-path rust/Cargo.toml --lib --tests` under the cap -- passed.
- Serial `cargo clippy` lib, benches, and tests passes with `-D warnings`,
  plus `cargo +nightly fmt --all -- --check` -- passed.
- `cargo test --manifest-path rust/Cargo.toml --lib zstd_compress_dictionary
  -- --test-threads=1` compiled but could not link the standalone test binary
  because three pre-existing C bridge symbols are unavailable outside the
  native harness; no native, upstream, or fuzzer tests were run.
This commit is contained in:
2026-07-21 09:44:30 +02:00
parent d8403672d5
commit 2eb56f3434
2 changed files with 34 additions and 4 deletions
+7 -3
View File
@@ -2877,7 +2877,8 @@ typedef void* (*ZSTD_rust_initCDictReserveEntropy_f)(
void* context, size_t workspaceSize);
typedef size_t (*ZSTD_rust_initCDictResetMatchState_f)(
void* context, const ZSTD_compressionParameters* cParams,
int useRowMatchFinder);
int useRowMatchFinder, int compResetPolicy,
int indexResetPolicy, int resetTarget);
typedef size_t (*ZSTD_rust_initCDictInsertDictionary_f)(
void* context, const void* params, const void* dict,
size_t dictSize, int dictContentType, int dtlm, int tfp);
@@ -6696,13 +6697,16 @@ static void* ZSTD_rust_initCDict_reserveEntropy(
static size_t ZSTD_rust_initCDict_resetMatchState(
void* context, const ZSTD_compressionParameters* cParams,
int useRowMatchFinder)
int useRowMatchFinder, int compResetPolicy,
int indexResetPolicy, int resetTarget)
{
ZSTD_CDict* const cdict = (ZSTD_CDict*)context;
return ZSTD_reset_matchState(
&cdict->matchState, &cdict->workspace, cParams,
(ZSTD_ParamSwitch_e)useRowMatchFinder,
ZSTDcrp_makeClean, ZSTDirp_reset, ZSTD_resetTarget_CDict);
(ZSTD_compResetPolicy_e)compResetPolicy,
(ZSTD_indexResetPolicy_e)indexResetPolicy,
(ZSTD_resetTarget_e)resetTarget);
}
static size_t ZSTD_rust_initCDict_insertDictionary(