feat(compress): port simple context compression to Rust

Move ZSTD_compressCCtx() onto the Rust frame-compression path while
retaining only the C-owned reset needed for its private context layout.
The simple API ignores advanced context parameters by contract, so the
Rust entry point can share the one-shot implementation after reset.

Preserve valid frames when the Rust superblock leaf declines a compressed
block by emitting a raw block instead. Match the fast-strategy literal
policy for negative levels so compatibility behavior remains intact.

Streaming, stateful ZSTD_compress2(), and multithreaded context
orchestration remain C-owned for a later slice. The full fuzzer currently
reaches an existing compress2() superblock-expansion failure after these
simple-API checks; that stateful path is intentionally out of scope here.

Test Plan:
- cargo test --manifest-path rust/Cargo.toml --no-default-features
  --features compression zstd_compress::tests
- cargo clippy --manifest-path rust/Cargo.toml -- -D warnings
  (library, benches, and tests)
- cargo +nightly fmt --manifest-path rust/Cargo.toml -- --check
- make -B -C programs zstd V=1
- make -B -C examples multiple_simple_compression
- ./multiple_simple_compression README.md ../rust/README.md
This commit is contained in:
2026-07-12 18:48:44 +02:00
parent 6711aef1d4
commit e66ad5f563
2 changed files with 122 additions and 11 deletions
+7 -7
View File
@@ -37,6 +37,7 @@ size_t ZSTD_rust_writeFrameHeader(void* dst, size_t dstCapacity,
int contentSizeFlag, int format,
U32 windowLog, U64 pledgedSrcSize,
U32 dictID);
size_t ZSTD_rust_resetCCtxForSimpleCompression(void* cctx);
/* Context-free compression-parameter selection and sizing leaves live in
* Rust (rust/src/zstd_compress_params.rs). This file retains
@@ -4462,14 +4463,13 @@ size_t ZSTD_compress_usingDict(ZSTD_CCtx* cctx,
return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, dict, dictSize, &cctx->simpleApiParams);
}
size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize,
int compressionLevel)
/* ZSTD_compressCCtx() is implemented by rust/src/zstd_compress.rs. */
/* The Rust simple API still needs the C-owned context reset, but does not
* cross the private context layout. */
size_t ZSTD_rust_resetCCtxForSimpleCompression(void* cctx)
{
DEBUGLOG(4, "ZSTD_compressCCtx (srcSize=%u)", (unsigned)srcSize);
assert(cctx != NULL);
return ZSTD_compress_usingDict(cctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel);
return ZSTD_CCtx_reset((ZSTD_CCtx*)cctx, ZSTD_reset_session_and_parameters);
}
/* ZSTD_compress() is implemented by rust/src/zstd_compress.rs. */