feat(cli): move patch memory-limit policy to Rust
Move patch-from memory-limit sizing and rejection status selection behind a Rust ABI shim. Keep the C diagnostics and assertion in place, and leave the existing preference unchanged when input sizes are unknown or exceed the window limit. Test Plan: - cargo test --manifest-path rust/cli/Cargo.toml --no-default-features --features cli,compression,decompression,benchmark (113 tests) - cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets with the CLI feature set - make -B -C programs -j2 zstd zstd-small zstd-frugal - make -C tests -j2 test-cli-tests (41 scenarios) and make -B -C tests -j2 test-zstream
This commit is contained in:
+13
-5
@@ -315,6 +315,9 @@ void FIO_rust_setOutBuffer(ZSTD_outBuffer* output, void* buf, size_t s, size_t p
|
||||
const char* FIO_rust_determineCompressedName(const char* srcFileName, const char* outDirName, const char* suffix);
|
||||
const char* FIO_rust_determineDstName(const char* srcFileName, const char* outDirName,
|
||||
const char* const* suffixList, const char* suffixListStr);
|
||||
int FIO_rust_adjustMemLimitForPatchFromMode(FIO_prefs_t* prefs,
|
||||
unsigned long long dictSize,
|
||||
unsigned long long maxSrcFileSize);
|
||||
#ifdef ZSTD_LZ4COMPRESS
|
||||
int FIO_rust_LZ4_GetBlockSize_FromBlockId(int id);
|
||||
#endif
|
||||
@@ -707,14 +710,19 @@ static void FIO_adjustMemLimitForPatchFromMode(FIO_prefs_t* const prefs,
|
||||
unsigned long long const dictSize,
|
||||
unsigned long long const maxSrcFileSize)
|
||||
{
|
||||
unsigned long long maxSize = MAX(prefs->memLimit, MAX(dictSize, maxSrcFileSize));
|
||||
enum {
|
||||
FIO_PATCH_MEM_LIMIT_SUCCESS = 0,
|
||||
FIO_PATCH_MEM_LIMIT_UNKNOWN_SIZE = 1,
|
||||
FIO_PATCH_MEM_LIMIT_TOO_LARGE = 2
|
||||
};
|
||||
unsigned const maxWindowSize = (1U << ZSTD_WINDOWLOG_MAX);
|
||||
if (maxSize == UTIL_FILESIZE_UNKNOWN)
|
||||
|
||||
int const status = FIO_rust_adjustMemLimitForPatchFromMode(prefs, dictSize, maxSrcFileSize);
|
||||
if (status == FIO_PATCH_MEM_LIMIT_UNKNOWN_SIZE)
|
||||
EXM_THROW(42, "Using --patch-from with stdin requires --stream-size");
|
||||
assert(maxSize != UTIL_FILESIZE_UNKNOWN);
|
||||
if (maxSize > maxWindowSize)
|
||||
if (status == FIO_PATCH_MEM_LIMIT_TOO_LARGE)
|
||||
EXM_THROW(42, "Can't handle files larger than %u GB\n", maxWindowSize/(1 GB));
|
||||
FIO_setMemLimit(prefs, (unsigned)maxSize);
|
||||
assert(status == FIO_PATCH_MEM_LIMIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* FIO_multiFilesConcatWarning() :
|
||||
|
||||
Reference in New Issue
Block a user