feat(compress): move C parameter update policy into Rust
Move ZSTD_CCtx_setCParams's validation and ordered parameter-update policy into the Rust projection. C retains the private ZSTD_CCtx_setParameter callback while Rust preserves the exact check/window/chain/hash/search/min-match/target/strategy order and error propagation. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml set_cparams -- --test-threads=1 - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; make -B -C programs -j1 zstd - git diff --cached --check
This commit is contained in:
@@ -196,6 +196,23 @@ typedef char ZSTD_rust_init_cstream_advanced_state_layout[
|
||||
== 5 * sizeof(void*)
|
||||
&& sizeof(ZSTD_rust_initCStreamAdvancedState) == 6 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
typedef size_t (*ZSTD_rust_setCParamsCheckCParams_f)(
|
||||
void* context, ZSTD_compressionParameters cParams);
|
||||
typedef size_t (*ZSTD_rust_setCParamsSetParameter_f)(
|
||||
void* context, int param, int value);
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
ZSTD_rust_setCParamsCheckCParams_f checkCParams;
|
||||
ZSTD_rust_setCParamsSetParameter_f setParameter;
|
||||
} ZSTD_rust_setCParamsState;
|
||||
size_t ZSTD_rust_setCParams(const ZSTD_rust_setCParamsState* state,
|
||||
ZSTD_compressionParameters cParams);
|
||||
typedef char ZSTD_rust_set_cparams_state_layout[
|
||||
(offsetof(ZSTD_rust_setCParamsState, callbackContext) == 0
|
||||
&& offsetof(ZSTD_rust_setCParamsState, checkCParams) == sizeof(void*)
|
||||
&& offsetof(ZSTD_rust_setCParamsState, setParameter) == 2 * sizeof(void*)
|
||||
&& sizeof(ZSTD_rust_setCParamsState) == 3 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
ZSTD_frameProgression ZSTD_rust_frameProgression(U64 consumedSrcSize,
|
||||
size_t buffered,
|
||||
U64 producedCSize);
|
||||
@@ -1873,20 +1890,28 @@ size_t ZSTD_CCtx_setParametersUsingCCtxParams(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t ZSTD_rust_setCParams_checkCParams(
|
||||
void* context, ZSTD_compressionParameters cParams)
|
||||
{
|
||||
(void)context;
|
||||
return ZSTD_checkCParams(cParams);
|
||||
}
|
||||
|
||||
static size_t ZSTD_rust_setCParams_setParameter(
|
||||
void* context, int param, int value)
|
||||
{
|
||||
return ZSTD_CCtx_setParameter((ZSTD_CCtx*)context, (ZSTD_cParameter)param, value);
|
||||
}
|
||||
|
||||
size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams)
|
||||
{
|
||||
ZSTD_rust_setCParamsState state;
|
||||
ZSTD_STATIC_ASSERT(sizeof(cparams) == 7 * 4 /* all params are listed below */);
|
||||
DEBUGLOG(4, "ZSTD_CCtx_setCParams");
|
||||
/* only update if all parameters are valid */
|
||||
FORWARD_IF_ERROR(ZSTD_checkCParams(cparams), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, (int)cparams.windowLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, (int)cparams.chainLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, (int)cparams.hashLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, (int)cparams.searchLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, (int)cparams.minMatch), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, (int)cparams.targetLength), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, (int)cparams.strategy), "");
|
||||
return 0;
|
||||
state.callbackContext = cctx;
|
||||
state.checkCParams = ZSTD_rust_setCParams_checkCParams;
|
||||
state.setParameter = ZSTD_rust_setCParams_setParameter;
|
||||
return ZSTD_rust_setCParams(&state, cparams);
|
||||
}
|
||||
|
||||
size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams)
|
||||
|
||||
Reference in New Issue
Block a user