feat(decompress): move legacy dispatch into Rust
Legacy detection, frame-size queries, one-shot decode, and buffered streaming were still routed through the C header dispatcher even though every historical v0.1 through v0.7 decoder is already ported under Rust feature gates. The C implementation also duplicated the support-level boundary independently from the Rust archive selection. Move the dispatcher and stream lifecycle to Rust using the existing DCtx field projection. Rust now selects the version, preserves the null-buffer and position semantics, initializes and frees buffered legacy contexts, and calls the frozen per-version modules. C retains only the configuration leaf that reports ZSTD_LEGACY_SUPPORT plus the private DCtx layout and trace helpers, so library, program, and test builds can still choose different support levels. Test Plan: - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression,decompression,dict-builder,legacy-v01,legacy-v02,legacy-v03,legacy-v04,legacy-v05,legacy-v06,legacy-v07 --all-targets -- --test-threads=1` -- 528 passed. - Native `test-legacy`, `test-invalidDictionaries`, `test-decodecorpus`, and `test-zstd` -- passed. - Strict C syntax checks with legacy support 0, 4, 5, and 7 -- passed. - `cargo clippy` default, benches, and tests for library and CLI -- passed.
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
#include "zstd_decompress_internal.h"
|
||||
#include "zstd_ddict.h"
|
||||
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
# include "../legacy/zstd_legacy.h"
|
||||
#endif
|
||||
|
||||
/* Keep the three public build-time tuning knobs in the C configuration domain.
|
||||
* Rust queries them through the small leaves below rather than baking a second
|
||||
* set of defaults into its source. */
|
||||
@@ -125,18 +121,7 @@ void ZSTD_rust_dctx_copy_prefix(ZSTD_DCtx* dstDCtx, const ZSTD_DCtx* srcDCtx);
|
||||
void ZSTD_rust_dctx_trace_begin(ZSTD_DCtx* dctx);
|
||||
void ZSTD_rust_dctx_trace_end(ZSTD_DCtx* dctx, U64 uncompressedSize,
|
||||
U64 compressedSize, int streaming);
|
||||
unsigned ZSTD_rust_legacy_is(const void* src, size_t srcSize);
|
||||
unsigned long long ZSTD_rust_legacy_get_decompressed_size(const void* src,
|
||||
size_t srcSize);
|
||||
size_t ZSTD_rust_legacy_find_compressed_size(const void* src, size_t srcSize);
|
||||
size_t ZSTD_rust_legacy_frame_size_info(const void* src, size_t srcSize,
|
||||
size_t* compressedSize,
|
||||
unsigned long long* decompressedBound,
|
||||
size_t* nbBlocks);
|
||||
size_t ZSTD_rust_legacy_decompress(void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize,
|
||||
const void* dict, size_t dictSize);
|
||||
void ZSTD_rust_legacy_free_stream(ZSTD_DCtx* dctx);
|
||||
unsigned ZSTD_rust_legacy_support(void);
|
||||
|
||||
void ZSTD_rust_dctx_view(ZSTD_DCtx* dctx, ZSTD_rustDctxView* out)
|
||||
{
|
||||
@@ -319,87 +304,16 @@ void ZSTD_rust_dctx_trace_end(ZSTD_DCtx* dctx, U64 uncompressedSize,
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned ZSTD_rust_legacy_is(const void* src, size_t srcSize)
|
||||
/* The Rust dispatcher has all version-specific legacy implementations. Keep
|
||||
* the active C configuration as a leaf so test builds, which compile every
|
||||
* Rust legacy module but vary this C macro per target, retain the historical
|
||||
* support boundary. */
|
||||
unsigned ZSTD_rust_legacy_support(void)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
return ZSTD_isLegacy(src, srcSize);
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) \
|
||||
&& (ZSTD_LEGACY_SUPPORT <= 7)
|
||||
return ZSTD_LEGACY_SUPPORT;
|
||||
#else
|
||||
(void)src;
|
||||
(void)srcSize;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned long long ZSTD_rust_legacy_get_decompressed_size(const void* src, size_t srcSize)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
return ZSTD_getDecompressedSize_legacy(src, srcSize);
|
||||
#else
|
||||
(void)src;
|
||||
(void)srcSize;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t ZSTD_rust_legacy_find_compressed_size(const void* src, size_t srcSize)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
return ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
|
||||
#else
|
||||
(void)src;
|
||||
(void)srcSize;
|
||||
return ERROR(prefix_unknown);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t ZSTD_rust_legacy_frame_size_info(const void* src, size_t srcSize,
|
||||
size_t* compressedSize,
|
||||
unsigned long long* decompressedBound,
|
||||
size_t* nbBlocks)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
ZSTD_frameSizeInfo const info = ZSTD_findFrameSizeInfoLegacy(src, srcSize);
|
||||
*compressedSize = info.compressedSize;
|
||||
*decompressedBound = info.decompressedBound;
|
||||
*nbBlocks = info.decompressedBound == ZSTD_CONTENTSIZE_ERROR
|
||||
? 0 : (size_t)(info.decompressedBound / ZSTD_BLOCKSIZE_MAX);
|
||||
return ZSTD_isError(info.compressedSize) ? info.compressedSize : 0;
|
||||
#else
|
||||
(void)src;
|
||||
(void)srcSize;
|
||||
*compressedSize = ERROR(prefix_unknown);
|
||||
*decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||
*nbBlocks = 0;
|
||||
return ERROR(prefix_unknown);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t ZSTD_rust_legacy_decompress(void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize,
|
||||
const void* dict, size_t dictSize)
|
||||
{
|
||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||
return ZSTD_decompressLegacy(dst, dstCapacity, src, srcSize, dict, dictSize);
|
||||
#else
|
||||
(void)dst;
|
||||
(void)dstCapacity;
|
||||
(void)src;
|
||||
(void)srcSize;
|
||||
(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)
|
||||
if (dctx->legacyContext) {
|
||||
ZSTD_freeLegacyStreamContext(dctx->legacyContext,
|
||||
dctx->previousLegacyVersion);
|
||||
dctx->legacyContext = NULL;
|
||||
}
|
||||
#else
|
||||
(void)dctx;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user