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:
@@ -939,6 +939,16 @@ pub unsafe extern "C" fn ZSTDMT_rust_cctx_pool_sizeof(pool: *const RustCCtxPool)
|
||||
.saturating_add(total_cctx_size)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sizeof_cctx_pool(wrapper_size: usize, rust_pool_size: usize) -> usize {
|
||||
wrapper_size.wrapping_add(rust_pool_size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTDMT_rust_sizeofCCtxPool(wrapperSize: usize, rustPoolSize: usize) -> usize {
|
||||
sizeof_cctx_pool(wrapperSize, rustPoolSize)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ZSTDMT_rust_cctx_pool_expand(
|
||||
pool: *mut RustCCtxPool,
|
||||
@@ -1580,4 +1590,22 @@ mod tests {
|
||||
1usize << 25
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cctx_pool_size_addition_handles_zero_components() {
|
||||
assert_eq!(sizeof_cctx_pool(0, 0), 0);
|
||||
assert_eq!(sizeof_cctx_pool(37, 0), 37);
|
||||
assert_eq!(sizeof_cctx_pool(0, 53), 53);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cctx_pool_size_addition_preserves_ordinary_sum() {
|
||||
assert_eq!(sizeof_cctx_pool(128, 4096), 4224);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cctx_pool_size_addition_wraps_like_c_size_t() {
|
||||
assert_eq!(sizeof_cctx_pool(usize::MAX, 1), 0);
|
||||
assert_eq!(sizeof_cctx_pool(usize::MAX - 7, 11), 3);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user