refactor(cli): derive window error log in Rust

Move the historical ceil(log2(windowSize)) calculation used by
FIO_zstdErrorHelp into Rust. C retains frame-header parsing, private read-pool
access, the ABI slot, callbacks, diagnostics, and output formatting. The
zero-size and non-power-of-two behavior remains explicit and tested at the
u64 boundary.

Test Plan:
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings` -- passed
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings` -- passed
- `ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` -- passed
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets` -- passed, 190 tests
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1` -- passed
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 ./tests/rustLibSmoke` -- passed
- `ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1 -C tests test` -- passed, including large streaming, native, fuzzer, and zstream phases
This commit is contained in:
2026-07-20 19:29:56 +02:00
parent e9850abbb7
commit a152fe6498
2 changed files with 48 additions and 17 deletions
+1 -5
View File
@@ -3654,7 +3654,7 @@ typedef struct {
const char* srcFileName;
unsigned long long windowSize;
size_t headerError;
unsigned windowLog;
unsigned windowLog; /* Rust derives this from windowSize; retain ABI layout. */
unsigned memLimit;
int errorCode;
FIO_rust_zstdErrorHelpDisplayFn display;
@@ -3725,7 +3725,6 @@ FIO_zstdErrorHelp(const FIO_prefs_t* const prefs,
int const errorCode = (int)ZSTD_getErrorCode(err);
size_t headerError = 1;
unsigned long long windowSize = 0;
unsigned windowLog = 0;
unsigned memLimit = 0;
FIO_rust_zstdErrorHelpState state = { 0 };
@@ -3735,8 +3734,6 @@ FIO_zstdErrorHelp(const FIO_prefs_t* const prefs,
&header, ress->readCtx->srcBuffer, ress->readCtx->srcBufferLoaded);
if (headerError == 0) {
windowSize = header.windowSize;
windowLog = FIO_highbit64(windowSize)
+ ((windowSize & (windowSize - 1)) != 0);
memLimit = prefs->memLimit;
}
}
@@ -3745,7 +3742,6 @@ FIO_zstdErrorHelp(const FIO_prefs_t* const prefs,
state.srcFileName = srcFileName;
state.windowSize = windowSize;
state.headerError = headerError;
state.windowLog = windowLog;
state.memLimit = memLimit;
state.errorCode = errorCode;
state.display = FIO_rust_zstdErrorHelp_display;