feat(compress): move end-flush input policy to Rust

Keep ZSTD_CStream context access and caller-specific streaming behavior in C,
while moving the pure stable-versus-buffered input-buffer policy to a scalar
Rust ABI helper. The helper returns the public repr(C) buffer layout, preserves
stable-mode source, size, and position values including NULL sources, and
returns a zeroed buffer for every other mode.

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` and `--tests` -- passed before and after formatting
- `cargo +nightly fmt --manifest-path rust/Cargo.toml` -- passed
- `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression` -- 274 passed
- `make -B -C lib -j2 lib` -- passed
- `make -C tests test-rust-lib-smoke` -- passed
- `make -B -C tests -j2 fuzzer` and `tests/fuzzer -s4560 -t56 -i57 -v` -- passed
- `make -C tests -j2 test-zstream` -- 84 named tests and 7,400 plus 8,519 randomized cases passed
- `git diff --check` and `git diff --cached --check` -- passed
This commit is contained in:
2026-07-18 10:35:09 +02:00
parent faffd99d1c
commit 027ec50b16
2 changed files with 59 additions and 4 deletions
+8 -3
View File
@@ -90,6 +90,10 @@ size_t ZSTD_rust_CStreamInSize(void);
size_t ZSTD_rust_CStreamOutSize(void);
size_t ZSTD_rust_sizeofLocalDict(int dictBufferPresent, size_t dictSize,
size_t cdictSize);
ZSTD_inBuffer ZSTD_rust_inBufferForEndFlush(int inBufferMode,
const void* expectedSrc,
size_t expectedSize,
size_t expectedPos);
/* Context-free compression-parameter selection and sizing leaves live in
* Rust (rust/src/zstd_compress_params.rs). This file retains
@@ -5615,9 +5619,10 @@ ZSTD_compressSequencesAndLiterals(ZSTD_CCtx* cctx,
static ZSTD_inBuffer inBuffer_forEndFlush(const ZSTD_CStream* zcs)
{
const ZSTD_inBuffer nullInput = { NULL, 0, 0 };
const int stableInput = (zcs->appliedParams.inBufferMode == ZSTD_bm_stable);
return stableInput ? zcs->expectedInBuffer : nullInput;
return ZSTD_rust_inBufferForEndFlush(zcs->appliedParams.inBufferMode,
zcs->expectedInBuffer.src,
zcs->expectedInBuffer.size,
zcs->expectedInBuffer.pos);
}
/*! ZSTD_flushStream() :