feat(compress): move frame progression ingestion to Rust

Keep ZSTD_getFrameProgression's multithreaded path and C-owned frame
construction unchanged while moving the single-thread ingested-value
calculation behind the existing scalar C-to-Rust boundary. The Rust helper
accepts the consumed U64 value and buffered size_t value, explicitly converts
the latter to u64, and uses wrapping addition to match C's unsigned
arithmetic. Focused tests cover zero, ordinary, and overflowing inputs.

Test Plan:
- `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` -- passed before and after formatting.
- The same clippy command with `--benches` -- passed before and after formatting.
- The same clippy command with `--tests` -- passed before and after formatting.
- `cargo +nightly fmt --manifest-path rust/Cargo.toml` -- passed.
- Focused Rust tests for `frame_progression_ingested` -- 3 passed.
- `make -B -C lib -j2 lib` -- passed.
- `make -C tests test-rust-lib-smoke` -- passed.
- `tests/fuzzer -s4560 -t56 -i57 -v` -- passed.
- `make -C tests -j2 test-zstream` -- passed: 84 named, 5,800, and 9,479 randomized cases.
- `git diff --check` and `git diff --cached --check` -- passed.

The zstream run retains the pre-existing warning at
`tests/zstreamtest.c:1899` about an unterminated initializer string.
This commit is contained in:
2026-07-18 13:03:34 +02:00
parent fcec7d3cc6
commit bf3440aea6
2 changed files with 49 additions and 1 deletions
+2 -1
View File
@@ -48,6 +48,7 @@ int ZSTD_rust_updateFrameProgression(unsigned long long* consumedSrcSize,
unsigned long long pledgedSrcSizePlusOne,
size_t srcSize, size_t cSize,
size_t fhSize);
U64 ZSTD_rust_frameProgressionIngested(U64 consumedSrcSize, size_t buffered);
size_t ZSTD_rust_resetCCtxForSimpleCompression(void* cctx);
size_t ZSTD_rust_prepareCCtxForSimpleCompression(void* cctx,
size_t srcSize,
@@ -1437,7 +1438,7 @@ ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx)
cctx->inBuffPos - cctx->inToCompress;
if (buffered) assert(cctx->inBuffPos >= cctx->inToCompress);
assert(buffered <= ZSTD_BLOCKSIZE_MAX);
fp.ingested = cctx->consumedSrcSize + buffered;
fp.ingested = ZSTD_rust_frameProgressionIngested(cctx->consumedSrcSize, buffered);
fp.consumed = cctx->consumedSrcSize;
fp.produced = cctx->producedCSize;
fp.flushed = cctx->producedCSize; /* simplified; some data might still be left within streaming output buffer */