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:
@@ -340,7 +340,7 @@ unsafe fn clamp_bounds(param: c_int, value: &mut c_int) -> usize {
|
||||
}
|
||||
|
||||
#[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) }
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ unsafe fn init_advanced_impl(params: *mut ZSTD_CCtx_params, zstd_params: ZSTD_pa
|
||||
}
|
||||
|
||||
#[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,
|
||||
zstd_params: ZSTD_parameters,
|
||||
) -> usize {
|
||||
@@ -694,7 +694,7 @@ pub unsafe extern "C" fn ZSTD_rust_createCCtxParams(
|
||||
}
|
||||
|
||||
#[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() {
|
||||
return 0;
|
||||
}
|
||||
@@ -1688,7 +1688,7 @@ mod tests {
|
||||
let params = storage.as_mut_ptr();
|
||||
unsafe {
|
||||
(*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).fParams, zstd_params.fParams);
|
||||
assert_eq!((*params).compressionLevel, NO_CLEVEL);
|
||||
@@ -1720,7 +1720,7 @@ mod tests {
|
||||
fParams: ZSTD_frameParameters::default(),
|
||||
};
|
||||
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)
|
||||
);
|
||||
|
||||
@@ -1734,7 +1734,7 @@ mod tests {
|
||||
let mut invalid_params = valid_params;
|
||||
invalid_params.cParams.minMatch = 2;
|
||||
assert_eq!(
|
||||
unsafe { ZSTD_rust_CCtxParams_init_advanced(params, invalid_params) },
|
||||
unsafe { ZSTD_CCtxParams_init_advanced(params, invalid_params) },
|
||||
ERROR(ZstdErrorCode::ParameterOutOfBound)
|
||||
);
|
||||
unsafe {
|
||||
@@ -1930,8 +1930,8 @@ mod tests {
|
||||
assert!(!params.is_null());
|
||||
assert_eq!((*params).compressionLevel, DEFAULT_CLEVEL);
|
||||
assert_eq!((*params).fParams.contentSizeFlag, 1);
|
||||
assert_eq!(ZSTD_rust_freeCCtxParams(params), 0);
|
||||
assert_eq!(ZSTD_rust_freeCCtxParams(ptr::null_mut()), 0);
|
||||
assert_eq!(ZSTD_freeCCtxParams(params), 0);
|
||||
assert_eq!(ZSTD_freeCCtxParams(ptr::null_mut()), 0);
|
||||
|
||||
let calls = AtomicUsize::new(0);
|
||||
let custom_mem = ZSTD_customMem {
|
||||
@@ -1943,7 +1943,7 @@ mod tests {
|
||||
assert!(!params.is_null());
|
||||
assert_eq!((*params).customMem.opaque, custom_mem.opaque);
|
||||
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!(ZSTD_rust_createCCtxParams(ZSTD_customMem {
|
||||
|
||||
Reference in New Issue
Block a user