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:
@@ -1554,8 +1554,6 @@ typedef char ZSTD_rust_next_input_size_hint_mt_or_st_state_layout[
|
||||
? 1 : -1];
|
||||
size_t ZSTD_rust_nextInputSizeHintMTorST(
|
||||
const ZSTD_rust_nextInputSizeHintMTorSTState* state);
|
||||
size_t ZSTD_rust_CStreamInSize(void);
|
||||
size_t ZSTD_rust_CStreamOutSize(void);
|
||||
size_t ZSTD_rust_sizeofCDict(size_t objectSize, size_t workspaceSize);
|
||||
size_t ZSTD_rust_sizeofLocalDict(int dictBufferPresent, size_t dictSize,
|
||||
size_t cdictSize);
|
||||
@@ -1925,9 +1923,6 @@ void ZSTD_rust_setBufferExpectations(
|
||||
* sanitizer workspace policy, which it feeds to the leaves as explicit
|
||||
* scalar inputs. The ZSTD_CParamMode_e and ZSTD_ParamSwitch_e enums are
|
||||
* passed as int; the Rust side mirrors their values. */
|
||||
int ZSTD_rust_params_maxCLevel(void);
|
||||
int ZSTD_rust_params_minCLevel(void);
|
||||
int ZSTD_rust_params_defaultCLevel(void);
|
||||
ZSTD_bounds ZSTD_rust_params_getBounds(int param);
|
||||
size_t ZSTD_rust_params_checkCParams(ZSTD_compressionParameters cParams);
|
||||
void ZSTD_rust_params_assertEqualCParams(ZSTD_compressionParameters cParams1,
|
||||
@@ -7547,13 +7542,6 @@ size_t ZSTD_freeCStream(ZSTD_CStream* zcs)
|
||||
|
||||
/*====== Initialization ======*/
|
||||
|
||||
size_t ZSTD_CStreamInSize(void) { return ZSTD_rust_CStreamInSize(); }
|
||||
|
||||
size_t ZSTD_CStreamOutSize(void)
|
||||
{
|
||||
return ZSTD_rust_CStreamOutSize();
|
||||
}
|
||||
|
||||
static ZSTD_CParamMode_e ZSTD_getCParamMode(ZSTD_CDict const* cdict, ZSTD_CCtx_params const* params, U64 pledgedSrcSize)
|
||||
{
|
||||
int const cdict_present = cdict != NULL;
|
||||
@@ -8653,10 +8641,6 @@ size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output)
|
||||
/* The compression-level tables (formerly included from clevels.h) live in
|
||||
* rust/src/zstd_compress_params.rs. */
|
||||
|
||||
int ZSTD_maxCLevel(void) { return ZSTD_rust_params_maxCLevel(); }
|
||||
int ZSTD_minCLevel(void) { return ZSTD_rust_params_minCLevel(); }
|
||||
int ZSTD_defaultCLevel(void) { return ZSTD_rust_params_defaultCLevel(); }
|
||||
|
||||
/**
|
||||
* Reverses the adjustment applied to cparams when enabling dedicated dict
|
||||
* search. This is used to recover the params set to be used in the working
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user