diff --git a/rust/src/zstd_ddict.rs b/rust/src/zstd_ddict.rs index 43227130d..053a9d840 100644 --- a/rust/src/zstd_ddict.rs +++ b/rust/src/zstd_ddict.rs @@ -2,17 +2,17 @@ //! Digested decompression dictionaries (`ZSTD_DDict`). //! -//! The decoder proper is still implemented in C during the migration. In -//! particular, its `ZSTD_loadDEntropy()` helper owns the format-specific -//! construction of the decoder tables. This module owns the DDict object, -//! its allocation and lifetime, and passes an ABI-identical table layout to -//! that helper. +//! The decoder proper and its `ZSTD_loadDEntropy()` dictionary-table loader +//! are Rust-owned. This module owns the DDict object, its allocation and +//! lifetime, and passes an ABI-identical table layout to the decoder module. use crate::common::{LL_FSE_LOG, ML_FSE_LOG, OFF_FSE_LOG, ZSTD_FRAMEIDSIZE, ZSTD_REP_NUM}; use crate::errors::{ERR_isError, ZstdErrorCode, ERROR}; use crate::mem::MEM_readLE32; use std::ffi::c_void; -use std::mem::{offset_of, size_of}; +#[cfg(not(test))] +use std::mem::offset_of; +use std::mem::size_of; use std::os::raw::{c_int, c_uint}; use std::ptr; @@ -103,15 +103,6 @@ struct ZstdDctxOffsets { fuzz_end: usize, } -#[cfg(not(test))] -unsafe extern "C" { - fn ZSTD_loadDEntropy( - entropy: *mut ZSTD_entropyDTables, - dict: *const c_void, - dict_size: usize, - ) -> usize; -} - #[cfg(test)] #[inline] unsafe fn ddict_dctx_offsets() -> ZstdDctxOffsets { @@ -258,20 +249,16 @@ unsafe fn load_d_entropy( dict: *const c_void, dict_size: usize, ) -> usize { - #[cfg(not(test))] - { - // The existing C decoder owns this helper until its translation unit is - // moved. Its argument is the ABI-compatible table storage above. - unsafe { ZSTD_loadDEntropy(entropy, dict, dict_size) } - } - - #[cfg(test)] - { - let _ = (entropy, dict, dict_size); - // Unit tests exercise the DDict ownership and raw-content paths. A - // full dictionary is covered by the C compatibility executables, where - // the decoder's real ZSTD_loadDEntropy() is linked in. - ERROR(ZstdErrorCode::DictionaryCorrupted) + // The DDict and decoder modules keep separate Rust representations so + // neither needs to expose the other module's private fields. Both are + // `repr(C)` and guarded by exact layout assertions; only the pointer type + // changes at this narrow module boundary. + unsafe { + crate::zstd_decompress::ZSTD_loadDEntropy( + entropy.cast::(), + dict, + dict_size, + ) } }