feat(compress): move external sequence store reset into Rust

Move the mutable external raw-sequence-store assignment and cursor reset
behind a Rust-owned pointer projection. Keep the public C entry point and
its stage/LDM assertions in C, without exposing RawSeqStore_t to Rust.

Test Plan:
- cargo test --manifest-path rust/Cargo.toml --lib
- cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- make -B -C programs -j1 zstd
- make -C tests -j1 test-zstream ZSTREAM_TESTTIME=-T1s
- focused reference_external_sequences unit tests
This commit is contained in:
2026-07-19 14:48:30 +02:00
parent 9a68253710
commit 814b7af16d
2 changed files with 130 additions and 5 deletions
+33 -5
View File
@@ -1390,6 +1390,30 @@ typedef char ZSTD_rust_external_sequence_producer_state_layout[
== 13 * sizeof(void*))
? 1 : -1];
typedef struct {
rawSeq** seq;
size_t* pos;
size_t* posInSequence;
size_t* size;
size_t* capacity;
} ZSTD_rust_externalSequenceStoreState;
void ZSTD_rust_referenceExternalSequences(
const ZSTD_rust_externalSequenceStoreState* state,
rawSeq* seq, size_t nbSeq);
typedef char ZSTD_rust_external_sequence_store_state_layout[
(offsetof(ZSTD_rust_externalSequenceStoreState, seq) == 0
&& offsetof(ZSTD_rust_externalSequenceStoreState, pos)
== sizeof(void*)
&& offsetof(ZSTD_rust_externalSequenceStoreState, posInSequence)
== 2 * sizeof(void*)
&& offsetof(ZSTD_rust_externalSequenceStoreState, size)
== 3 * sizeof(void*)
&& offsetof(ZSTD_rust_externalSequenceStoreState, capacity)
== 4 * sizeof(void*)
&& sizeof(ZSTD_rust_externalSequenceStoreState)
== 5 * sizeof(void*))
? 1 : -1];
/* The sequence-compression loop receives only the state it actually reads or
* updates. In particular, neither ZSTD_CCtx nor a C function pointer crosses
* the Rust ABI. */
@@ -4066,11 +4090,15 @@ void ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSeq)
{
assert(cctx->stage == ZSTDcs_init);
assert(nbSeq == 0 || cctx->appliedParams.ldmParams.enableLdm != ZSTD_ps_enable);
cctx->externSeqStore.seq = seq;
cctx->externSeqStore.size = nbSeq;
cctx->externSeqStore.capacity = nbSeq;
cctx->externSeqStore.pos = 0;
cctx->externSeqStore.posInSequence = 0;
{
ZSTD_rust_externalSequenceStoreState state;
state.seq = &cctx->externSeqStore.seq;
state.pos = &cctx->externSeqStore.pos;
state.posInSequence = &cctx->externSeqStore.posInSequence;
state.size = &cctx->externSeqStore.size;
state.capacity = &cctx->externSeqStore.capacity;
ZSTD_rust_referenceExternalSequences(&state, seq, nbSeq);
}
}