From b550b14ceba318a5d47f1cc95cf797dd315b1544 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Mon, 20 Jul 2026 09:29:04 +0200 Subject: [PATCH] refactor(decompress): remove redundant dictionary bridge Call the authoritative DDict constructor directly from the Rust decompression policy after converting the shared repr(C) allocator projection. Remove the C forwarding declaration and wrapper so dictionary creation no longer crosses an unnecessary Rust-to-C-to-C boundary, while compile-time size and alignment checks keep the allocator conversion tied to the ABI contract. Test Plan: - `ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings` - `ulimit -v 41943040; make -j1` - `ulimit -v 41943040; make -j1 -C tests test` - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings` - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets` The integrated checks ran at the combined working-tree tip, including the parallel MT checksum seam that remains as the next commit. Standalone root Rust unit linking remains unavailable because the crate imports C-owned bridge symbols without a Cargo build/link setup. --- lib/decompress/zstd_decompress.c | 13 ------------- rust/src/zstd_decompress.rs | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index c2bf54ad8..294b11e00 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -142,10 +142,6 @@ size_t ZSTD_rust_decompress_stack(void* dst, size_t dstCapacity, size_t ZSTD_rust_decompress_stack_context(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); -ZSTD_DDict* ZSTD_rust_create_ddict(const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType, - ZSTD_customMem customMem); unsigned ZSTD_rust_legacy_support(void); #if ZSTD_TRACE @@ -291,15 +287,6 @@ size_t ZSTD_rust_decompress_stack(void* dst, size_t dstCapacity, #endif } -ZSTD_DDict* ZSTD_rust_create_ddict(const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType, - ZSTD_customMem customMem) -{ - return ZSTD_createDDict_advanced(dict, dictSize, dictLoadMethod, - dictContentType, customMem); -} - void ZSTD_rust_dctx_trace_view(ZSTD_DCtx* dctx, ZSTD_rustDctxTraceView* out) { diff --git a/rust/src/zstd_decompress.rs b/rust/src/zstd_decompress.rs index ea18d8f0a..b1cb8fcf1 100644 --- a/rust/src/zstd_decompress.rs +++ b/rust/src/zstd_decompress.rs @@ -22,7 +22,7 @@ use crate::mem::{MEM_32bits, MEM_readLE16, MEM_readLE32, MEM_readLE64}; use crate::xxhash::{XXH64_digest, XXH64_reset, XXH64_state_t, XXH64_update, XXH64}; use crate::zstd_ddict::{ ZSTD_DDict, ZSTD_DDict_dictContent, ZSTD_DDict_dictSize, ZSTD_copyDDictParameters, - ZSTD_freeDDict, ZSTD_getDictID_fromDDict, + ZSTD_createDDict_advanced, ZSTD_freeDDict, ZSTD_getDictID_fromDDict, }; use std::cmp::{max, min}; use std::ffi::c_void; @@ -304,6 +304,8 @@ const _: () = { assert!(offset_of!(ZSTD_rustDctxView, static_size) == 29 * size_of::()); assert!(offset_of!(ZSTD_rustDctxView, dctx_size) == 67 * size_of::()); assert!(size_of::() == 68 * size_of::()); + assert!(size_of::() == size_of::()); + assert!(align_of::() == align_of::()); assert!(align_of::() == align_of::()); }; @@ -352,13 +354,6 @@ unsafe extern "C" { src: *const c_void, src_size: usize, ) -> usize; - fn ZSTD_rust_create_ddict( - dict: *const c_void, - dict_size: usize, - dict_load_method: c_int, - dict_content_type: c_int, - custom_mem: ZSTD_customMem, - ) -> *mut ZSTD_DDict; #[cfg(all( not(test), any( @@ -1719,6 +1714,11 @@ unsafe fn dctx_custom_mem(view: &ZSTD_rustDctxView) -> ZSTD_customMem { unsafe { field(view.custom_mem) } } +#[inline] +unsafe fn ddict_custom_mem(view: &ZSTD_rustDctxView) -> crate::zstd_ddict::ZSTD_customMem { + unsafe { std::mem::transmute(dctx_custom_mem(view)) } +} + #[inline] unsafe fn dctx_ddict(view: &ZSTD_rustDctxView) -> *const ZSTD_DDict { unsafe { field(view.ddict) } @@ -3991,12 +3991,12 @@ pub unsafe extern "C" fn ZSTD_DCtx_loadDictionary_advanced( unsafe { clear_dict(&view) }; if !dict.is_null() && dict_size != 0 { let ddict = unsafe { - ZSTD_rust_create_ddict( + ZSTD_createDDict_advanced( dict, dict_size, dict_load_method, dict_content_type, - dctx_custom_mem(&view), + ddict_custom_mem(&view), ) }; if ddict.is_null() {