refactor(mt): move serial reset error policy to Rust
Project the private serial-state reset result into Rust for the stream-initialization error decision while retaining C-owned allocation, serial-state mutation, dictionary setup, synchronization, callback order, and ABI layouts. Nonzero callback status preserves the existing memory_allocation error path. Test Plan: ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings; cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings; cargo test --manifest-path rust/cli/Cargo.toml --all-targets (188 passed); cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check; make -j1; ./tests/rustLibSmoke; make -j1 -C tests test (all shell tests, large streaming tests, native tester, fuzzer phases, and zstream tester passed).
This commit is contained in:
@@ -2136,6 +2136,23 @@ fn normalize_mt_job_size(job_size: usize, job_size_min: usize, job_size_max: usi
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn init_serial_reset_result(status: c_int) -> usize {
|
||||
if status != 0 {
|
||||
ERROR(ZstdErrorCode::MemoryAllocation)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
/// Map the private C serial-reset result to the MT stream-initialization ABI
|
||||
/// error. C retains serial-state allocation and mutation; Rust owns only this
|
||||
/// scalar error policy.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTDMT_rust_initSerialResetResult(status: c_int) -> usize {
|
||||
init_serial_reset_result(status)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn init_round_buffer_capacity(
|
||||
projection: ZSTDMT_initCStreamProjection,
|
||||
@@ -6590,6 +6607,18 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn init_serial_reset_result_maps_nonzero_status_to_memory_error() {
|
||||
let expected_error = ERROR(ZstdErrorCode::MemoryAllocation);
|
||||
|
||||
assert_eq!(init_serial_reset_result(0), 0);
|
||||
assert_eq!(ZSTDMT_rust_initSerialResetResult(0), 0);
|
||||
for status in [1, -1, 2] {
|
||||
assert_eq!(init_serial_reset_result(status), expected_error);
|
||||
assert_eq!(ZSTDMT_rust_initSerialResetResult(status), expected_error);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn init_c_stream_preserves_success_order_and_normalization() {
|
||||
let projection = init_projection();
|
||||
|
||||
Reference in New Issue
Block a user