diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 491b8bae6..b05f02dc5 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2877,7 +2877,8 @@ typedef void* (*ZSTD_rust_initCDictReserveEntropy_f)( void* context, size_t workspaceSize); typedef size_t (*ZSTD_rust_initCDictResetMatchState_f)( void* context, const ZSTD_compressionParameters* cParams, - int useRowMatchFinder); + int useRowMatchFinder, int compResetPolicy, + int indexResetPolicy, int resetTarget); typedef size_t (*ZSTD_rust_initCDictInsertDictionary_f)( void* context, const void* params, const void* dict, size_t dictSize, int dictContentType, int dtlm, int tfp); @@ -6696,13 +6697,16 @@ static void* ZSTD_rust_initCDict_reserveEntropy( static size_t ZSTD_rust_initCDict_resetMatchState( void* context, const ZSTD_compressionParameters* cParams, - int useRowMatchFinder) + int useRowMatchFinder, int compResetPolicy, + int indexResetPolicy, int resetTarget) { ZSTD_CDict* const cdict = (ZSTD_CDict*)context; return ZSTD_reset_matchState( &cdict->matchState, &cdict->workspace, cParams, (ZSTD_ParamSwitch_e)useRowMatchFinder, - ZSTDcrp_makeClean, ZSTDirp_reset, ZSTD_resetTarget_CDict); + (ZSTD_compResetPolicy_e)compResetPolicy, + (ZSTD_indexResetPolicy_e)indexResetPolicy, + (ZSTD_resetTarget_e)resetTarget); } static size_t ZSTD_rust_initCDict_insertDictionary( diff --git a/rust/src/zstd_compress_dictionary.rs b/rust/src/zstd_compress_dictionary.rs index 5131bb051..fcbf41c24 100644 --- a/rust/src/zstd_compress_dictionary.rs +++ b/rust/src/zstd_compress_dictionary.rs @@ -1337,7 +1337,8 @@ pub unsafe extern "C" fn ZSTD_rust_compressBeginUsingDict( type InitCDictReserveContentFn = unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void; type InitCDictReserveEntropyFn = unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void; -type InitCDictResetMatchStateFn = unsafe extern "C" fn(*mut c_void, *const c_void, c_int) -> usize; +type InitCDictResetMatchStateFn = + unsafe extern "C" fn(*mut c_void, *const c_void, c_int, c_int, c_int, c_int) -> usize; type InitCDictInsertDictionaryFn = unsafe extern "C" fn( *mut c_void, *const c_void, @@ -1408,6 +1409,10 @@ const _: () = { }; const CDICT_DEFAULT_CLEVEL: c_int = 3; +// Values mirror the private C enums passed to ZSTD_reset_matchState(). +const CDICT_RESET_COMP_POLICY_MAKE_CLEAN: c_int = 0; +const CDICT_RESET_INDEX_POLICY_RESET: c_int = 1; +const CDICT_RESET_TARGET_CDICT: c_int = 0; /// Initialize a private CDict through narrow C callbacks. #[no_mangle] @@ -1492,6 +1497,9 @@ pub unsafe extern "C" fn ZSTD_rust_initCDict( state.callback_context, state.c_params.cast(), *state.use_row_match_finder, + CDICT_RESET_COMP_POLICY_MAKE_CLEAN, + CDICT_RESET_INDEX_POLICY_RESET, + CDICT_RESET_TARGET_CDICT, ) }; if ERR_isError(reset_match_result) { @@ -2801,6 +2809,9 @@ mod tests { reserve_content_available: bool, reset_c_params: ZSTD_compressionParameters, reset_use_row_match_finder: c_int, + reset_comp_policy: c_int, + reset_index_policy: c_int, + reset_target: c_int, inserted_params: *const c_void, inserted_dict: *const c_void, inserted_size: usize, @@ -2822,6 +2833,9 @@ mod tests { reserve_content_available: true, reset_c_params: ZSTD_compressionParameters::default(), reset_use_row_match_finder: 0, + reset_comp_policy: 0, + reset_index_policy: 0, + reset_target: 0, inserted_params: ptr::null(), inserted_dict: ptr::null(), inserted_size: 0, @@ -2868,11 +2882,17 @@ mod tests { context: *mut c_void, c_params: *const c_void, use_row_match_finder: c_int, + comp_policy: c_int, + index_policy: c_int, + reset_target: c_int, ) -> usize { let probe = unsafe { init_cdict_probe(context) }; probe.events.push("reset-match"); probe.reset_c_params = unsafe { *c_params.cast::() }; probe.reset_use_row_match_finder = use_row_match_finder; + probe.reset_comp_policy = comp_policy; + probe.reset_index_policy = index_policy; + probe.reset_target = reset_target; probe.reset_match_result } @@ -2965,6 +2985,9 @@ mod tests { assert_eq!(dict_content, dictionary.as_ptr().cast()); assert_eq!(probe.reset_c_params, c_params); assert_eq!(probe.reset_use_row_match_finder, use_row_match_finder); + assert_eq!(probe.reset_comp_policy, CDICT_RESET_COMP_POLICY_MAKE_CLEAN); + assert_eq!(probe.reset_index_policy, CDICT_RESET_INDEX_POLICY_RESET); + assert_eq!(probe.reset_target, CDICT_RESET_TARGET_CDICT); assert_eq!(probe.inserted_params, params); assert_eq!(probe.inserted_dict, dictionary.as_ptr().cast()); assert_eq!(probe.inserted_size, dictionary.len()); @@ -3061,6 +3084,9 @@ mod tests { assert_eq!(dict_content, probe.content_storage.as_ptr().cast()); assert_eq!(probe.inserted_dict, dict_content); assert_eq!(dict_content_size, dictionary.len()); + assert_eq!(probe.reset_comp_policy, CDICT_RESET_COMP_POLICY_MAKE_CLEAN); + assert_eq!(probe.reset_index_policy, CDICT_RESET_INDEX_POLICY_RESET); + assert_eq!(probe.reset_target, CDICT_RESET_TARGET_CDICT); assert_eq!(probe.inserted_dtlm, ZSTD_DTL_FULL); assert_eq!(probe.inserted_tfp, ZSTD_TFP_FOR_CDICT as c_int); assert_eq!(probe.reserved_entropy_size, HUF_WORKSPACE_SIZE);