refactor(decompress): move legacy threshold policy to Rust

Keep the target-specific ZSTD_LEGACY_SUPPORT macro in the C translation unit, but pass its scalar value through a Rust policy bridge before legacy dispatch. Rust now accepts only the historical supported range 1 through 7 and normalizes all other values, including a missing projection, to disabled. ABI assertions and focused tests preserve the compile-time configuration contract.

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 07:57:10 +02:00
parent 78c4118a67
commit f077d71e8b
2 changed files with 73 additions and 7 deletions
+18 -7
View File
@@ -187,6 +187,15 @@ typedef char ZSTD_rust_decompress_stack_callbacks_layout[
size_t ZSTD_rust_decompress_stack_action(
const ZSTD_rustDecompressStackProjection* projection,
const ZSTD_rustDecompressStackCallbacks* callbacks);
typedef struct {
unsigned configured_level;
} ZSTD_rustLegacySupportProjection;
typedef char ZSTD_rust_legacy_support_projection_layout[
(offsetof(ZSTD_rustLegacySupportProjection, configured_level) == 0
&& sizeof(ZSTD_rustLegacySupportProjection) == sizeof(unsigned))
? 1 : -1];
unsigned ZSTD_rust_legacy_support_policy(
const ZSTD_rustLegacySupportProjection* projection);
unsigned ZSTD_rust_legacy_support(void);
#if ZSTD_TRACE
@@ -352,15 +361,17 @@ void ZSTD_rust_dctx_trace_view(ZSTD_DCtx* dctx,
}
/* 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. */
* the active C configuration as a scalar leaf so test builds, which compile
* every Rust legacy module but vary this C macro per target, retain the
* historical support boundary. Rust owns normalization of that scalar. */
unsigned ZSTD_rust_legacy_support(void)
{
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) \
&& (ZSTD_LEGACY_SUPPORT <= 7)
return ZSTD_LEGACY_SUPPORT;
ZSTD_rustLegacySupportProjection const projection = {
#if defined(ZSTD_LEGACY_SUPPORT)
ZSTD_LEGACY_SUPPORT
#else
return 0;
0
#endif
};
return ZSTD_rust_legacy_support_policy(&projection);
}