feat(compress): move CDict content copy policy into Rust

Move CDict by-reference versus by-copy selection and dictionary-content
copying into the Rust initialization leaf. C now exposes only an aligned
private-workspace reservation callback, retaining ownership of the opaque
workspace layout while Rust owns the content policy and copy operation.

Add focused coverage for both by-reference bypass and by-copy reservation,
copying, and callback ordering.

Test Plan:
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml
- 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-zstream ZSTREAM_TESTTIME=-T2s
- ulimit -v 41943040 && make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
- ulimit -v 41943040 && cargo fmt --manifest-path rust/Cargo.toml -- --check
- git diff --check
This commit is contained in:
2026-07-19 22:01:27 +02:00
parent 2125f9822d
commit 29198a1157
2 changed files with 128 additions and 53 deletions
+8 -17
View File
@@ -2222,8 +2222,8 @@ typedef char ZSTD_rust_external_sequence_store_state_layout[
== 5 * sizeof(void*))
? 1 : -1];
typedef size_t (*ZSTD_rust_initCDictAssignContent_f)(
void* context, const void* dict, size_t dictSize, int dictLoadMethod);
typedef void* (*ZSTD_rust_initCDictReserveContent_f)(
void* context, size_t dictSize);
typedef void* (*ZSTD_rust_initCDictReserveEntropy_f)(void* context);
typedef void (*ZSTD_rust_initCDictResetBlockState_f)(void* context);
typedef size_t (*ZSTD_rust_initCDictResetMatchState_f)(
@@ -2247,7 +2247,7 @@ typedef struct {
U32* dictID;
int* compressionLevel;
int* contentSizeFlag;
ZSTD_rust_initCDictAssignContent_f assignContent;
ZSTD_rust_initCDictReserveContent_f reserveContent;
ZSTD_rust_initCDictReserveEntropy_f reserveEntropy;
ZSTD_rust_initCDictResetBlockState_f resetBlockState;
ZSTD_rust_initCDictResetMatchState_f resetMatchState;
@@ -2283,7 +2283,7 @@ typedef char ZSTD_rust_init_cdict_state_layout[
== 12 * sizeof(void*)
&& offsetof(ZSTD_rust_initCDictState, contentSizeFlag)
== 13 * sizeof(void*)
&& offsetof(ZSTD_rust_initCDictState, assignContent)
&& offsetof(ZSTD_rust_initCDictState, reserveContent)
== 14 * sizeof(void*)
&& offsetof(ZSTD_rust_initCDictState, reserveEntropy)
== 15 * sizeof(void*)
@@ -6029,20 +6029,11 @@ ZSTD_compress_insertDictionary(ZSTD_compressedBlockState_t* bs,
ZSTD_loadDictionaryContent_callback);
}
static size_t ZSTD_rust_initCDict_assignContent(
void* context, const void* dict, size_t dictSize, int dictLoadMethod)
static void* ZSTD_rust_initCDict_reserveContent(void* context, size_t dictSize)
{
ZSTD_CDict* const cdict = (ZSTD_CDict*)context;
if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dict) || (!dictSize)) {
cdict->dictContent = dict;
} else {
void* const internalBuffer = ZSTD_cwksp_reserve_object(
&cdict->workspace, ZSTD_cwksp_align(dictSize, sizeof(void*)));
RETURN_ERROR_IF(!internalBuffer, memory_allocation, "NULL pointer!");
cdict->dictContent = internalBuffer;
ZSTD_memcpy(internalBuffer, dict, dictSize);
}
return 0;
return ZSTD_cwksp_reserve_object(
&cdict->workspace, ZSTD_cwksp_align(dictSize, sizeof(void*)));
}
static void* ZSTD_rust_initCDict_reserveEntropy(void* context)
@@ -6624,7 +6615,7 @@ static size_t ZSTD_initCDict_internal(
state.dictID = &cdict->dictID;
state.compressionLevel = &params.compressionLevel;
state.contentSizeFlag = &params.fParams.contentSizeFlag;
state.assignContent = ZSTD_rust_initCDict_assignContent;
state.reserveContent = ZSTD_rust_initCDict_reserveContent;
state.reserveEntropy = ZSTD_rust_initCDict_reserveEntropy;
state.resetBlockState = ZSTD_rust_initCDict_resetBlockState;
state.resetMatchState = ZSTD_rust_initCDict_resetMatchState;