feat(compress): move parameter update policy to Rust
Move ZSTD_isUpdateAuthorized behind the existing Rust parameter API while retaining the C context-stage checks, diagnostics, and mutation flow. Test Plan: - cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression (187 tests) - cargo clippy for library, benches, and tests - make -B -C lib -j2 lib
This commit is contained in:
@@ -176,6 +176,26 @@ const C_MAX_BLOCK_SIZE: c_int = 1015;
|
||||
const C_REPCODE_RESOLUTION: c_int = 1016;
|
||||
const C_BLOCK_SPLITTER_LEVEL: c_int = 1017;
|
||||
|
||||
#[inline]
|
||||
fn is_update_authorized(param: c_int) -> bool {
|
||||
matches!(
|
||||
param,
|
||||
C_COMPRESSION_LEVEL
|
||||
| C_HASH_LOG
|
||||
| C_CHAIN_LOG
|
||||
| C_SEARCH_LOG
|
||||
| C_MIN_MATCH
|
||||
| C_TARGET_LENGTH
|
||||
| C_STRATEGY
|
||||
| C_BLOCK_SPLITTER_LEVEL
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTD_rust_isUpdateAuthorized(param: c_int) -> c_int {
|
||||
is_update_authorized(param) as c_int
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
unsafe extern "C" {
|
||||
fn ZSTD_rust_cctx_params_is_multithreaded() -> c_int;
|
||||
@@ -974,6 +994,64 @@ mod tests {
|
||||
use std::mem::{align_of, offset_of, size_of, MaybeUninit};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
#[test]
|
||||
fn update_authorization_matches_the_c_parameter_policy() {
|
||||
let authorized = [
|
||||
C_COMPRESSION_LEVEL,
|
||||
C_HASH_LOG,
|
||||
C_CHAIN_LOG,
|
||||
C_SEARCH_LOG,
|
||||
C_MIN_MATCH,
|
||||
C_TARGET_LENGTH,
|
||||
C_STRATEGY,
|
||||
C_BLOCK_SPLITTER_LEVEL,
|
||||
];
|
||||
let unauthorized = [
|
||||
C_FORMAT,
|
||||
C_WINDOW_LOG,
|
||||
C_CONTENT_SIZE_FLAG,
|
||||
C_CHECKSUM_FLAG,
|
||||
C_DICT_ID_FLAG,
|
||||
C_FORCE_MAX_WINDOW,
|
||||
C_NB_WORKERS,
|
||||
C_JOB_SIZE,
|
||||
C_OVERLAP_LOG,
|
||||
C_RSYNCABLE,
|
||||
C_ENABLE_DEDICATED_DICT_SEARCH,
|
||||
C_ENABLE_LDM,
|
||||
C_LDM_HASH_LOG,
|
||||
C_LDM_MIN_MATCH,
|
||||
C_LDM_BUCKET_SIZE_LOG,
|
||||
C_LDM_HASH_RATE_LOG,
|
||||
C_FORCE_ATTACH_DICT,
|
||||
C_LITERAL_COMPRESSION_MODE,
|
||||
C_TARGET_C_BLOCK_SIZE,
|
||||
C_SRC_SIZE_HINT,
|
||||
C_STABLE_IN_BUFFER,
|
||||
C_STABLE_OUT_BUFFER,
|
||||
C_BLOCK_DELIMITERS,
|
||||
C_VALIDATE_SEQUENCES,
|
||||
C_SPLIT_AFTER_SEQUENCES,
|
||||
C_USE_ROW_MATCH_FINDER,
|
||||
C_DETERMINISTIC_REF_PREFIX,
|
||||
C_PREFETCH_CDICT_TABLES,
|
||||
C_ENABLE_SEQ_PRODUCER_FALLBACK,
|
||||
C_MAX_BLOCK_SIZE,
|
||||
C_REPCODE_RESOLUTION,
|
||||
-1,
|
||||
1018,
|
||||
];
|
||||
|
||||
for param in authorized {
|
||||
assert!(is_update_authorized(param));
|
||||
assert_eq!(ZSTD_rust_isUpdateAuthorized(param), 1);
|
||||
}
|
||||
for param in unauthorized {
|
||||
assert!(!is_update_authorized(param));
|
||||
assert_eq!(ZSTD_rust_isUpdateAuthorized(param), 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn private_parameter_mirror_matches_the_c_layout() {
|
||||
let pointer_size = size_of::<usize>();
|
||||
|
||||
Reference in New Issue
Block a user