feat(compress): move MT buffer pool size addition to Rust
Keep buffer-pool ownership, allocation, synchronization, and the Rust pool's saturating accounting in their existing implementations. The C wrapper still handles NULL, obtains sizeof(*bufPool), and queries the Rust pool size; Rust now performs only the final size_t addition with wrapping semantics. The sequence-pool sizing alias continues to call the same C helper and therefore retains its behavior. Test Plan: - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` (before and after formatting) -- passed - The same clippy command with `--benches` and `--tests` -- passed - `cargo +nightly fmt --manifest-path rust/Cargo.toml` -- passed - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression zstdmt_compress` -- 29 passed - `make -B -C lib -j2 lib` -- passed - `make -C tests test-rust-lib-smoke` -- passed - `tests/fuzzer -s4560 -t56 -i57 -v` -- 57 passed - `make -C tests -j2 test-zstream` -- 84 named, 7,661, and 8,090 randomized tests passed - `git diff --check` and `git diff --cached --check` -- passed The zstream build still emits the pre-existing unterminated-string warning at tests/zstreamtest.c:1899.
This commit is contained in:
@@ -686,6 +686,16 @@ pub unsafe extern "C" fn ZSTDMT_rust_buffer_pool_sizeof(pool: *const RustBufferP
|
||||
.saturating_add(total_buffer_size)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sizeof_buffer_pool(wrapper_size: usize, rust_pool_size: usize) -> usize {
|
||||
wrapper_size.wrapping_add(rust_pool_size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTDMT_rust_sizeofBufferPool(wrapperSize: usize, rustPoolSize: usize) -> usize {
|
||||
sizeof_buffer_pool(wrapperSize, rustPoolSize)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ZSTDMT_rust_buffer_pool_set_size(
|
||||
pool: *mut RustBufferPool,
|
||||
@@ -1608,4 +1618,22 @@ mod tests {
|
||||
assert_eq!(sizeof_cctx_pool(usize::MAX, 1), 0);
|
||||
assert_eq!(sizeof_cctx_pool(usize::MAX - 7, 11), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffer_pool_size_addition_handles_zero_components() {
|
||||
assert_eq!(sizeof_buffer_pool(0, 0), 0);
|
||||
assert_eq!(sizeof_buffer_pool(37, 0), 37);
|
||||
assert_eq!(sizeof_buffer_pool(0, 53), 53);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffer_pool_size_addition_preserves_ordinary_sum() {
|
||||
assert_eq!(sizeof_buffer_pool(128, 4096), 4224);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffer_pool_size_addition_wraps_like_c_size_t() {
|
||||
assert_eq!(sizeof_buffer_pool(usize::MAX, 1), 0);
|
||||
assert_eq!(sizeof_buffer_pool(usize::MAX - 7, 11), 3);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user