feat(cdict): move workspace reservation sizing to Rust

CDict initialization already lets Rust choose by-reference versus by-copy
content, but the C bridge still selected the pointer-rounded content allocation
and the HUF entropy-workspace size. That kept advanced and static CDict
dictionary loading dependent on C policy even though the allocator itself can
remain private.

Compute the content reservation with the C-equivalent wrapping pointer
alignment in Rust and pass both that size and the HUF workspace size through the
existing callbacks. C now only forwards the sizes to
ZSTD_cwksp_reserve_object; private CDict/workspace layouts and allocator
behavior remain behind the ABI bridge. Focused probes cover alignment
boundaries, by-copy content, and both reservation sizes.

Test Plan:
- `ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` -- passed
- `ulimit -v 41943040; gcc -fsyntax-only -std=c99 -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=0 -DZSTD_MULTITHREAD -DZSTD_LEGACY_SUPPORT=5 -Ilib -Ilib/common -Ilib/compress -Ilib/decompress -Ilib/dict -Ilib/deprecated lib/compress/zstd_compress.c` -- passed
- `ulimit -v 41943040; clang -fsyntax-only -std=c99 -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=0 -DZSTD_MULTITHREAD -DZSTD_LEGACY_SUPPORT=5 -DZSTD_NO_ASM=1 -Ilib -Ilib/common -Ilib/compress -Ilib/decompress -Ilib/dict -Ilib/deprecated lib/compress/zstd_compress.c` -- passed
- `git diff --check` and `git diff --cached --check` -- passed
- Cargo builds/tests, make, fuzzers, and large upstream tests were not run per task constraints
- GPG signing was unavailable because the configured pinentry could not start;
  this commit was created explicitly unsigned with `--no-gpg-sign`
This commit is contained in:
2026-07-20 17:15:07 +02:00
parent 0d4164fbfe
commit c89ac3d6cf
2 changed files with 57 additions and 11 deletions
+8 -6
View File
@@ -2639,7 +2639,8 @@ typedef char ZSTD_rust_external_sequence_store_state_layout[
typedef void* (*ZSTD_rust_initCDictReserveContent_f)(
void* context, size_t dictSize);
typedef void* (*ZSTD_rust_initCDictReserveEntropy_f)(void* context);
typedef void* (*ZSTD_rust_initCDictReserveEntropy_f)(
void* context, size_t workspaceSize);
typedef size_t (*ZSTD_rust_initCDictResetMatchState_f)(
void* context, const ZSTD_compressionParameters* cParams,
int useRowMatchFinder);
@@ -6420,17 +6421,18 @@ ZSTD_compress_insertDictionary(ZSTD_compressedBlockState_t* bs,
ZSTD_loadDictionaryContent_callback);
}
static void* ZSTD_rust_initCDict_reserveContent(void* context, size_t dictSize)
static void* ZSTD_rust_initCDict_reserveContent(
void* context, size_t reservedSize)
{
ZSTD_CDict* const cdict = (ZSTD_CDict*)context;
return ZSTD_cwksp_reserve_object(
&cdict->workspace, ZSTD_cwksp_align(dictSize, sizeof(void*)));
return ZSTD_cwksp_reserve_object(&cdict->workspace, reservedSize);
}
static void* ZSTD_rust_initCDict_reserveEntropy(void* context)
static void* ZSTD_rust_initCDict_reserveEntropy(
void* context, size_t workspaceSize)
{
ZSTD_CDict* const cdict = (ZSTD_CDict*)context;
return ZSTD_cwksp_reserve_object(&cdict->workspace, HUF_WORKSPACE_SIZE);
return ZSTD_cwksp_reserve_object(&cdict->workspace, workspaceSize);
}
static size_t ZSTD_rust_initCDict_resetMatchState(