refactor(compress): expose CCtx parameter leaves from Rust
The three public CCtx parameter APIs were still implemented as C bodies that only forwarded into Rust symbols. Move ownership of those leaves to the Rust ABI by using the existing public C symbol names directly, while retaining the same signatures, behavior, and linker-visible API names. The neighboring C helpers remain because they carry C-owned configuration or private-state adaptation rather than being pure public forwarders. Test Plan: - `cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check` -- passed. - `cc -fsyntax-only -Ilib -Icommon lib/compress/zstd_compress.c` -- passed. - `git diff --check` and `git diff --cached --check` -- passed. - Heavy cargo, make, and test commands were intentionally not run per scope.
This commit is contained in:
@@ -2001,7 +2001,6 @@ typedef char ZSTD_rust_select_block_compressor_state_layout[
|
|||||||
/* CCtx parameter state is mirrored by rust/src/zstd_compress_params_api.rs.
|
/* CCtx parameter state is mirrored by rust/src/zstd_compress_params_api.rs.
|
||||||
* Rust owns parameter bounds and clamping; C exposes only the
|
* Rust owns parameter bounds and clamping; C exposes only the
|
||||||
* build-configuration values required by that narrow ABI. */
|
* build-configuration values required by that narrow ABI. */
|
||||||
ZSTD_bounds ZSTD_rust_cctx_params_get_bounds(int param);
|
|
||||||
size_t ZSTD_rust_cctx_params_clamp_bounds(int param, int* value);
|
size_t ZSTD_rust_cctx_params_clamp_bounds(int param, int* value);
|
||||||
int ZSTD_rust_cctx_params_within_bounds(int param, int value);
|
int ZSTD_rust_cctx_params_within_bounds(int param, int value);
|
||||||
int ZSTD_rust_cctx_params_is_multithreaded(void);
|
int ZSTD_rust_cctx_params_is_multithreaded(void);
|
||||||
@@ -2009,15 +2008,12 @@ int ZSTD_rust_cctx_params_nb_workers_max(void);
|
|||||||
int ZSTD_rust_cctx_params_job_size_min(void);
|
int ZSTD_rust_cctx_params_job_size_min(void);
|
||||||
int ZSTD_rust_cctx_params_job_size_max(void);
|
int ZSTD_rust_cctx_params_job_size_max(void);
|
||||||
ZSTD_CCtx_params* ZSTD_rust_createCCtxParams(ZSTD_customMem customMem);
|
ZSTD_CCtx_params* ZSTD_rust_createCCtxParams(ZSTD_customMem customMem);
|
||||||
size_t ZSTD_rust_freeCCtxParams(ZSTD_CCtx_params* params);
|
|
||||||
void ZSTD_rust_makeCCtxParamsFromCParams(
|
void ZSTD_rust_makeCCtxParamsFromCParams(
|
||||||
ZSTD_CCtx_params* cctxParams,
|
ZSTD_CCtx_params* cctxParams,
|
||||||
const ZSTD_compressionParameters* cParams);
|
const ZSTD_compressionParameters* cParams);
|
||||||
void ZSTD_rust_CCtxParams_init_internal(
|
void ZSTD_rust_CCtxParams_init_internal(
|
||||||
ZSTD_CCtx_params* cctxParams, const ZSTD_parameters* params,
|
ZSTD_CCtx_params* cctxParams, const ZSTD_parameters* params,
|
||||||
int compressionLevel);
|
int compressionLevel);
|
||||||
size_t ZSTD_rust_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams,
|
|
||||||
ZSTD_parameters params);
|
|
||||||
void ZSTD_rust_CCtxParams_setZstdParams(ZSTD_CCtx_params* cctxParams,
|
void ZSTD_rust_CCtxParams_setZstdParams(ZSTD_CCtx_params* cctxParams,
|
||||||
const ZSTD_parameters* params);
|
const ZSTD_parameters* params);
|
||||||
int ZSTD_useTargetCBlockSize(const ZSTD_CCtx_params* cctxParams);
|
int ZSTD_useTargetCBlockSize(const ZSTD_CCtx_params* cctxParams);
|
||||||
@@ -3584,11 +3580,6 @@ ZSTD_CCtx_params* ZSTD_createCCtxParams(void)
|
|||||||
return ZSTD_rust_createCCtxParams(ZSTD_defaultCMem);
|
return ZSTD_rust_createCCtxParams(ZSTD_defaultCMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params)
|
|
||||||
{
|
|
||||||
return ZSTD_rust_freeCCtxParams(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ZSTD_NO_CLEVEL 0
|
#define ZSTD_NO_CLEVEL 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3606,11 +3597,6 @@ ZSTD_CCtxParams_init_internal(ZSTD_CCtx_params* cctxParams,
|
|||||||
cctxParams->useRowMatchFinder, cctxParams->postBlockSplitter, cctxParams->ldmParams.enableLdm);
|
cctxParams->useRowMatchFinder, cctxParams->postBlockSplitter, cctxParams->ldmParams.enableLdm);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params)
|
|
||||||
{
|
|
||||||
return ZSTD_rust_CCtxParams_init_advanced(cctxParams, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets cctxParams' cParams and fParams from params, but otherwise leaves them alone.
|
* Sets cctxParams' cParams and fParams from params, but otherwise leaves them alone.
|
||||||
* @param params Validated zstd parameters.
|
* @param params Validated zstd parameters.
|
||||||
@@ -3622,11 +3608,6 @@ static void ZSTD_CCtxParams_setZstdParams(
|
|||||||
ZSTD_rust_CCtxParams_setZstdParams(cctxParams, params);
|
ZSTD_rust_CCtxParams_setZstdParams(cctxParams, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
|
|
||||||
{
|
|
||||||
return ZSTD_rust_cctx_params_get_bounds((int)param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ZSTD_rust_cctx_params_is_multithreaded(void)
|
int ZSTD_rust_cctx_params_is_multithreaded(void)
|
||||||
{
|
{
|
||||||
#ifdef ZSTD_MULTITHREAD
|
#ifdef ZSTD_MULTITHREAD
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ unsafe fn clamp_bounds(param: c_int, value: &mut c_int) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn ZSTD_rust_cctx_params_get_bounds(param: c_int) -> ZSTD_bounds {
|
pub unsafe extern "C" fn ZSTD_cParam_getBounds(param: c_int) -> ZSTD_bounds {
|
||||||
unsafe { current_bounds(param) }
|
unsafe { current_bounds(param) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ unsafe fn init_advanced_impl(params: *mut ZSTD_CCtx_params, zstd_params: ZSTD_pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn ZSTD_rust_CCtxParams_init_advanced(
|
pub unsafe extern "C" fn ZSTD_CCtxParams_init_advanced(
|
||||||
params: *mut ZSTD_CCtx_params,
|
params: *mut ZSTD_CCtx_params,
|
||||||
zstd_params: ZSTD_parameters,
|
zstd_params: ZSTD_parameters,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
@@ -694,7 +694,7 @@ pub unsafe extern "C" fn ZSTD_rust_createCCtxParams(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn ZSTD_rust_freeCCtxParams(params: *mut ZSTD_CCtx_params) -> usize {
|
pub unsafe extern "C" fn ZSTD_freeCCtxParams(params: *mut ZSTD_CCtx_params) -> usize {
|
||||||
if params.is_null() {
|
if params.is_null() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1688,7 +1688,7 @@ mod tests {
|
|||||||
let params = storage.as_mut_ptr();
|
let params = storage.as_mut_ptr();
|
||||||
unsafe {
|
unsafe {
|
||||||
(*params).customMem.opaque = ptr::dangling_mut::<c_void>();
|
(*params).customMem.opaque = ptr::dangling_mut::<c_void>();
|
||||||
assert_eq!(ZSTD_rust_CCtxParams_init_advanced(params, zstd_params), 0);
|
assert_eq!(ZSTD_CCtxParams_init_advanced(params, zstd_params), 0);
|
||||||
assert_eq!((*params).cParams, zstd_params.cParams);
|
assert_eq!((*params).cParams, zstd_params.cParams);
|
||||||
assert_eq!((*params).fParams, zstd_params.fParams);
|
assert_eq!((*params).fParams, zstd_params.fParams);
|
||||||
assert_eq!((*params).compressionLevel, NO_CLEVEL);
|
assert_eq!((*params).compressionLevel, NO_CLEVEL);
|
||||||
@@ -1720,7 +1720,7 @@ mod tests {
|
|||||||
fParams: ZSTD_frameParameters::default(),
|
fParams: ZSTD_frameParameters::default(),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
unsafe { ZSTD_rust_CCtxParams_init_advanced(ptr::null_mut(), valid_params) },
|
unsafe { ZSTD_CCtxParams_init_advanced(ptr::null_mut(), valid_params) },
|
||||||
ERROR(ZstdErrorCode::Generic)
|
ERROR(ZstdErrorCode::Generic)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1734,7 +1734,7 @@ mod tests {
|
|||||||
let mut invalid_params = valid_params;
|
let mut invalid_params = valid_params;
|
||||||
invalid_params.cParams.minMatch = 2;
|
invalid_params.cParams.minMatch = 2;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
unsafe { ZSTD_rust_CCtxParams_init_advanced(params, invalid_params) },
|
unsafe { ZSTD_CCtxParams_init_advanced(params, invalid_params) },
|
||||||
ERROR(ZstdErrorCode::ParameterOutOfBound)
|
ERROR(ZstdErrorCode::ParameterOutOfBound)
|
||||||
);
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -1930,8 +1930,8 @@ mod tests {
|
|||||||
assert!(!params.is_null());
|
assert!(!params.is_null());
|
||||||
assert_eq!((*params).compressionLevel, DEFAULT_CLEVEL);
|
assert_eq!((*params).compressionLevel, DEFAULT_CLEVEL);
|
||||||
assert_eq!((*params).fParams.contentSizeFlag, 1);
|
assert_eq!((*params).fParams.contentSizeFlag, 1);
|
||||||
assert_eq!(ZSTD_rust_freeCCtxParams(params), 0);
|
assert_eq!(ZSTD_freeCCtxParams(params), 0);
|
||||||
assert_eq!(ZSTD_rust_freeCCtxParams(ptr::null_mut()), 0);
|
assert_eq!(ZSTD_freeCCtxParams(ptr::null_mut()), 0);
|
||||||
|
|
||||||
let calls = AtomicUsize::new(0);
|
let calls = AtomicUsize::new(0);
|
||||||
let custom_mem = ZSTD_customMem {
|
let custom_mem = ZSTD_customMem {
|
||||||
@@ -1943,7 +1943,7 @@ mod tests {
|
|||||||
assert!(!params.is_null());
|
assert!(!params.is_null());
|
||||||
assert_eq!((*params).customMem.opaque, custom_mem.opaque);
|
assert_eq!((*params).customMem.opaque, custom_mem.opaque);
|
||||||
assert_eq!(calls.load(Ordering::Relaxed), 1);
|
assert_eq!(calls.load(Ordering::Relaxed), 1);
|
||||||
assert_eq!(ZSTD_rust_freeCCtxParams(params), 0);
|
assert_eq!(ZSTD_freeCCtxParams(params), 0);
|
||||||
assert_eq!(calls.load(Ordering::Relaxed), 2);
|
assert_eq!(calls.load(Ordering::Relaxed), 2);
|
||||||
|
|
||||||
assert!(ZSTD_rust_createCCtxParams(ZSTD_customMem {
|
assert!(ZSTD_rust_createCCtxParams(ZSTD_customMem {
|
||||||
|
|||||||
Reference in New Issue
Block a user