feat(compress): move repcode invalidation to Rust
Keep ZSTD_invalidateRepCodes responsible for extracting the private previous block state and checking that the match window has no external dictionary. Delegate only the fixed three-entry repcode reset through a narrow pointer ABI, with a C assertion preserving the Rust side's ZSTD_REP_NUM assumption. Test Plan: - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression zstd_compress::tests::invalidate_rep_codes_clears_all_entries` -- passed - `make -B -C lib -j2 lib` -- passed - `make -C tests -j2 fuzzer` and `./tests/fuzzer -s4560 -t47 -i48 -v` -- passed - Required clippy, nightly fmt, and diff checks -- passed
This commit is contained in:
@@ -72,6 +72,7 @@ unsafe extern "C" {
|
||||
|
||||
const ZSTD_FAST: c_int = 1;
|
||||
const ZSTD_DFAST: c_int = 2;
|
||||
const ZSTD_REP_NUM: usize = 3;
|
||||
#[cfg(test)]
|
||||
const ZSTD_BM_BUFFERED: c_int = 0;
|
||||
const ZSTD_BM_STABLE: c_int = 1;
|
||||
@@ -365,6 +366,14 @@ pub unsafe extern "C" fn ZSTD_rust_copyCDictTableIntoCCtx(
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear the previous block's repcodes before the next regular compression.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ZSTD_rust_invalidateRepCodes(rep: *mut u32) {
|
||||
debug_assert!(!rep.is_null());
|
||||
let rep = unsafe { std::slice::from_raw_parts_mut(rep, ZSTD_REP_NUM) };
|
||||
rep.fill(0);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn zeroed_state() -> ZSTD_compressedBlockState_t {
|
||||
/* The state contains only integer arrays and enum fields. */
|
||||
@@ -1118,6 +1127,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalidate_rep_codes_clears_all_entries() {
|
||||
let mut rep = [11u32, 22, 33];
|
||||
|
||||
unsafe { ZSTD_rust_invalidateRepCodes(rep.as_mut_ptr()) };
|
||||
|
||||
assert_eq!(rep, [0; ZSTD_REP_NUM]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_one_shot_abi_is_c_compatible() {
|
||||
let entry: unsafe extern "C" fn(*mut c_void, usize, *const c_void, usize, c_int) -> usize =
|
||||
|
||||
Reference in New Issue
Block a user