refactor(compress): move stream buffer policy to Rust
Project the public ZSTD_compressStream2 buffer positions into Rust and preserve the original output-first classification. C retains the dstSize_tooSmall and srcSize_wrong mappings, exact diagnostics, private context, and streaming state machine. Test Plan: - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings` -- passed - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings` -- passed - `ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` -- passed - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1` -- passed - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 ./tests/rustLibSmoke` -- passed - `ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1 -C tests test` -- passed, including large streaming, native, fuzzer, and zstream phases
This commit is contained in:
@@ -769,6 +769,30 @@ size_t ZSTD_compressStream2_c(ZSTD_CCtx* cctx,
|
||||
ZSTD_outBuffer* output,
|
||||
ZSTD_inBuffer* input,
|
||||
ZSTD_EndDirective endOp);
|
||||
typedef struct {
|
||||
size_t outputPos;
|
||||
size_t outputSize;
|
||||
size_t inputPos;
|
||||
size_t inputSize;
|
||||
} ZSTD_rust_compressStream2BufferPolicyState;
|
||||
enum {
|
||||
ZSTD_RUST_COMPRESS_STREAM2_BUFFER_VALID = 0,
|
||||
ZSTD_RUST_COMPRESS_STREAM2_BUFFER_OUTPUT_INVALID = 1,
|
||||
ZSTD_RUST_COMPRESS_STREAM2_BUFFER_INPUT_INVALID = 2
|
||||
};
|
||||
int ZSTD_rust_compressStream2BufferPolicy(
|
||||
const ZSTD_rust_compressStream2BufferPolicyState* state);
|
||||
typedef char ZSTD_rust_compress_stream2_buffer_policy_state_layout[
|
||||
(offsetof(ZSTD_rust_compressStream2BufferPolicyState, outputPos) == 0
|
||||
&& offsetof(ZSTD_rust_compressStream2BufferPolicyState, outputSize)
|
||||
== sizeof(size_t)
|
||||
&& offsetof(ZSTD_rust_compressStream2BufferPolicyState, inputPos)
|
||||
== 2 * sizeof(size_t)
|
||||
&& offsetof(ZSTD_rust_compressStream2BufferPolicyState, inputSize)
|
||||
== 3 * sizeof(size_t)
|
||||
&& sizeof(ZSTD_rust_compressStream2BufferPolicyState)
|
||||
== 4 * sizeof(size_t))
|
||||
? 1 : -1];
|
||||
typedef struct {
|
||||
int endOp;
|
||||
} ZSTD_rust_compressStream2PolicyState;
|
||||
@@ -8273,8 +8297,14 @@ size_t ZSTD_compressStream2_c( ZSTD_CCtx* cctx,
|
||||
{
|
||||
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
||||
/* check conditions */
|
||||
RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall, "invalid output buffer");
|
||||
RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong, "invalid input buffer");
|
||||
{ ZSTD_rust_compressStream2BufferPolicyState const state = {
|
||||
output->pos, output->size, input->pos, input->size};
|
||||
int const bufferPolicy = ZSTD_rust_compressStream2BufferPolicy(&state);
|
||||
RETURN_ERROR_IF(bufferPolicy == ZSTD_RUST_COMPRESS_STREAM2_BUFFER_OUTPUT_INVALID,
|
||||
dstSize_tooSmall, "invalid output buffer");
|
||||
RETURN_ERROR_IF(bufferPolicy == ZSTD_RUST_COMPRESS_STREAM2_BUFFER_INPUT_INVALID,
|
||||
srcSize_wrong, "invalid input buffer");
|
||||
}
|
||||
{ ZSTD_rust_compressStream2PolicyState const state = {(int)endOp};
|
||||
RETURN_ERROR_IF(!ZSTD_rust_compressStream2Policy(&state),
|
||||
parameter_outOfBound, "invalid endDirective");
|
||||
|
||||
Reference in New Issue
Block a user