refactor(fileio): move compression teardown order to Rust
Keep fileio's compression-resource teardown order in the Rust policy layer: dictionary, write pool, read pool, then compression context. The C adapter keeps cRess_t and each private resource layout local while exposing only one callback projection to Rust, preserving the existing cleanup behavior. The Rust entry point also treats a null state as a no-op and verifies the projection layout at compile time. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml free_c_resources --lib - ulimit -v 41943040; make -j1 - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings
This commit is contained in:
+53
-4
@@ -1820,12 +1820,61 @@ static cRess_t FIO_createCResources(FIO_prefs_t* const prefs,
|
||||
return ress;
|
||||
}
|
||||
|
||||
typedef void (*FIO_rust_freeCResourcesCallback_f)(void* context);
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
FIO_rust_freeCResourcesCallback_f freeDict;
|
||||
FIO_rust_freeCResourcesCallback_f freeWritePool;
|
||||
FIO_rust_freeCResourcesCallback_f freeReadPool;
|
||||
FIO_rust_freeCResourcesCallback_f freeCctx;
|
||||
} FIO_rust_freeCResourcesState;
|
||||
typedef char FIO_rust_free_c_resources_state_layout[
|
||||
(offsetof(FIO_rust_freeCResourcesState, callbackContext) == 0
|
||||
&& offsetof(FIO_rust_freeCResourcesState, freeDict) == sizeof(void*)
|
||||
&& offsetof(FIO_rust_freeCResourcesState, freeWritePool)
|
||||
== 2 * sizeof(void*)
|
||||
&& offsetof(FIO_rust_freeCResourcesState, freeReadPool)
|
||||
== 3 * sizeof(void*)
|
||||
&& offsetof(FIO_rust_freeCResourcesState, freeCctx)
|
||||
== 4 * sizeof(void*)
|
||||
&& sizeof(FIO_rust_freeCResourcesState) == 5 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
void FIO_rust_freeCResources(const FIO_rust_freeCResourcesState* state);
|
||||
|
||||
static void FIO_rust_freeCResources_dict(void* context)
|
||||
{
|
||||
cRess_t* const ress = (cRess_t*)context;
|
||||
FIO_freeDict(&(ress->dict));
|
||||
}
|
||||
|
||||
static void FIO_rust_freeCResources_writePool(void* context)
|
||||
{
|
||||
cRess_t* const ress = (cRess_t*)context;
|
||||
AIO_WritePool_free(ress->writeCtx);
|
||||
}
|
||||
|
||||
static void FIO_rust_freeCResources_readPool(void* context)
|
||||
{
|
||||
cRess_t* const ress = (cRess_t*)context;
|
||||
AIO_ReadPool_free(ress->readCtx);
|
||||
}
|
||||
|
||||
static void FIO_rust_freeCResources_cctx(void* context)
|
||||
{
|
||||
cRess_t* const ress = (cRess_t*)context;
|
||||
ZSTD_freeCStream(ress->cctx); /* never fails */
|
||||
}
|
||||
|
||||
static void FIO_freeCResources(cRess_t* const ress)
|
||||
{
|
||||
FIO_freeDict(&(ress->dict));
|
||||
AIO_WritePool_free(ress->writeCtx);
|
||||
AIO_ReadPool_free(ress->readCtx);
|
||||
ZSTD_freeCStream(ress->cctx); /* never fails */
|
||||
FIO_rust_freeCResourcesState const state = {
|
||||
ress,
|
||||
FIO_rust_freeCResources_dict,
|
||||
FIO_rust_freeCResources_writePool,
|
||||
FIO_rust_freeCResources_readPool,
|
||||
FIO_rust_freeCResources_cctx
|
||||
};
|
||||
FIO_rust_freeCResources(&state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user