feat(compress): move pledged source setter into Rust

Move the active-stage check and pledged-size update behind a scalar Rust ABI
leaf while keeping the CCtx layout and public C entry point in C. Preserve the
stage_wrong error encoding and the unsigned wrap behavior at U64::MAX.

Test Plan:
- cargo test --manifest-path rust/Cargo.toml --lib zstd_compress::tests (80 passed)
- cargo clippy --manifest-path rust/Cargo.toml --lib -- -D warnings
- rustfmt +nightly --edition 2021 rust/src/zstd_compress.rs --check
- make -C programs -j2 zstd
- git diff --check
This commit is contained in:
2026-07-18 17:45:30 +02:00
parent 643cb45d89
commit a4a64f2e38
2 changed files with 80 additions and 4 deletions
+5 -4
View File
@@ -48,6 +48,9 @@ int ZSTD_rust_updateFrameProgression(unsigned long long* consumedSrcSize,
unsigned long long pledgedSrcSizePlusOne,
size_t srcSize, size_t cSize,
size_t fhSize);
size_t ZSTD_rust_setPledgedSrcSize(int streamStage,
unsigned long long pledgedSrcSize,
unsigned long long* pledgedSrcSizePlusOne);
ZSTD_frameProgression ZSTD_rust_frameProgression(U64 consumedSrcSize,
size_t buffered,
U64 producedCSize);
@@ -974,10 +977,8 @@ size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params)
size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize)
{
DEBUGLOG(4, "ZSTD_CCtx_setPledgedSrcSize to %llu bytes", pledgedSrcSize);
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong,
"Can't set pledgedSrcSize when not in init stage.");
cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
return 0;
return ZSTD_rust_setPledgedSrcSize((int)cctx->streamStage, pledgedSrcSize,
&cctx->pledgedSrcSizePlusOne);
}
static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(