feat(decompress): invoke trace hooks from Rust

Keep weak-symbol discovery and private dctx/ddict extraction in the C adapter,
but project the exact trace callback types into Rust and invoke them from the
Rust trace lifecycle. Preserve the nullable-hook behavior, trace context
width, dictionary-cold timing, record field layout, size conversions, and the
no-trace build path. Add focused Rust policy tests for callback, record, and
null-projection behavior.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --manifest-path rust/Cargo.toml --tests
- ulimit -v 41943040; make -j1
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
2026-07-21 19:58:11 +02:00
parent 8597c9c4aa
commit 09abf02049
2 changed files with 55 additions and 28 deletions
+9 -20
View File
@@ -116,15 +116,21 @@ typedef char ZSTD_rust_dctx_view_layout[
* representation instead of U64, whose typedef may be a different C type on
* some targets even when it has the same width. */
typedef unsigned long long ZSTD_rustTraceCtx;
#if ZSTD_TRACE
typedef ZSTD_rustTraceCtx (*ZSTD_rustTraceBeginFn)(const ZSTD_DCtx* dctx);
typedef void (*ZSTD_rustTraceEndFn)(ZSTD_rustTraceCtx traceCtx,
const ZSTD_Trace* trace);
#else
typedef ZSTD_rustTraceCtx (*ZSTD_rustTraceBeginFn)(const void* dctx);
typedef void (*ZSTD_rustTraceEndFn)(ZSTD_rustTraceCtx traceCtx,
const void* trace);
#endif
typedef struct {
ZSTD_rustTraceCtx* trace_ctx;
ZSTD_rustTraceBeginFn begin;
ZSTD_rustTraceEndFn end;
const void* dctx;
const ZSTD_DCtx* dctx;
const void* ddict;
int dictionary_is_cold;
} ZSTD_rustDctxTraceView;
@@ -226,23 +232,6 @@ unsigned ZSTD_rust_legacy_support_policy(
const ZSTD_rustLegacySupportProjection* projection);
unsigned ZSTD_rust_legacy_support(void);
#if ZSTD_TRACE
static ZSTD_rustTraceCtx ZSTD_rust_trace_begin_callback(const void* dctx)
{
return (ZSTD_trace_decompress_begin != NULL)
? ZSTD_trace_decompress_begin((const ZSTD_DCtx*)dctx) : 0;
}
static void ZSTD_rust_trace_end_callback(ZSTD_rustTraceCtx traceCtx,
const void* trace)
{
if (ZSTD_trace_decompress_end != NULL) {
ZSTD_trace_decompress_end((ZSTD_TraceCtx)traceCtx,
(const ZSTD_Trace*)trace);
}
}
#endif
void ZSTD_rust_dctx_view(ZSTD_DCtx* dctx, ZSTD_rustDctxView* out)
{
ZSTD_memset(out, 0, sizeof(*out));
@@ -389,9 +378,9 @@ void ZSTD_rust_dctx_trace_view(ZSTD_DCtx* dctx,
#if ZSTD_TRACE
out->trace_ctx = &dctx->traceCtx;
out->begin = (ZSTD_trace_decompress_begin != NULL)
? ZSTD_rust_trace_begin_callback : NULL;
? ZSTD_trace_decompress_begin : NULL;
out->end = (ZSTD_trace_decompress_end != NULL)
? ZSTD_rust_trace_end_callback : NULL;
? ZSTD_trace_decompress_end : NULL;
out->ddict = dctx->ddict;
out->dictionary_is_cold = dctx->ddictIsCold;
#endif