From 66a163a78c742bf1e8aeca8642ef3590eef3b073 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Mon, 20 Jul 2026 13:15:57 +0200 Subject: [PATCH] refactor(compress): expose dictionary entropy leaf from Rust The dictionary entropy-header loader was already implemented in Rust, but C kept a private bridge declaration and retained `ZSTD_loadCEntropy` as a forwarding wrapper. Export the original ABI name from Rust and retain a crate-local `ZSTD_rust_loadCEntropy` alias for existing Rust callers. Remove only the bridge declaration and forwarding body; dictionary-content orchestration, callbacks, and private C layouts remain unchanged. Test Plan: - `cc -std=c99 -Ilib -Ilib/common -Ilib/compress -Ilib/decompress -Ilib/dict -fsyntax-only lib/compress/zstd_compress.c` -- passed. - `git diff --check` -- passed. - `cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` -- passed. - `git diff --cached --check` -- passed. - Cargo build/test, make, and other heavy checks were intentionally not run per the requested lightweight-only scope. --- lib/compress/zstd_compress.c | 10 ---------- rust/src/zstd_compress_dictionary.rs | 7 ++++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index a64b4d9bb..b17de4cb0 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2139,8 +2139,6 @@ void ZSTD_rust_storeLastLiterals(SeqStore_t* seqStorePtr, void ZSTD_rust_validateSeqStore(const SeqStore_t* seqStore, U32 minMatch); U32 ZSTD_rust_resolveRepcodeToRawOffset(const U32 rep[ZSTD_REP_NUM], U32 offBase, U32 ll0); -size_t ZSTD_rust_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace, - const void* dict, size_t dictSize); /* Rust owns dictionary-content orchestration and policy. The callbacks below * keep configuration-sensitive match-state, LDM, workspace, and matchfinder * operations private to C. */ @@ -6231,14 +6229,6 @@ static void ZSTD_loadDictionaryContent_assertInvalidStrategy(void* opaque) } -/* Dictionary entropy-header loading and content orchestration live in Rust; - * this keeps the original internal symbol available to C callers. */ -size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace, - const void* const dict, size_t dictSize) -{ - return ZSTD_rust_loadCEntropy(bs, workspace, dict, dictSize); -} - /* Package only scalar policy inputs and opaque private-operation callbacks for * the Rust dictionary-content orchestrator. */ static size_t ZSTD_loadDictionaryContent_callback( diff --git a/rust/src/zstd_compress_dictionary.rs b/rust/src/zstd_compress_dictionary.rs index fec8140cc..a5af0630c 100644 --- a/rust/src/zstd_compress_dictionary.rs +++ b/rust/src/zstd_compress_dictionary.rs @@ -5,8 +5,7 @@ //! Dictionary entropy-header loading. //! //! This is the Rust leaf for `ZSTD_dictNCountRepeat()` and -//! `ZSTD_loadCEntropy()` in `lib/compress/zstd_compress.c`. C retains the -//! original symbols through thin compatibility shims and keeps the +//! `ZSTD_loadCEntropy()` in `lib/compress/zstd_compress.c`. C keeps the //! configuration-sensitive dictionary-content operations on its side. use crate::bits::ZSTD_highbit32; @@ -2256,7 +2255,7 @@ unsafe fn read_and_build_fse_table( /// truncated entropy headers are converted to `ZSTD_error_dictionaryCorrupted` /// just as the C `RETURN_ERROR_IF(..., dictionary_corrupted, ...)` paths do. #[no_mangle] -pub unsafe extern "C" fn ZSTD_rust_loadCEntropy( +pub unsafe extern "C" fn ZSTD_loadCEntropy( bs: *mut ZSTD_compressedBlockState_t, workspace: *mut c_void, dict: *const c_void, @@ -2401,6 +2400,8 @@ pub unsafe extern "C" fn ZSTD_rust_loadCEntropy( offset } +pub(crate) use ZSTD_loadCEntropy as ZSTD_rust_loadCEntropy; + /// Rust-owned dispatch for C's `ZSTD_compress_insertDictionary()`. /// /// The callback is the only operation that still crosses back into C. It