From ca9e3837714675db4013f28938b4a297d1004d1f Mon Sep 17 00:00:00 2001 From: ddidderr Date: Mon, 20 Jul 2026 13:00:39 +0200 Subject: [PATCH] refactor(compress): expose compressed block reset from Rust The compressed-block reset logic was already implemented in Rust, but the Rust export used a private bridge name and C retained a forwarding wrapper under the original ABI name. Export the original `ZSTD_reset_compressedBlockState` symbol directly from Rust, keep the `ZSTD_rust_resetCompressedBlockState` crate-local alias for existing Rust callers, and remove only the redundant C declaration and body. Private context-layout code and other C functions remain unchanged. Test Plan: - `git diff --check` -- passed. - `cc -std=c99 -Ilib -Ilib/common -Ilib/compress -Ilib/decompress -Ilib/dict -fsyntax-only lib/compress/zstd_compress.c` -- passed. - `cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` -- passed. - Cargo build/test and make were intentionally not run per the requested lightweight-only scope. --- lib/compress/zstd_compress.c | 6 ------ rust/src/zstd_compress_stats.rs | 6 ++++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index ec9fd6a44..a64b4d9bb 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2125,7 +2125,6 @@ size_t ZSTD_rust_buildBlockEntropyStats( int strategy, int disableLiteralCompression, ZSTD_entropyCTablesMetadata_t* entropyMetadata, void* workspace, size_t wkspSize); -void ZSTD_rust_resetCompressedBlockState(ZSTD_compressedBlockState_t* bs); void ZSTD_rust_invalidateRepCodes(U32 rep[ZSTD_REP_NUM]); void ZSTD_rust_invalidateMatchState( size_t endT, U32* lowLimit, U32* dictLimit, @@ -4163,11 +4162,6 @@ size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx) return ZSTD_rust_toFlushNow(&state); } -void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs) -{ - ZSTD_rust_resetCompressedBlockState(bs); -} - /** * Controls, for this matchState reset, whether the tables need to be cleared / * prepared for the coming compression (ZSTDcrp_makeClean), or whether the diff --git a/rust/src/zstd_compress_stats.rs b/rust/src/zstd_compress_stats.rs index c75bd2036..209a9900f 100644 --- a/rust/src/zstd_compress_stats.rs +++ b/rust/src/zstd_compress_stats.rs @@ -1089,7 +1089,7 @@ pub unsafe extern "C" fn ZSTD_rust_postProcessSequenceProducerResult( /// `ZSTD_reset_compressedBlockState()`. The caller must provide a valid /// mutable compressed block state. #[no_mangle] -pub unsafe extern "C" fn ZSTD_rust_resetCompressedBlockState( +pub unsafe extern "C" fn ZSTD_reset_compressedBlockState( block_state: *mut ZSTD_compressedBlockState_t, ) { let block_state = unsafe { &mut *block_state }; @@ -1100,6 +1100,8 @@ pub unsafe extern "C" fn ZSTD_rust_resetCompressedBlockState( block_state.entropy.fse.litlength_repeatMode = FSE_REPEAT_NONE; } +pub(crate) use ZSTD_reset_compressedBlockState as ZSTD_rust_resetCompressedBlockState; + /// Swaps the two C-owned block-state pointers after a block is confirmed. /// /// The enclosing `ZSTD_blockState_t` contains C-only match-state storage, so @@ -3287,7 +3289,7 @@ mod tests { block_state.entropy.fse.matchlength_repeatMode = 1; block_state.entropy.fse.litlength_repeatMode = 2; - unsafe { ZSTD_rust_resetCompressedBlockState(&mut block_state) }; + unsafe { ZSTD_reset_compressedBlockState(&mut block_state) }; assert_eq!(block_state.rep, [1, 4, 8]); assert_eq!(block_state.entropy.huf.repeatMode, HUF_REPEAT_NONE);