refactor(decompress): move stack-context dispatch policy to Rust

Keep the heapmode guard, stack-owned ZSTD_DCtx, static initialization, and
private context layout in C. Once the context is initialized, Rust now owns the
one-shot stack-context policy: it clears the projected static-size marker and
dispatches the existing ZSTD_decompressDCtx implementation through the opaque
context pointer.

Add matching C/Rust view-layout assertions and focused callback tests covering
static-size clearing, argument forwarding, and null-context rejection.

Test Plan:
- `ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check`
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings`
- `ulimit -v 41943040; make -j1`
- `ulimit -v 41943040; make -j1 -C tests test` (all upstream tests completed successfully)
- Standalone Rust unit linking remains unavailable without the C-owned bridge symbols; the integrated build and upstream C/Rust oracle supplied the runtime/link coverage.
This commit is contained in:
2026-07-20 09:07:11 +02:00
parent 2442fddc38
commit 870d6a2e40
2 changed files with 144 additions and 6 deletions
+11 -5
View File
@@ -106,6 +106,12 @@ typedef struct {
size_t dctx_size;
} ZSTD_rustDctxView;
typedef char ZSTD_rust_dctx_view_layout[
(offsetof(ZSTD_rustDctxView, dctx) == 0
&& offsetof(ZSTD_rustDctxView, static_size) == 29 * sizeof(void*)
&& offsetof(ZSTD_rustDctxView, dctx_size) == 67 * sizeof(void*)
&& sizeof(ZSTD_rustDctxView) == 68 * sizeof(void*)) ? 1 : -1];
/* Rust exposes this as u64. Use the trace API's exact unsigned-long-long
* representation instead of U64, whose typedef may be a different C type on
* some targets even when it has the same width. */
@@ -133,6 +139,9 @@ int ZSTD_rust_no_forward_progress_max(void);
int ZSTD_rust_heapmode(void);
size_t ZSTD_rust_decompress_stack(void* dst, size_t dstCapacity,
const void* src, size_t srcSize);
size_t ZSTD_rust_decompress_stack_context(ZSTD_DCtx* dctx,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize);
ZSTD_DDict* ZSTD_rust_create_ddict(const void* dict, size_t dictSize,
ZSTD_dictLoadMethod_e dictLoadMethod,
ZSTD_dictContentType_e dictContentType,
@@ -277,11 +286,8 @@ size_t ZSTD_rust_decompress_stack(void* dst, size_t dstCapacity,
ZSTD_DCtx dctx;
ZSTD_DCtx* const initialized = ZSTD_initStaticDCtx(&dctx, sizeof(dctx));
if (initialized == NULL) return ERROR(memory_allocation);
/* This is a stack DCtx, not a user-provided static workspace. Keep the
* original heapmode=0 semantics so legacy decoding is permitted and no
* static-context allocation restrictions leak into the one-shot API. */
initialized->staticSize = 0;
return ZSTD_decompressDCtx(initialized, dst, dstCapacity, src, srcSize);
return ZSTD_rust_decompress_stack_context(initialized, dst, dstCapacity,
src, srcSize);
#endif
}