refactor(compress): expose stream size and level leaves from Rust

Move the public stream-size and predefined compression-level leaves to their
caller-facing Rust symbols, removing the remaining C-only forwarding bodies.
Keep crate-local aliases where Rust implementation modules still use the old
internal names, while the public C ABI now lands directly in Rust.

Test Plan: Nightly Rust formatting and staged diff checks passed; capped native and upstream gates pending.
This commit is contained in:
2026-07-20 11:18:44 +02:00
parent c8603f2b3e
commit 58606b18aa
3 changed files with 14 additions and 26 deletions
+5 -5
View File
@@ -45,13 +45,13 @@ pub extern "C" fn ZSTD_compressBound(src_size: usize) -> usize {
/// Returns the recommended input buffer size for the public streaming API.
#[no_mangle]
pub extern "C" fn ZSTD_rust_CStreamInSize() -> usize {
pub extern "C" fn ZSTD_CStreamInSize() -> usize {
ZSTD_BLOCKSIZE_MAX
}
/// Returns the recommended output buffer size for the public streaming API.
#[no_mangle]
pub extern "C" fn ZSTD_rust_CStreamOutSize() -> usize {
pub extern "C" fn ZSTD_CStreamOutSize() -> usize {
ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_BLOCK_HEADER_SIZE + 4
}
@@ -105,12 +105,12 @@ mod tests {
#[test]
fn cstream_sizes_match_the_public_formulas() {
assert_eq!(ZSTD_rust_CStreamInSize(), 128 * 1024);
assert_eq!(ZSTD_CStreamInSize(), 128 * 1024);
assert_eq!(
ZSTD_rust_CStreamOutSize(),
ZSTD_CStreamOutSize(),
ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_BLOCK_HEADER_SIZE + 4
);
assert_eq!(ZSTD_rust_CStreamOutSize(), 131_591);
assert_eq!(ZSTD_CStreamOutSize(), 131_591);
}
#[test]
+9 -5
View File
@@ -344,7 +344,7 @@ fn cparams_from_row(row: [u32; 7]) -> ZSTD_compressionParameters {
#[inline]
fn bounds(param: c_int) -> ZSTD_bounds {
let (lowerBound, upperBound) = match param {
ZSTD_C_COMPRESSION_LEVEL => (ZSTD_rust_params_minCLevel(), ZSTD_rust_params_maxCLevel()),
ZSTD_C_COMPRESSION_LEVEL => (ZSTD_minCLevel(), ZSTD_maxCLevel()),
ZSTD_C_WINDOW_LOG => (ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX),
ZSTD_C_HASH_LOG => (ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX),
ZSTD_C_CHAIN_LOG => (ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX),
@@ -937,7 +937,7 @@ fn select_cparams(
let mut cparams = cparams_from_row(DEFAULT_CPARAMS[table_id][row]);
if compression_level < 0 {
let clamped = compression_level.max(ZSTD_rust_params_minCLevel());
let clamped = compression_level.max(ZSTD_minCLevel());
cparams.targetLength = (-clamped) as u32;
}
cparams
@@ -1119,22 +1119,26 @@ fn assert_equal_cparams(
/// Returns the highest table-backed compression level (`ZSTD_MAX_CLEVEL`).
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_maxCLevel() -> c_int {
pub extern "C" fn ZSTD_maxCLevel() -> c_int {
ZSTD_MAX_CLEVEL
}
/// Returns the lowest public fast level (`-ZSTD_TARGETLENGTH_MAX`).
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_minCLevel() -> c_int {
pub extern "C" fn ZSTD_minCLevel() -> c_int {
-ZSTD_TARGETLENGTH_MAX
}
/// Returns the default compression level from `zstd.h`.
#[no_mangle]
pub extern "C" fn ZSTD_rust_params_defaultCLevel() -> c_int {
pub extern "C" fn ZSTD_defaultCLevel() -> c_int {
ZSTD_CLEVEL_DEFAULT
}
/* Keep existing Rust parameter-module callers source-compatible while the
* public C symbols are owned directly by these Rust leaves. */
pub(crate) use ZSTD_defaultCLevel as ZSTD_rust_params_defaultCLevel;
/// Returns bounds for the seven core compression parameters and compression
/// level. Other `ZSTD_cParameter` cases remain C-owned.
#[no_mangle]