refactor(fileio): move decompression teardown order to Rust
Project the decompression-resource cleanup callbacks into Rust so the stable teardown order remains dictionary, dstream, write pool, and read pool. C retains ownership of dRess_t and each private resource implementation, with its existing dstream CHECK behavior preserved. Focused tests cover order and null or incomplete callback states. All heavy verification was run serially with a 40 GiB virtual-memory cap and one build job. Test Plan: - git diff --cached --check - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --all-targets (788 passed) - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets (181 passed) - ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check - ulimit -v 41943040; make -j1 - ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
+53
-4
@@ -3648,6 +3648,51 @@ typedef struct {
|
||||
ReadPoolCtx_t *readCtx;
|
||||
} dRess_t;
|
||||
|
||||
typedef void (*FIO_rust_freeDResourcesCallback_f)(void* context);
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
FIO_rust_freeDResourcesCallback_f freeDict;
|
||||
FIO_rust_freeDResourcesCallback_f freeDctx;
|
||||
FIO_rust_freeDResourcesCallback_f freeWritePool;
|
||||
FIO_rust_freeDResourcesCallback_f freeReadPool;
|
||||
} FIO_rust_freeDResourcesState;
|
||||
typedef char FIO_rust_free_d_resources_state_layout[
|
||||
(offsetof(FIO_rust_freeDResourcesState, callbackContext) == 0
|
||||
&& offsetof(FIO_rust_freeDResourcesState, freeDict) == sizeof(void*)
|
||||
&& offsetof(FIO_rust_freeDResourcesState, freeDctx)
|
||||
== 2 * sizeof(void*)
|
||||
&& offsetof(FIO_rust_freeDResourcesState, freeWritePool)
|
||||
== 3 * sizeof(void*)
|
||||
&& offsetof(FIO_rust_freeDResourcesState, freeReadPool)
|
||||
== 4 * sizeof(void*)
|
||||
&& sizeof(FIO_rust_freeDResourcesState) == 5 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
void FIO_rust_freeDResources(const FIO_rust_freeDResourcesState* state);
|
||||
|
||||
static void FIO_rust_freeDResources_dict(void* context)
|
||||
{
|
||||
dRess_t* const ress = (dRess_t*)context;
|
||||
FIO_freeDict(&(ress->dict));
|
||||
}
|
||||
|
||||
static void FIO_rust_freeDResources_dctx(void* context)
|
||||
{
|
||||
dRess_t* const ress = (dRess_t*)context;
|
||||
CHECK( ZSTD_freeDStream(ress->dctx) );
|
||||
}
|
||||
|
||||
static void FIO_rust_freeDResources_writePool(void* context)
|
||||
{
|
||||
dRess_t* const ress = (dRess_t*)context;
|
||||
AIO_WritePool_free(ress->writeCtx);
|
||||
}
|
||||
|
||||
static void FIO_rust_freeDResources_readPool(void* context)
|
||||
{
|
||||
dRess_t* const ress = (dRess_t*)context;
|
||||
AIO_ReadPool_free(ress->readCtx);
|
||||
}
|
||||
|
||||
static dRess_t FIO_createDResources(FIO_prefs_t* const prefs, const char* dictFileName)
|
||||
{
|
||||
int useMMap = prefs->mmapDict == ZSTD_ps_enable;
|
||||
@@ -3693,10 +3738,14 @@ static dRess_t FIO_createDResources(FIO_prefs_t* const prefs, const char* dictFi
|
||||
|
||||
static void FIO_freeDResources(dRess_t ress)
|
||||
{
|
||||
FIO_freeDict(&(ress.dict));
|
||||
CHECK( ZSTD_freeDStream(ress.dctx) );
|
||||
AIO_WritePool_free(ress.writeCtx);
|
||||
AIO_ReadPool_free(ress.readCtx);
|
||||
FIO_rust_freeDResourcesState const state = {
|
||||
&ress,
|
||||
FIO_rust_freeDResources_dict,
|
||||
FIO_rust_freeDResources_dctx,
|
||||
FIO_rust_freeDResources_writePool,
|
||||
FIO_rust_freeDResources_readPool
|
||||
};
|
||||
FIO_rust_freeDResources(&state);
|
||||
}
|
||||
|
||||
/* FIO_passThrough() : just copy input into output, for compatibility with gzip -df mode
|
||||
|
||||
Reference in New Issue
Block a user