feat(compress): call the Rust CCtx block reset leaf directly
Pass the private CCtx compressed-block-state pointer into the Rust reset tail and invoke the existing Rust reset leaf directly. Remove the redundant C adapter while keeping reset-tail ordering and private state opaque at the ABI boundary. Strengthen reset-tail tests to verify the direct reset state. Test Plan: - ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml - 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 - ulimit -v 41943040 && cargo fmt --manifest-path rust/Cargo.toml -- --check - git diff --check
This commit is contained in:
@@ -1563,14 +1563,14 @@ typedef char ZSTD_rust_reset_cctx_workspace_state_layout[
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
ZSTD_rust_resetCCtxStorageCallback_f initialize;
|
||||
ZSTD_rust_resetCCtxStorageCallback_f resetCompressedBlockState;
|
||||
void* compressedBlockState;
|
||||
ZSTD_rust_resetCCtxTailCallback_f resetMatchState;
|
||||
ZSTD_rust_resetCCtxTailCallback_f resetStorage;
|
||||
} ZSTD_rust_resetCCtxTailState;
|
||||
typedef char ZSTD_rust_reset_cctx_tail_state_layout[
|
||||
(offsetof(ZSTD_rust_resetCCtxTailState, callbackContext) == 0
|
||||
&& offsetof(ZSTD_rust_resetCCtxTailState, initialize) == sizeof(void*)
|
||||
&& offsetof(ZSTD_rust_resetCCtxTailState, resetCompressedBlockState)
|
||||
&& offsetof(ZSTD_rust_resetCCtxTailState, compressedBlockState)
|
||||
== 2 * sizeof(void*)
|
||||
&& offsetof(ZSTD_rust_resetCCtxTailState, resetMatchState)
|
||||
== 3 * sizeof(void*)
|
||||
@@ -4248,13 +4248,6 @@ static void ZSTD_rust_resetCCtxTail_initialize(void* opaque)
|
||||
cctx->dictContentSize = 0;
|
||||
}
|
||||
|
||||
static void ZSTD_rust_resetCCtxTail_resetCompressedBlockState(void* opaque)
|
||||
{
|
||||
ZSTD_rust_resetCCtxTailContext* const context =
|
||||
(ZSTD_rust_resetCCtxTailContext*)opaque;
|
||||
ZSTD_reset_compressedBlockState(context->cctx->blockState.prevCBlock);
|
||||
}
|
||||
|
||||
static size_t ZSTD_rust_resetCCtxTail_resetMatchState(void* opaque)
|
||||
{
|
||||
ZSTD_rust_resetCCtxTailContext* const context =
|
||||
@@ -4427,8 +4420,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
|
||||
tailContext.storageState = &storageState;
|
||||
tailState.callbackContext = &tailContext;
|
||||
tailState.initialize = ZSTD_rust_resetCCtxTail_initialize;
|
||||
tailState.resetCompressedBlockState =
|
||||
ZSTD_rust_resetCCtxTail_resetCompressedBlockState;
|
||||
tailState.compressedBlockState = zc->blockState.prevCBlock;
|
||||
tailState.resetMatchState = ZSTD_rust_resetCCtxTail_resetMatchState;
|
||||
tailState.resetStorage = ZSTD_rust_resetCCtxTail_resetStorage;
|
||||
FORWARD_IF_ERROR(ZSTD_rust_resetCCtxTail(&tailState), "");
|
||||
|
||||
+27
-41
@@ -43,8 +43,8 @@ use crate::zstd_compress_stats::{
|
||||
ZSTD_rust_deriveSeqStoreChunk, ZSTD_rust_determineBlockSize, ZSTD_rust_entropyCompressSeqStore,
|
||||
ZSTD_rust_entropyCompressSeqStore_internal, ZSTD_rust_fastSequenceLengthSum,
|
||||
ZSTD_rust_finalizeOffBase, ZSTD_rust_get1BlockSummary, ZSTD_rust_isRLE, ZSTD_rust_maybeRLE,
|
||||
ZSTD_rust_postProcessSequenceProducerResult, ZSTD_rust_resetSeqStore,
|
||||
ZSTD_rust_seqStore_resolveOffCodes, ZSTD_rust_storeLastLiterals,
|
||||
ZSTD_rust_postProcessSequenceProducerResult, ZSTD_rust_resetCompressedBlockState,
|
||||
ZSTD_rust_resetSeqStore, ZSTD_rust_seqStore_resolveOffCodes, ZSTD_rust_storeLastLiterals,
|
||||
ZSTD_rust_transferSequencesNoDelim, ZSTD_rust_transferSequencesWBlockDelim,
|
||||
ZSTD_rust_validateSeqStore, ZSTD_LLT_LITERAL_LENGTH, ZSTD_LLT_MATCH_LENGTH,
|
||||
};
|
||||
@@ -6803,14 +6803,14 @@ const _: () = {
|
||||
|
||||
/// C-owned operations used by the post-workspace CCtx reset tail.
|
||||
///
|
||||
/// Rust owns the operation order and error propagation. C retains the
|
||||
/// private context initialization, compressed-block reset, match-state reset,
|
||||
/// and storage publication operations.
|
||||
/// Rust owns the operation order, compressed-block reset, and error
|
||||
/// propagation. C retains the private context initialization, match-state
|
||||
/// reset, and storage publication operations.
|
||||
#[repr(C)]
|
||||
pub struct ZSTD_rust_resetCCtxTailState {
|
||||
callbackContext: *mut c_void,
|
||||
initialize: Option<ResetCCtxStorageCallback>,
|
||||
resetCompressedBlockState: Option<ResetCCtxStorageCallback>,
|
||||
compressedBlockState: *mut ZSTD_compressedBlockState_t,
|
||||
resetMatchState: Option<ResetCCtxTailCallback>,
|
||||
resetStorage: Option<ResetCCtxTailCallback>,
|
||||
}
|
||||
@@ -6819,8 +6819,7 @@ const _: () = {
|
||||
assert!(offset_of!(ZSTD_rust_resetCCtxTailState, callbackContext) == 0);
|
||||
assert!(offset_of!(ZSTD_rust_resetCCtxTailState, initialize) == size_of::<usize>());
|
||||
assert!(
|
||||
offset_of!(ZSTD_rust_resetCCtxTailState, resetCompressedBlockState)
|
||||
== 2 * size_of::<usize>()
|
||||
offset_of!(ZSTD_rust_resetCCtxTailState, compressedBlockState) == 2 * size_of::<usize>()
|
||||
);
|
||||
assert!(offset_of!(ZSTD_rust_resetCCtxTailState, resetMatchState) == 3 * size_of::<usize>());
|
||||
assert!(
|
||||
@@ -7126,19 +7125,19 @@ pub unsafe extern "C" fn ZSTD_rust_resetCCtxTail(
|
||||
let Some(initialize) = state.initialize else {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
};
|
||||
let Some(reset_compressed_block_state) = state.resetCompressedBlockState else {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
};
|
||||
let Some(reset_match_state) = state.resetMatchState else {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
};
|
||||
let Some(reset_storage) = state.resetStorage else {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
};
|
||||
if state.compressedBlockState.is_null() {
|
||||
return ERROR(ZstdErrorCode::Generic);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
initialize(state.callbackContext);
|
||||
reset_compressed_block_state(state.callbackContext);
|
||||
ZSTD_rust_resetCompressedBlockState(state.compressedBlockState);
|
||||
let result = reset_match_state(state.callbackContext);
|
||||
if ERR_isError(result) {
|
||||
return result;
|
||||
@@ -16740,11 +16739,6 @@ mod tests {
|
||||
context.events.push("initialize");
|
||||
}
|
||||
|
||||
unsafe extern "C" fn reset_cctx_tail_test_reset_compressed_block_state(context: *mut c_void) {
|
||||
let context = unsafe { reset_cctx_tail_test_context(context) };
|
||||
context.events.push("reset-compressed-block-state");
|
||||
}
|
||||
|
||||
unsafe extern "C" fn reset_cctx_tail_test_reset_match_state(context: *mut c_void) -> usize {
|
||||
let context = unsafe { reset_cctx_tail_test_context(context) };
|
||||
context.events.push("reset-match-state");
|
||||
@@ -16759,11 +16753,12 @@ mod tests {
|
||||
|
||||
fn reset_cctx_tail_test_state(
|
||||
context: &mut ResetCCtxTailTestContext,
|
||||
compressed_block_state: *mut ZSTD_compressedBlockState_t,
|
||||
) -> ZSTD_rust_resetCCtxTailState {
|
||||
ZSTD_rust_resetCCtxTailState {
|
||||
callbackContext: (context as *mut ResetCCtxTailTestContext).cast(),
|
||||
initialize: Some(reset_cctx_tail_test_initialize),
|
||||
resetCompressedBlockState: Some(reset_cctx_tail_test_reset_compressed_block_state),
|
||||
compressedBlockState: compressed_block_state,
|
||||
resetMatchState: Some(reset_cctx_tail_test_reset_match_state),
|
||||
resetStorage: Some(reset_cctx_tail_test_reset_storage),
|
||||
}
|
||||
@@ -16772,18 +16767,17 @@ mod tests {
|
||||
#[test]
|
||||
fn cctx_reset_tail_preserves_post_workspace_callback_order() {
|
||||
let mut context = ResetCCtxTailTestContext::default();
|
||||
let state = reset_cctx_tail_test_state(&mut context);
|
||||
let mut block_state =
|
||||
unsafe { MaybeUninit::<ZSTD_compressedBlockState_t>::zeroed().assume_init() };
|
||||
let state = reset_cctx_tail_test_state(&mut context, &mut block_state);
|
||||
|
||||
assert_eq!(unsafe { ZSTD_rust_resetCCtxTail(&state) }, 0);
|
||||
assert_eq!(
|
||||
context.events,
|
||||
[
|
||||
"initialize",
|
||||
"reset-compressed-block-state",
|
||||
"reset-match-state",
|
||||
"reset-storage",
|
||||
]
|
||||
["initialize", "reset-match-state", "reset-storage"]
|
||||
);
|
||||
assert_eq!(block_state.rep, [1, 4, 8]);
|
||||
assert_eq!(block_state.entropy.huf.repeatMode, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -16792,20 +16786,15 @@ mod tests {
|
||||
match_result: ERROR(ZstdErrorCode::StageWrong),
|
||||
..ResetCCtxTailTestContext::default()
|
||||
};
|
||||
let state = reset_cctx_tail_test_state(&mut context);
|
||||
let mut block_state =
|
||||
unsafe { MaybeUninit::<ZSTD_compressedBlockState_t>::zeroed().assume_init() };
|
||||
let state = reset_cctx_tail_test_state(&mut context, &mut block_state);
|
||||
|
||||
assert_eq!(
|
||||
unsafe { ZSTD_rust_resetCCtxTail(&state) },
|
||||
ERROR(ZstdErrorCode::StageWrong)
|
||||
);
|
||||
assert_eq!(
|
||||
context.events,
|
||||
[
|
||||
"initialize",
|
||||
"reset-compressed-block-state",
|
||||
"reset-match-state"
|
||||
]
|
||||
);
|
||||
assert_eq!(context.events, ["initialize", "reset-match-state"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -16814,7 +16803,9 @@ mod tests {
|
||||
storage_result: ERROR(ZstdErrorCode::MemoryAllocation),
|
||||
..ResetCCtxTailTestContext::default()
|
||||
};
|
||||
let state = reset_cctx_tail_test_state(&mut context);
|
||||
let mut block_state =
|
||||
unsafe { MaybeUninit::<ZSTD_compressedBlockState_t>::zeroed().assume_init() };
|
||||
let state = reset_cctx_tail_test_state(&mut context, &mut block_state);
|
||||
|
||||
assert_eq!(
|
||||
unsafe { ZSTD_rust_resetCCtxTail(&state) },
|
||||
@@ -16822,12 +16813,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
context.events,
|
||||
[
|
||||
"initialize",
|
||||
"reset-compressed-block-state",
|
||||
"reset-match-state",
|
||||
"reset-storage",
|
||||
]
|
||||
["initialize", "reset-match-state", "reset-storage"]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user