feat(compress): move CCtx size aggregation to Rust
Keep ZSTD_sizeof_CCtx's NULL handling, workspace accounting, local-dictionary sizing, and multithreaded context sizing in C, where the private layouts and ownership remain visible. Pass only the four resulting size_t values to a Rust ABI helper, which performs the final ordered additions with C-compatible wrapping semantics. Add focused coverage for zero, ordinary, and overflowing component sums. Test Plan: - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` -- passed before and after formatting - 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 sizeof_cctx` -- passed (6 tests) - `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, 6252 and 9519 randomized) - `git diff --check` and `git diff --cached --check` -- passed
This commit is contained in:
@@ -90,6 +90,8 @@ 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);
|
||||
size_t ZSTD_rust_sizeofCCtx(size_t objectSize, size_t workspaceSize,
|
||||
size_t localDictSize, size_t mtctxSize);
|
||||
ZSTD_inBuffer ZSTD_rust_inBufferForEndFlush(int inBufferMode,
|
||||
const void* expectedSrc,
|
||||
size_t expectedSize,
|
||||
@@ -582,11 +584,15 @@ static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx)
|
||||
size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx)
|
||||
{
|
||||
if (cctx==NULL) return 0; /* support sizeof on NULL */
|
||||
/* cctx may be in the workspace */
|
||||
return (cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx))
|
||||
+ ZSTD_cwksp_sizeof(&cctx->workspace)
|
||||
+ ZSTD_sizeof_localDict(cctx->localDict)
|
||||
+ ZSTD_sizeof_mtctx(cctx);
|
||||
{
|
||||
/* cctx may be in the workspace */
|
||||
size_t const objectSize = cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx);
|
||||
size_t const workspaceSize = ZSTD_cwksp_sizeof(&cctx->workspace);
|
||||
size_t const localDictSize = ZSTD_sizeof_localDict(cctx->localDict);
|
||||
size_t const mtctxSize = ZSTD_sizeof_mtctx(cctx);
|
||||
return ZSTD_rust_sizeofCCtx(objectSize, workspaceSize, localDictSize,
|
||||
mtctxSize);
|
||||
}
|
||||
}
|
||||
|
||||
size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs)
|
||||
|
||||
Reference in New Issue
Block a user