feat(compress): move match-state invalidation leaf into Rust
Route match-state invalidation through a Rust leaf. C still computes the private window pointer difference and passes the opaque dictionary-state pointer, while Rust preserves the window-limit, next-index, dictionary, optimal-parser, and dictionary-match-state reset order. Add a focused test for all invalidated fields and use the concrete C pointer type at the ABI boundary to avoid strict-aliasing warnings. Test Plan: - cargo fmt --manifest-path rust/Cargo.toml -- --check - ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml zstd_compress::tests::invalidate_match_state -- --nocapture - ulimit -v 41943040 && make -j1 - ulimit -v 41943040 && make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
This commit is contained in:
@@ -6916,6 +6916,34 @@ pub unsafe extern "C" fn ZSTD_rust_windowClear(
|
||||
}
|
||||
}
|
||||
|
||||
/// Invalidate a C-owned match-state projection after the caller computes the
|
||||
/// private window pointer difference. Rust owns the paired window-limit and
|
||||
/// match-state field updates while C retains the match-state layout.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ZSTD_rust_invalidateMatchState(
|
||||
end_t: usize,
|
||||
low_limit: *mut u32,
|
||||
dict_limit: *mut u32,
|
||||
next_to_update: *mut u32,
|
||||
loaded_dict_end: *mut u32,
|
||||
lit_length_sum: *mut u32,
|
||||
dict_match_state: *mut *const c_void,
|
||||
) {
|
||||
debug_assert!(!low_limit.is_null());
|
||||
debug_assert!(!dict_limit.is_null());
|
||||
debug_assert!(!next_to_update.is_null());
|
||||
debug_assert!(!loaded_dict_end.is_null());
|
||||
debug_assert!(!lit_length_sum.is_null());
|
||||
debug_assert!(!dict_match_state.is_null());
|
||||
unsafe {
|
||||
ZSTD_rust_windowClear(end_t, low_limit, dict_limit);
|
||||
*next_to_update = *dict_limit;
|
||||
*loaded_dict_end = 0;
|
||||
*lit_length_sum = 0;
|
||||
*dict_match_state = ptr::null();
|
||||
}
|
||||
}
|
||||
|
||||
const HASH_READ_SIZE: u32 = 8;
|
||||
|
||||
/// Private C window fields projected for the shared window-update policy.
|
||||
@@ -12808,6 +12836,36 @@ mod tests {
|
||||
assert_eq!(dict_limit, 0x89ab_cdef);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalidate_match_state_clears_window_and_private_fields() {
|
||||
let mut low_limit = 11u32;
|
||||
let mut dict_limit = 22u32;
|
||||
let mut next_to_update = 33u32;
|
||||
let mut loaded_dict_end = 44u32;
|
||||
let mut lit_length_sum = 55u32;
|
||||
let marker = 0x5au8;
|
||||
let mut dict_match_state = (&marker as *const u8).cast::<c_void>();
|
||||
|
||||
unsafe {
|
||||
ZSTD_rust_invalidateMatchState(
|
||||
0x1234_5678,
|
||||
&mut low_limit,
|
||||
&mut dict_limit,
|
||||
&mut next_to_update,
|
||||
&mut loaded_dict_end,
|
||||
&mut lit_length_sum,
|
||||
&mut dict_match_state,
|
||||
)
|
||||
};
|
||||
|
||||
assert_eq!(low_limit, 0x1234_5678);
|
||||
assert_eq!(dict_limit, 0x1234_5678);
|
||||
assert_eq!(next_to_update, 0x1234_5678);
|
||||
assert_eq!(loaded_dict_end, 0);
|
||||
assert_eq!(lit_length_sum, 0);
|
||||
assert!(dict_match_state.is_null());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn window_update_leaves_empty_input_untouched() {
|
||||
let mut state = ZSTD_rust_windowUpdateState {
|
||||
|
||||
Reference in New Issue
Block a user