feat(compress): move MT CCtx pool size addition to Rust

Keep ZSTDMT_sizeof_CCtxPool's NULL handling, wrapper sizeof, and Rust pool
size query in C while delegating only the final size_t aggregation to a
Rust ABI helper. The helper uses wrapping_add so its result matches C's
unsigned size_t arithmetic without changing the pool's existing saturating
internal accounting, layout, synchronization, or allocation paths.

Test Plan:
- `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression zstdmt_compress` -- passed (26 tests)
- Required clippy sequence before and after `cargo +nightly fmt` -- passed
- `make -B -C lib -j2 lib` -- passed
- `make -C tests test-rust-lib-smoke` -- passed
- `tests/fuzzer -s4560 -t56 -i57 -v` -- passed (57 tests)
- `make -C tests -j2 test-zstream` -- passed (84 named, 6,871 and 9,464 randomized tests)
- `git diff --check` and `git diff --cached --check` -- passed
- Existing warning at `tests/zstreamtest.c:1899` remains unchanged
This commit is contained in:
2026-07-18 11:59:34 +02:00
parent 6d4917e187
commit 56c4ed7bab
2 changed files with 32 additions and 1 deletions
+4 -1
View File
@@ -344,6 +344,7 @@ ZSTDMT_RustCCtxPool* ZSTDMT_rust_cctx_pool_create(unsigned nbWorkers,
ZSTD_customMem cMem);
void ZSTDMT_rust_cctx_pool_free(ZSTDMT_RustCCtxPool* pool);
size_t ZSTDMT_rust_cctx_pool_sizeof(const ZSTDMT_RustCCtxPool* pool);
size_t ZSTDMT_rust_sizeofCCtxPool(size_t wrapperSize, size_t rustPoolSize);
ZSTDMT_RustCCtxPool* ZSTDMT_rust_cctx_pool_expand(ZSTDMT_RustCCtxPool* pool,
unsigned nbWorkers);
ZSTD_CCtx* ZSTDMT_rust_cctx_pool_get(ZSTDMT_RustCCtxPool* pool);
@@ -401,8 +402,10 @@ static ZSTDMT_CCtxPool* ZSTDMT_expandCCtxPool(ZSTDMT_CCtxPool* srcPool,
/* only works during initialization phase, not during compression */
static size_t ZSTDMT_sizeof_CCtxPool(ZSTDMT_CCtxPool* cctxPool)
{
size_t rustPoolSize;
if (cctxPool == NULL) return 0;
return sizeof(*cctxPool) + ZSTDMT_rust_cctx_pool_sizeof(cctxPool->rustPool);
rustPoolSize = ZSTDMT_rust_cctx_pool_sizeof(cctxPool->rustPool);
return ZSTDMT_rust_sizeofCCtxPool(sizeof(*cctxPool), rustPoolSize);
}
static ZSTD_CCtx* ZSTDMT_getCCtx(ZSTDMT_CCtxPool* cctxPool)