feat(compress): move trace context reset to Rust

Keep the C-owned trace slot behind an explicit pointer projection so the
Rust trace boundary owns the complete enabled-call lifecycle. Rust now reads
the context, publishes the record, and clears the slot after the callback;
C only supplies private CCtx fields and the weak callback adapter.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --tests (rust)
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --tests -- -A clippy::manual-bits -D warnings (rust)
- ulimit -v 41943040; make -j1
- ulimit -v 41943040; make -j1 -C tests test
- Focused trace lifecycle test added; standalone cargo test remains link-blocked by the existing C-owned decompression view symbols.
This commit is contained in:
2026-07-21 23:37:03 +02:00
parent 9589c5e327
commit c7789446dc
2 changed files with 57 additions and 9 deletions
+2 -3
View File
@@ -7362,7 +7362,7 @@ typedef void (*ZSTD_rust_traceEnd_f)(
void* context, unsigned long long traceCtx, const void* trace);
typedef struct {
void* callbackContext;
unsigned long long traceCtx;
unsigned long long* traceCtx;
int streaming;
unsigned dictionaryID;
size_t dictionarySize;
@@ -7413,7 +7413,7 @@ void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize)
#if ZSTD_TRACE
ZSTD_rust_traceEndState state;
state.callbackContext = cctx;
state.traceCtx = cctx->traceCtx;
state.traceCtx = &cctx->traceCtx;
state.streaming = cctx->inBuffSize > 0 || cctx->outBuffSize > 0
|| cctx->appliedParams.nbWorkers > 0;
state.dictionaryID = cctx->dictID;
@@ -7424,7 +7424,6 @@ void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize)
state.cctx = cctx;
state.traceEnd = ZSTD_rust_traceEnd_callback;
ZSTD_rust_traceEnd(&state);
cctx->traceCtx = 0;
#else
(void)cctx;
(void)extraCSize;