feat(compress): project stream continue states into Rust
Pass the shared continue and end projections directly through the buffered stream ABI so Rust owns stream dispatch into the migrated compression paths. Remove the redundant C continue/end forwarding callbacks while retaining the C reset callback for private CCtx session state. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo fmt --all -- --check - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --lib zstd_compress::tests::compress_stream -- --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:
@@ -1007,9 +1007,6 @@ typedef char ZSTD_rust_compress_end_state_layout[
|
||||
/* Rust owns the single-threaded buffered/stable stream state machine. The
|
||||
* projection contains only stream bookkeeping and callback slots; operations
|
||||
* which still need the private CCtx layout remain C callbacks. */
|
||||
typedef size_t (*ZSTD_rust_compressStreamBlock_f)(
|
||||
void* context, void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize);
|
||||
typedef size_t (*ZSTD_rust_compressStreamReset_f)(void* context);
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
@@ -1028,8 +1025,8 @@ typedef struct {
|
||||
size_t* outBuffContentSize;
|
||||
size_t* outBuffFlushedSize;
|
||||
U32* frameEnded;
|
||||
ZSTD_rust_compressStreamBlock_f compressContinue;
|
||||
ZSTD_rust_compressStreamBlock_f compressEnd;
|
||||
const ZSTD_rust_compressContinueState* compressContinueState;
|
||||
const ZSTD_rust_compressEndState* compressEndState;
|
||||
ZSTD_rust_compressStreamReset_f resetSession;
|
||||
} ZSTD_rust_compressStreamState;
|
||||
size_t ZSTD_rust_compressStreamGeneric(
|
||||
@@ -1066,9 +1063,9 @@ typedef char ZSTD_rust_compress_stream_state_layout[
|
||||
== 10 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t)
|
||||
&& offsetof(ZSTD_rust_compressStreamState, frameEnded)
|
||||
== 11 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t)
|
||||
&& offsetof(ZSTD_rust_compressStreamState, compressContinue)
|
||||
&& offsetof(ZSTD_rust_compressStreamState, compressContinueState)
|
||||
== 12 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t)
|
||||
&& offsetof(ZSTD_rust_compressStreamState, compressEnd)
|
||||
&& offsetof(ZSTD_rust_compressStreamState, compressEndState)
|
||||
== 13 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t)
|
||||
&& offsetof(ZSTD_rust_compressStreamState, resetSession)
|
||||
== 14 * sizeof(void*) + 2 * sizeof(int) + 2 * sizeof(size_t)
|
||||
@@ -7233,22 +7230,6 @@ static size_t ZSTD_nextInputSizeHint(const ZSTD_CCtx* cctx)
|
||||
/** ZSTD_compressStream_generic():
|
||||
* internal function for all *compressStream*() variants
|
||||
* @return : hint size for next input to complete ongoing block */
|
||||
static size_t ZSTD_rust_compressStream_continue(
|
||||
void* context, void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize)
|
||||
{
|
||||
return ZSTD_compressContinue_public(
|
||||
(ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize);
|
||||
}
|
||||
|
||||
static size_t ZSTD_rust_compressStream_end(
|
||||
void* context, void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize)
|
||||
{
|
||||
return ZSTD_compressEnd_public(
|
||||
(ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize);
|
||||
}
|
||||
|
||||
static size_t ZSTD_rust_compressStream_reset(void* context)
|
||||
{
|
||||
return ZSTD_CCtx_reset((ZSTD_CCtx*)context, ZSTD_reset_session_only);
|
||||
@@ -7259,7 +7240,24 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
||||
ZSTD_inBuffer* input,
|
||||
ZSTD_EndDirective const flushMode)
|
||||
{
|
||||
ZSTD_rust_compressContinueContext continueContext;
|
||||
ZSTD_rust_compressEndState endState;
|
||||
ZSTD_rust_compressStreamState state;
|
||||
ZSTD_CCtx* const cctx = (ZSTD_CCtx*)zcs;
|
||||
ZSTD_compressContinue_prepare(cctx, cctx->blockSizeMax,
|
||||
0 /* block size already selected */, &continueContext);
|
||||
endState.callbackContext = zcs;
|
||||
endState.compressContinueState = &continueContext.state;
|
||||
endState.trace = ZSTD_rust_compressEnd_trace;
|
||||
endState.consumedSrcSize = &cctx->consumedSrcSize;
|
||||
endState.pledgedSrcSizePlusOne = cctx->pledgedSrcSizePlusOne;
|
||||
endState.contentSizeFlag = cctx->appliedParams.fParams.contentSizeFlag;
|
||||
endState.stage = (int*)&cctx->stage;
|
||||
endState.noDictIDFlag = cctx->appliedParams.fParams.noDictIDFlag;
|
||||
endState.checksumFlag = cctx->appliedParams.fParams.checksumFlag;
|
||||
endState.format = (int)cctx->appliedParams.format;
|
||||
endState.windowLog = cctx->appliedParams.cParams.windowLog;
|
||||
endState.checksumState = &cctx->xxhState;
|
||||
state.callbackContext = zcs;
|
||||
state.inBufferMode = (int)zcs->appliedParams.inBufferMode;
|
||||
state.outBufferMode = (int)zcs->appliedParams.outBufferMode;
|
||||
@@ -7276,8 +7274,8 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
||||
state.outBuffContentSize = &zcs->outBuffContentSize;
|
||||
state.outBuffFlushedSize = &zcs->outBuffFlushedSize;
|
||||
state.frameEnded = &zcs->frameEnded;
|
||||
state.compressContinue = ZSTD_rust_compressStream_continue;
|
||||
state.compressEnd = ZSTD_rust_compressStream_end;
|
||||
state.compressContinueState = &continueContext.state;
|
||||
state.compressEndState = &endState;
|
||||
state.resetSession = ZSTD_rust_compressStream_reset;
|
||||
return ZSTD_rust_compressStreamGeneric(
|
||||
&state, output, input, (int)flushMode);
|
||||
|
||||
Reference in New Issue
Block a user