feat(cli): move dictionary release dispatch into Rust
Route FIO_freeDict through the Rust filesystem backend for malloc-backed and mapped dictionaries. Keep enum validation in C, pair Windows views with their file handles, support the non-POSIX malloc fallback, and clear every ownership field so repeated cleanup remains harmless. Test Plan: - cargo test --manifest-path rust/cli/Cargo.toml --lib fileio_backend -- --test-threads=1 (25 passed) - cargo clippy --manifest-path rust/cli/Cargo.toml --lib -- -D warnings - rustfmt +nightly --edition 2021 rust/src/fileio_backend.rs --check - make -C programs -j2 zstd - git diff --check
This commit is contained in:
+20
-23
@@ -380,8 +380,11 @@ int FIO_rust_setDictBufferMMap(const char* fileName,
|
||||
void** buffer,
|
||||
size_t* mappedSize,
|
||||
void** dictHandle);
|
||||
void FIO_rust_munmapDict(void** buffer, size_t* bufferSize, void** dictHandle);
|
||||
#endif
|
||||
void FIO_rust_freeDict(int dictBufferType,
|
||||
void** buffer,
|
||||
size_t* bufferSize,
|
||||
void** dictHandle);
|
||||
int FIO_rust_removeFile(const char* path);
|
||||
int FIO_rust_passThrough(ReadPoolCtx_t* readCtx, WritePoolCtx_t* writeCtx);
|
||||
#ifdef ZSTD_LZ4COMPRESS
|
||||
@@ -656,10 +659,6 @@ static size_t FIO_setDictBufferMalloc(FIO_Dict_t* dict, const char* fileName, FI
|
||||
}
|
||||
|
||||
#if (PLATFORM_POSIX_VERSION > 0)
|
||||
static void FIO_munmap(FIO_Dict_t* dict)
|
||||
{
|
||||
FIO_rust_munmapDict(&dict->dictBuffer, &dict->dictBufferSize, NULL);
|
||||
}
|
||||
static size_t FIO_setDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_prefs_t* const prefs, stat_t* dictFileStat)
|
||||
{
|
||||
U64 fileSize;
|
||||
@@ -701,12 +700,6 @@ static size_t FIO_setDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_
|
||||
return 0;
|
||||
}
|
||||
#elif defined(_MSC_VER) || defined(_WIN32)
|
||||
static void FIO_munmap(FIO_Dict_t* dict)
|
||||
{
|
||||
FIO_rust_munmapDict(&dict->dictBuffer,
|
||||
&dict->dictBufferSize,
|
||||
(void**)&dict->dictHandle);
|
||||
}
|
||||
static size_t FIO_setDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_prefs_t* const prefs, stat_t* dictFileStat)
|
||||
{
|
||||
U64 fileSize;
|
||||
@@ -755,26 +748,30 @@ static size_t FIO_setDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_
|
||||
{
|
||||
return FIO_setDictBufferMalloc(dict, fileName, prefs, dictFileStat);
|
||||
}
|
||||
static void FIO_munmap(FIO_Dict_t* dict) {
|
||||
free(dict->dictBuffer);
|
||||
dict->dictBuffer = NULL;
|
||||
dict->dictBufferSize = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void FIO_freeDict(FIO_Dict_t* dict) {
|
||||
if (dict->dictBufferType == FIO_mallocDict) {
|
||||
free(dict->dictBuffer);
|
||||
dict->dictBuffer = NULL;
|
||||
dict->dictBufferSize = 0;
|
||||
} else if (dict->dictBufferType == FIO_mmapDict) {
|
||||
FIO_munmap(dict);
|
||||
} else {
|
||||
if (dict->dictBufferType != FIO_mallocDict
|
||||
&& dict->dictBufferType != FIO_mmapDict) {
|
||||
assert(0); /* Should not reach this case */
|
||||
return;
|
||||
}
|
||||
|
||||
FIO_rust_freeDict((int)dict->dictBufferType,
|
||||
&dict->dictBuffer,
|
||||
&dict->dictBufferSize,
|
||||
#if defined(_MSC_VER) || defined(_WIN32)
|
||||
(void**)&dict->dictHandle
|
||||
#else
|
||||
NULL
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
static void FIO_initDict(FIO_Dict_t* dict, const char* fileName, FIO_prefs_t* const prefs, stat_t* dictFileStat, FIO_dictBufferType_t dictBufferType) {
|
||||
#if defined(_MSC_VER) || defined(_WIN32)
|
||||
dict->dictHandle = NULL;
|
||||
#endif
|
||||
dict->dictBufferType = dictBufferType;
|
||||
if (dict->dictBufferType == FIO_mallocDict) {
|
||||
dict->dictBufferSize = FIO_setDictBufferMalloc(dict, fileName, prefs, dictFileStat);
|
||||
|
||||
Reference in New Issue
Block a user