refactor(decompress): move sequence mode policy to Rust

Keep the C build-time mutual-exclusion check and private decoder-context assembly in the C shim, but pass the selected force-short/force-long policy through Rust. Rust now owns normalization to the runtime, short, or long sequence decoder mode, with ABI assertions and focused null/build-policy tests.

Test Plan: Not run in this atomic commit; the capped serial Rust, native, smoke, and original test-suite verification follows.
This commit is contained in:
2026-07-21 08:13:08 +02:00
parent f077d71e8b
commit f44d9726c3
2 changed files with 93 additions and 9 deletions
+23 -8
View File
@@ -25,13 +25,19 @@
#error "Cannot force the use of the short and the long ZSTD_decompressSequences variants!"
#endif
#if defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT)
#define ZSTD_RUST_SEQUENCE_DECODER_MODE 1
#elif defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG)
#define ZSTD_RUST_SEQUENCE_DECODER_MODE 2
#else
#define ZSTD_RUST_SEQUENCE_DECODER_MODE 0
#endif
typedef struct {
int forceShort;
int forceLong;
} ZSTD_rustSequenceDecoderPolicy;
typedef char ZSTD_rust_sequence_decoder_policy_layout[
(offsetof(ZSTD_rustSequenceDecoderPolicy, forceShort) == 0
&& offsetof(ZSTD_rustSequenceDecoderPolicy, forceLong) == sizeof(int)
&& sizeof(ZSTD_rustSequenceDecoderPolicy) == 2 * sizeof(int))
? 1 : -1];
int ZSTD_rust_sequence_decoder_mode(
const ZSTD_rustSequenceDecoderPolicy* policy);
typedef char ZSTD_rust_block_seq_symbol_layout[(sizeof(ZSTD_seqSymbol) == 8) ? 1 : -1];
typedef char ZSTD_rust_block_entropy_rep_offset[
@@ -72,6 +78,15 @@ typedef struct {
static ZSTD_rustBlockCtx ZSTD_rust_block_context(ZSTD_DCtx* dctx)
{
ZSTD_rustBlockCtx ctx;
ZSTD_rustSequenceDecoderPolicy const sequencePolicy = {
#if defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT)
1, 0
#elif defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG)
0, 1
#else
0, 0
#endif
};
ctx.lltPtr = &dctx->LLTptr;
ctx.mltPtr = &dctx->MLTptr;
ctx.oftPtr = &dctx->OFTptr;
@@ -98,7 +113,7 @@ static ZSTD_rustBlockCtx ZSTD_rust_block_context(ZSTD_DCtx* dctx)
ctx.litBufferLocation = &dctx->litBufferLocation;
ctx.litExtraBuffer = dctx->litExtraBuffer;
ctx.litExtraBufferSize = ZSTD_LITBUFFEREXTRASIZE;
ctx.sequenceDecoderMode = ZSTD_RUST_SEQUENCE_DECODER_MODE;
ctx.sequenceDecoderMode = ZSTD_rust_sequence_decoder_mode(&sequencePolicy);
return ctx;
}