feat(compress): move frame header projection into Rust

Remove the C frame-header callback from the Rust-owned compressContinue
orchestration.  Project the applied frame parameters and dictionary ID as
scalars, so Rust can call the existing header serializer directly while
preserving pledged-size subtraction, stage transitions, and output accounting.
Route the sequence API's remaining header call directly to the same Rust leaf
and delete the redundant C wrapper.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --lib zstd_compress::tests::compress_continue -- --nocapture
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --all-targets -- -D warnings
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test
- 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
This commit is contained in:
2026-07-20 00:06:44 +02:00
parent 048979aff6
commit 534d7c9264
3 changed files with 122 additions and 89 deletions
+46 -43
View File
@@ -878,11 +878,8 @@ typedef char ZSTD_rust_frame_chunk_state_layout[
? 1 : -1];
/* The high-level continue/block entry points are Rust-owned. This projection
* carries only mutable scalar state and C callbacks; the private CCtx and
* match-state layout never crosses the ABI. */
typedef size_t (*ZSTD_rust_compressContinueHeader_f)(void* context,
void* dst,
size_t dstCapacity);
* carries frame-header scalars, mutable state, and C callbacks; the private
* CCtx and match-state layout never crosses the ABI. */
typedef void (*ZSTD_rust_compressContinueWindow_f)(void* context,
const void* src,
size_t srcSize);
@@ -894,7 +891,6 @@ typedef size_t (*ZSTD_rust_compressContinueBlock_f)(void* context,
U32 lastFrameChunk);
typedef struct {
void* callbackContext;
ZSTD_rust_compressContinueHeader_f writeFrameHeader;
ZSTD_rust_compressContinueWindow_f updateWindow;
ZSTD_rust_compressContinueWindow_f correctOverflow;
ZSTD_rust_compressContinueBlock_f compressFrameChunk;
@@ -905,6 +901,12 @@ typedef struct {
U64 pledgedSrcSizePlusOne;
size_t blockSizeMax;
int checkBlockSize;
int noDictIDFlag;
int checksumFlag;
int contentSizeFlag;
int format;
U32 windowLog;
U32 dictID;
} ZSTD_rust_compressContinueState;
size_t ZSTD_rust_compressContinue(
const ZSTD_rust_compressContinueState* state,
@@ -913,21 +915,32 @@ size_t ZSTD_rust_compressContinue(
U32 frame, U32 lastFrameChunk);
typedef char ZSTD_rust_compress_continue_state_layout[
(offsetof(ZSTD_rust_compressContinueState, callbackContext) == 0
&& offsetof(ZSTD_rust_compressContinueState, writeFrameHeader) == sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, updateWindow) == 2 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, correctOverflow) == 3 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, compressFrameChunk) == 4 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, compressBlock) == 5 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, stage) == 6 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, consumedSrcSize) == 7 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, producedCSize) == 8 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, pledgedSrcSizePlusOne) == 9 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, updateWindow) == sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, correctOverflow) == 2 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, compressFrameChunk) == 3 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, compressBlock) == 4 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, stage) == 5 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, consumedSrcSize) == 6 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, producedCSize) == 7 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, pledgedSrcSizePlusOne) == 8 * sizeof(void*)
&& offsetof(ZSTD_rust_compressContinueState, blockSizeMax)
== 9 * sizeof(void*) + sizeof(U64)
== 8 * sizeof(void*) + sizeof(U64)
&& offsetof(ZSTD_rust_compressContinueState, checkBlockSize)
== 9 * sizeof(void*) + sizeof(U64) + sizeof(size_t)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t)
&& offsetof(ZSTD_rust_compressContinueState, noDictIDFlag)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + sizeof(int)
&& offsetof(ZSTD_rust_compressContinueState, checksumFlag)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 2 * sizeof(int)
&& offsetof(ZSTD_rust_compressContinueState, contentSizeFlag)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 3 * sizeof(int)
&& offsetof(ZSTD_rust_compressContinueState, format)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 4 * sizeof(int)
&& offsetof(ZSTD_rust_compressContinueState, windowLog)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 5 * sizeof(int)
&& offsetof(ZSTD_rust_compressContinueState, dictID)
== 8 * sizeof(void*) + sizeof(U64) + sizeof(size_t) + 5 * sizeof(int) + sizeof(U32)
&& sizeof(ZSTD_rust_compressContinueState)
== (sizeof(void*) == 8 ? 96 : 52))
== (sizeof(void*) == 8 ? 112 : 72))
? 1 : -1];
/* Rust owns the end-of-frame orchestration. The callbacks retain the
@@ -5600,28 +5613,6 @@ static size_t ZSTD_compress_frameChunk(ZSTD_CCtx* cctx,
}
static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
const ZSTD_CCtx_params* params,
U64 pledgedSrcSize, U32 dictID)
{
return ZSTD_rust_writeFrameHeader(dst, dstCapacity,
params->fParams.noDictIDFlag,
params->fParams.checksumFlag,
params->fParams.contentSizeFlag,
(int)params->format,
params->cParams.windowLog,
pledgedSrcSize, dictID);
}
static size_t ZSTD_rust_compressContinue_writeFrameHeader(
void* context, void* dst, size_t dstCapacity)
{
ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context;
return ZSTD_writeFrameHeader(
dst, dstCapacity, &cctx->appliedParams,
cctx->pledgedSrcSizePlusOne - 1, cctx->dictID);
}
static void ZSTD_rust_compressContinue_updateWindow(
void* context, const void* src, size_t srcSize)
{
@@ -5676,7 +5667,6 @@ static size_t ZSTD_compressContinue_dispatch(
{
ZSTD_rust_compressContinueState state;
state.callbackContext = cctx;
state.writeFrameHeader = ZSTD_rust_compressContinue_writeFrameHeader;
state.updateWindow = ZSTD_rust_compressContinue_updateWindow;
state.correctOverflow = ZSTD_rust_compressContinue_correctOverflow;
state.compressFrameChunk = ZSTD_rust_compressContinue_frameChunk;
@@ -5687,6 +5677,12 @@ static size_t ZSTD_compressContinue_dispatch(
state.pledgedSrcSizePlusOne = cctx->pledgedSrcSizePlusOne;
state.blockSizeMax = blockSizeMax;
state.checkBlockSize = checkBlockSize;
state.noDictIDFlag = cctx->appliedParams.fParams.noDictIDFlag;
state.checksumFlag = cctx->appliedParams.fParams.checksumFlag;
state.contentSizeFlag = cctx->appliedParams.fParams.contentSizeFlag;
state.format = (int)cctx->appliedParams.format;
state.windowLog = cctx->appliedParams.cParams.windowLog;
state.dictID = cctx->dictID;
return ZSTD_rust_compressContinue(
&state, dst, dstCapacity, src, srcSize, frame, lastFrameChunk);
}
@@ -8030,8 +8026,15 @@ static size_t ZSTD_rust_sequenceApi_writeFrameHeader(
void* context, void* dst, size_t dstCapacity, size_t pledgedSrcSize)
{
ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)context;
return ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams,
pledgedSrcSize, cctx->dictID);
return ZSTD_rust_writeFrameHeader(
dst, dstCapacity,
cctx->appliedParams.fParams.noDictIDFlag,
cctx->appliedParams.fParams.checksumFlag,
cctx->appliedParams.fParams.contentSizeFlag,
(int)cctx->appliedParams.format,
cctx->appliedParams.cParams.windowLog,
pledgedSrcSize,
cctx->dictID);
}
static void ZSTD_rust_sequenceApi_updateChecksum(