feat(compress): route target blocks through Rust
Project the target-sized block state into frame-chunk compression and invoke Rust sequence-store construction followed by the existing target-block post-build leaf. Refresh the per-block isFirstBlock snapshot to preserve the former C adapter's behavior while leaving the split-block branch on its existing callback path for a later seam. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo fmt --manifest-path rust/Cargo.toml --all -- --check - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --lib 'zstd_compress::tests::frame_chunk' -- --nocapture - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --lib - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; make -j1 - ulimit -v 41943040; make -j1 -C tests test-zstream ZSTREAM_TESTTIME=-T2s - ulimit -v 41943040; make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
This commit is contained in:
+54
-10
@@ -586,6 +586,7 @@ pub struct ZSTD_rust_frameChunkState {
|
||||
compress_split: FrameChunkCompressFn,
|
||||
compress_internal: Option<FrameChunkCompressFn>,
|
||||
compress_internal_state: *const ZSTD_rust_compressContinueBlockState,
|
||||
compress_target_state: *const ZSTD_rust_targetCBlockSizeState,
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
@@ -630,9 +631,13 @@ const _: () = {
|
||||
== 11 * size_of::<usize>() + size_of::<c_longlong>() + 6 * size_of::<c_int>()
|
||||
);
|
||||
assert!(
|
||||
size_of::<ZSTD_rust_frameChunkState>()
|
||||
offset_of!(ZSTD_rust_frameChunkState, compress_target_state)
|
||||
== 12 * size_of::<usize>() + size_of::<c_longlong>() + 6 * size_of::<c_int>()
|
||||
);
|
||||
assert!(
|
||||
size_of::<ZSTD_rust_frameChunkState>()
|
||||
== 13 * size_of::<usize>() + size_of::<c_longlong>() + 6 * size_of::<c_int>()
|
||||
);
|
||||
};
|
||||
|
||||
/// Rust implementation of `ZSTD_compress_frameChunk`.
|
||||
@@ -722,15 +727,49 @@ unsafe fn compress_frame_chunk_body_with(
|
||||
unsafe { prepare_frame_chunk_block(&*state.prepare_state, ip.cast(), block_size) };
|
||||
|
||||
let c_size = if state.use_target_c_block_size != 0 {
|
||||
unsafe {
|
||||
(state.compress_target)(
|
||||
state.callback_context,
|
||||
op.cast(),
|
||||
remaining_capacity,
|
||||
ip.cast(),
|
||||
block_size,
|
||||
last_block,
|
||||
)
|
||||
if !state.compress_target_state.is_null() {
|
||||
let block_state = if state.compress_internal_state.is_null() {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
} else {
|
||||
unsafe { &*state.compress_internal_state }
|
||||
};
|
||||
if block_state.build_seq_store_state.is_null() {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
}
|
||||
let bss = unsafe {
|
||||
ZSTD_rust_buildSeqStore(
|
||||
block_state.build_seq_store_state,
|
||||
ip.cast(),
|
||||
block_size,
|
||||
)
|
||||
};
|
||||
if ERR_isError(bss) {
|
||||
return bss;
|
||||
}
|
||||
let mut target_state = unsafe { ptr::read(state.compress_target_state) };
|
||||
target_state.is_first_block = unsafe { *state.is_first_block };
|
||||
unsafe {
|
||||
ZSTD_rust_compressBlockTargetCBlockSizeAfterBuild(
|
||||
&target_state,
|
||||
op.cast(),
|
||||
remaining_capacity,
|
||||
ip.cast(),
|
||||
block_size,
|
||||
bss as c_int,
|
||||
last_block,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
unsafe {
|
||||
(state.compress_target)(
|
||||
state.callback_context,
|
||||
op.cast(),
|
||||
remaining_capacity,
|
||||
ip.cast(),
|
||||
block_size,
|
||||
last_block,
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if state.block_splitter_enabled != 0 {
|
||||
unsafe {
|
||||
@@ -10413,6 +10452,7 @@ mod tests {
|
||||
compress_split: compress_end_test_frame_target,
|
||||
compress_internal: Some(compress_end_test_frame_target),
|
||||
compress_internal_state: ptr::null(),
|
||||
compress_target_state: ptr::null(),
|
||||
});
|
||||
let frame_chunk_state = context
|
||||
.frame_chunk_state
|
||||
@@ -11289,6 +11329,7 @@ mod tests {
|
||||
compress_split: frame_chunk_test_split,
|
||||
compress_internal: Some(frame_chunk_test_internal),
|
||||
compress_internal_state: ptr::null(),
|
||||
compress_target_state: ptr::null(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11629,6 +11670,7 @@ mod tests {
|
||||
compress_split: compress_continue_test_frame,
|
||||
compress_internal: Some(compress_continue_test_frame),
|
||||
compress_internal_state: ptr::null(),
|
||||
compress_target_state: ptr::null(),
|
||||
});
|
||||
let frame_chunk_state = context
|
||||
.frame_chunk_state
|
||||
@@ -12115,6 +12157,7 @@ mod tests {
|
||||
compress_split: compress_stream_test_block,
|
||||
compress_internal: Some(compress_stream_test_block),
|
||||
compress_internal_state: ptr::null(),
|
||||
compress_target_state: ptr::null(),
|
||||
});
|
||||
let continue_frame_chunk_state = context
|
||||
.continue_frame_chunk_state
|
||||
@@ -12140,6 +12183,7 @@ mod tests {
|
||||
compress_split: compress_stream_test_end,
|
||||
compress_internal: Some(compress_stream_test_end),
|
||||
compress_internal_state: ptr::null(),
|
||||
compress_target_state: ptr::null(),
|
||||
});
|
||||
let end_frame_chunk_state = context
|
||||
.end_frame_chunk_state
|
||||
|
||||
Reference in New Issue
Block a user