feat(decompress): move legacy stream dispatch to Rust
Move the legacy buffered-stream dispatcher out of the C decompression adapter while keeping ZSTD_DCtx_s private and C-owned. Rust now consumes the existing ZSTD_rustDctxView projection, detects the legacy version at input.pos, preserves static-context rejection and stream-stage reset behavior, and handles legacy context replacement through the version-gated v0.4-v0.7 Rust stream APIs. The Rust boundary retains the C helper's NULL normalization, dictionary lifetime sentinel, previous-version cleanup semantics, input/output position updates, and version-unsupported and no-legacy-support fallbacks. The C legacy free helper remains unchanged; only the dispatcher declaration and body were removed from the adapter. Focused tests cover unsupported versions, stage reset, context reuse/switching, and partial v0.4 input/output progress. Test Plan: - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` -- passed - Same clippy command with `--benches` and `--tests` -- passed - `cargo +nightly fmt --manifest-path rust/Cargo.toml`, followed by all three clippy commands -- passed - Decompression/legacy clippy with `-D warnings` -- passed - All 107 Rust tests with v0.4-v0.7 features -- passed - Focused legacy dispatcher tests: 4 passed - `make -C lib -j2 lib-mt` and `make -C lib -j2 lib-nomt` -- passed - `make -C tests -j2 test-legacy` -- built, then failed in the existing simple one-shot path with one v0.8 output byte mismatch (`e0` vs expected `e2`) before the streaming check; the new dispatcher symbol was not called on that failing path
This commit is contained in:
@@ -143,10 +143,6 @@ size_t ZSTD_rust_legacy_frame_size_info(const void* src, size_t srcSize,
|
||||
size_t ZSTD_rust_legacy_decompress(void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize,
|
||||
const void* dict, size_t dictSize);
|
||||
size_t ZSTD_rust_legacy_decompress_stream(ZSTD_DCtx* dctx,
|
||||
ZSTD_outBuffer* output,
|
||||
ZSTD_inBuffer* input,
|
||||
const void* dict, size_t dictSize);
|
||||
void ZSTD_rust_legacy_free_stream(ZSTD_DCtx* dctx);
|
||||
|
||||
void ZSTD_rust_dctx_view(ZSTD_DCtx* dctx, ZSTD_rustDctxView* out)
|
||||
@@ -428,46 +424,6 @@ size_t ZSTD_rust_legacy_decompress(void* dst, size_t dstCapacity,
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t ZSTD_rust_legacy_decompress_stream(ZSTD_DCtx* dctx,
|
||||
ZSTD_outBuffer* output,
|
||||
ZSTD_inBuffer* input,
|
||||
const void* dict, size_t dictSize)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
size_t hint;
|
||||
if (dctx->legacyVersion) {
|
||||
hint = ZSTD_decompressLegacyStream(dctx->legacyContext,
|
||||
dctx->legacyVersion, output, input);
|
||||
if (hint == 0) dctx->streamStage = zdss_init;
|
||||
return hint;
|
||||
}
|
||||
{
|
||||
const char* const istart = input->pos != 0
|
||||
? (const char*)input->src + input->pos
|
||||
: (const char*)input->src;
|
||||
size_t const inputSize = input->size - input->pos;
|
||||
U32 const legacyVersion = ZSTD_isLegacy(istart, inputSize);
|
||||
if (!legacyVersion) return ERROR(prefix_unknown);
|
||||
if (dctx->staticSize) return ERROR(memory_allocation);
|
||||
FORWARD_IF_ERROR(ZSTD_initLegacyStream(&dctx->legacyContext,
|
||||
dctx->previousLegacyVersion,
|
||||
legacyVersion, dict, dictSize), "");
|
||||
dctx->legacyVersion = dctx->previousLegacyVersion = legacyVersion;
|
||||
hint = ZSTD_decompressLegacyStream(dctx->legacyContext, legacyVersion,
|
||||
output, input);
|
||||
if (hint == 0) dctx->streamStage = zdss_init;
|
||||
return hint;
|
||||
}
|
||||
#else
|
||||
(void)dctx;
|
||||
(void)output;
|
||||
(void)input;
|
||||
(void)dict;
|
||||
(void)dictSize;
|
||||
return ERROR(prefix_unknown);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ZSTD_rust_legacy_free_stream(ZSTD_DCtx* dctx)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
|
||||
Reference in New Issue
Block a user