Skip to content
3 changes: 2 additions & 1 deletion c2rust-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ pub use crate::lib::dictBuilder::cover::{
pub use crate::lib::dictBuilder::fastcover::{
ZDICT_optimizeTrainFromBuffer_fastCover, ZDICT_trainFromBuffer_fastCover,
};
pub use crate::lib::dictBuilder::zdict::ZDICT_trainFromBuffer_legacy;
pub use crate::lib::zdict::{
experimental::{ZDICT_cover_params_t, ZDICT_fastCover_params_t},
experimental::{ZDICT_cover_params_t, ZDICT_fastCover_params_t, ZDICT_legacy_params_t},
ZDICT_getDictID, ZDICT_getErrorName, ZDICT_isError, ZDICT_params_t, ZDICT_trainFromBuffer,
};

Expand Down
3 changes: 3 additions & 0 deletions lib/common/huf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub(crate) const HUF_TABLELOG_MAX: usize = 12;
pub(crate) const HUF_TABLELOG_DEFAULT: core::ffi::c_int = 11;
pub(crate) const HUF_SYMBOLVALUE_MAX: core::ffi::c_int = 255;

pub(crate) const HUF_CTABLE_WORKSPACE_SIZE_U32: usize =
(4 * (HUF_SYMBOLVALUE_MAX as usize + 1)) + 192;

/// Absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work
const HUF_TABLELOG_ABSOLUTEMAX: usize = 12;
const _: () = assert!(
Expand Down
20 changes: 10 additions & 10 deletions lib/common/zstd_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ pub(crate) const bt_compressed: blockType_e = 2;

pub(crate) const MINMATCH: core::ffi::c_int = 3;

pub(crate) const Litbits: core::ffi::c_int = 8;
pub(crate) const LitHufLog: core::ffi::c_int = 11;
pub(crate) const MaxLit: core::ffi::c_int = ((1) << Litbits) - 1;
pub(crate) const MaxML: core::ffi::c_int = 52;
pub(crate) const MaxLL: core::ffi::c_int = 35;
pub(crate) const DefaultMaxOff: core::ffi::c_int = 28;
pub(crate) const MaxOff: core::ffi::c_int = 31;
pub(crate) const Litbits: u32 = 8;
pub(crate) const LitHufLog: u32 = 11;
pub(crate) const MaxLit: u32 = (1 << Litbits) - 1;
pub(crate) const MaxML: u32 = 52;
pub(crate) const MaxLL: u32 = 35;
pub(crate) const DefaultMaxOff: u32 = 28;
pub(crate) const MaxOff: u32 = 31;
pub(crate) const MaxSeq: usize = const_max(MaxLL as usize, MaxML as usize); /* Assumption : MaxOff < MaxLL,MaxML */
pub(crate) const MLFSELog: core::ffi::c_int = 9;
pub(crate) const LLFSELog: core::ffi::c_int = 9;
pub(crate) const OffFSELog: core::ffi::c_int = 8;
pub(crate) const MLFSELog: u32 = 9;
pub(crate) const LLFSELog: u32 = 9;
pub(crate) const OffFSELog: u32 = 8;
pub(crate) const MaxFSELog: usize = const_max(
const_max(MLFSELog as usize, LLFSELog as usize),
OffFSELog as usize,
Expand Down
62 changes: 28 additions & 34 deletions lib/compress/zstd_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4655,7 +4655,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
};
stats.lastCountSize = 0;
stats.longOffsets = ZSTD_seqToCodes(seqStorePtr);
let mut max = MaxLL as core::ffi::c_uint;
let mut max = MaxLL;
let mostFrequent = HIST_countFast_wksp(
countWorkspace,
&mut max,
Expand All @@ -4671,7 +4671,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
max,
mostFrequent,
nbSeq,
LLFSELog as core::ffi::c_uint,
LLFSELog,
((*prevEntropy).litlengthCTable).as_ptr(),
LL_defaultNorm.as_ptr(),
LL_defaultNormLog,
Expand All @@ -4682,15 +4682,15 @@ unsafe fn ZSTD_buildSequencesStatistics(
op as *mut core::ffi::c_void,
oend.offset_from_unsigned(op),
CTable_LitLength,
LLFSELog as u32,
LLFSELog,
stats.LLtype as SymbolEncodingType_e,
countWorkspace,
max,
llCodeTable,
nbSeq,
LL_defaultNorm.as_ptr(),
LL_defaultNormLog,
MaxLL as u32,
MaxLL,
((*prevEntropy).litlengthCTable).as_ptr(),
::core::mem::size_of::<[FSE_CTable; 329]>(),
entropyWorkspace,
Expand All @@ -4704,7 +4704,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
stats.lastCountSize = countSize;
}
op = op.add(countSize);
let mut max_0 = MaxOff as core::ffi::c_uint;
let mut max_0 = MaxOff;
let mostFrequent_0 = HIST_countFast_wksp(
countWorkspace,
&mut max_0,
Expand All @@ -4713,7 +4713,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
entropyWorkspace,
entropyWkspSize,
);
let defaultPolicy = (if max_0 <= DefaultMaxOff as core::ffi::c_uint {
let defaultPolicy = (if max_0 <= DefaultMaxOff {
ZSTD_defaultAllowed as core::ffi::c_int
} else {
ZSTD_defaultDisallowed as core::ffi::c_int
Expand All @@ -4725,7 +4725,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
max_0,
mostFrequent_0,
nbSeq,
OffFSELog as core::ffi::c_uint,
OffFSELog,
((*prevEntropy).offcodeCTable).as_ptr(),
OF_defaultNorm.as_ptr(),
OF_defaultNormLog,
Expand All @@ -4736,15 +4736,15 @@ unsafe fn ZSTD_buildSequencesStatistics(
op as *mut core::ffi::c_void,
oend.offset_from_unsigned(op),
CTable_OffsetBits,
OffFSELog as u32,
OffFSELog,
stats.Offtype as SymbolEncodingType_e,
countWorkspace,
max_0,
ofCodeTable,
nbSeq,
OF_defaultNorm.as_ptr(),
OF_defaultNormLog,
DefaultMaxOff as u32,
DefaultMaxOff,
((*prevEntropy).offcodeCTable).as_ptr(),
::core::mem::size_of::<[FSE_CTable; 193]>(),
entropyWorkspace,
Expand All @@ -4758,7 +4758,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
stats.lastCountSize = countSize_0;
}
op = op.add(countSize_0);
let mut max_1 = MaxML as core::ffi::c_uint;
let mut max_1 = MaxML;
let mostFrequent_1 = HIST_countFast_wksp(
countWorkspace,
&mut max_1,
Expand All @@ -4774,7 +4774,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
max_1,
mostFrequent_1,
nbSeq,
MLFSELog as core::ffi::c_uint,
MLFSELog,
((*prevEntropy).matchlengthCTable).as_ptr(),
ML_defaultNorm.as_ptr(),
ML_defaultNormLog,
Expand All @@ -4785,15 +4785,15 @@ unsafe fn ZSTD_buildSequencesStatistics(
op as *mut core::ffi::c_void,
oend.offset_from_unsigned(op),
CTable_MatchLength,
MLFSELog as u32,
MLFSELog,
stats.MLtype as SymbolEncodingType_e,
countWorkspace,
max_1,
mlCodeTable,
nbSeq,
ML_defaultNorm.as_ptr(),
ML_defaultNormLog,
MaxML as u32,
MaxML,
((*prevEntropy).matchlengthCTable).as_ptr(),
::core::mem::size_of::<[FSE_CTable; 363]>(),
entropyWorkspace,
Expand Down Expand Up @@ -5659,7 +5659,7 @@ unsafe fn ZSTD_buildBlockEntropyStats_literals(
let nodeWksp = countWkspStart.add(countWkspSize);
let nodeWkspSize = wkspEnd.offset_from_unsigned(nodeWksp);
let mut maxSymbolValue = HUF_SYMBOLVALUE_MAX as core::ffi::c_uint;
let mut huffLog = LitHufLog as core::ffi::c_uint;
let mut huffLog = LitHufLog;
let mut repeat = (*prevHuf).repeatMode;
libc::memcpy(
nextHuf as *mut core::ffi::c_void,
Expand Down Expand Up @@ -6020,38 +6020,38 @@ unsafe fn ZSTD_estimateBlockSize_sequences(
(*fseMetadata).ofType,
ofCodeTable,
nbSeq,
MaxOff as core::ffi::c_uint,
MaxOff,
((*fseTables).offcodeCTable).as_ptr(),
core::ptr::null(),
OF_defaultNorm.as_ptr(),
OF_defaultNormLog,
DefaultMaxOff as u32,
DefaultMaxOff,
workspace,
wkspSize,
));
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateBlockSize_symbolType(
(*fseMetadata).llType,
llCodeTable,
nbSeq,
MaxLL as core::ffi::c_uint,
MaxLL,
((*fseTables).litlengthCTable).as_ptr(),
LL_bits.as_ptr(),
LL_defaultNorm.as_ptr(),
LL_defaultNormLog,
MaxLL as u32,
MaxLL,
workspace,
wkspSize,
));
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateBlockSize_symbolType(
(*fseMetadata).mlType,
mlCodeTable,
nbSeq,
MaxML as core::ffi::c_uint,
MaxML,
((*fseTables).matchlengthCTable).as_ptr(),
ML_bits.as_ptr(),
ML_defaultNorm.as_ptr(),
ML_defaultNormLog,
MaxML as u32,
MaxML,
workspace,
wkspSize,
));
Expand Down Expand Up @@ -7343,7 +7343,7 @@ pub unsafe fn ZSTD_loadCEntropy(
dictSize: size_t,
) -> size_t {
let mut offcodeNCount: [core::ffi::c_short; 32] = [0; 32];
let mut offcodeMaxValue = MaxOff as core::ffi::c_uint;
let mut offcodeMaxValue = MaxOff;
let mut dictPtr = dict as *const u8;
let dictEnd = dictPtr.add(dictSize);
dictPtr = dictPtr.add(8);
Expand Down Expand Up @@ -7390,7 +7390,7 @@ pub unsafe fn ZSTD_loadCEntropy(
}
dictPtr = dictPtr.add(offcodeHeaderSize);
let mut matchlengthNCount: [core::ffi::c_short; 53] = [0; 53];
let mut matchlengthMaxValue = MaxML as core::ffi::c_uint;
let mut matchlengthMaxValue = MaxML;
let mut matchlengthLog: core::ffi::c_uint = 0;
let matchlengthHeaderSize = FSE_readNCount(
&mut matchlengthNCount,
Expand All @@ -7415,14 +7415,11 @@ pub unsafe fn ZSTD_loadCEntropy(
)) {
return Error::dictionary_corrupted.to_error_code();
}
(*bs).entropy.fse.matchlength_repeatMode = ZSTD_dictNCountRepeat(
matchlengthNCount.as_mut_ptr(),
matchlengthMaxValue,
MaxML as core::ffi::c_uint,
);
(*bs).entropy.fse.matchlength_repeatMode =
ZSTD_dictNCountRepeat(matchlengthNCount.as_mut_ptr(), matchlengthMaxValue, MaxML);
dictPtr = dictPtr.add(matchlengthHeaderSize);
let mut litlengthNCount: [core::ffi::c_short; 36] = [0; 36];
let mut litlengthMaxValue = MaxLL as core::ffi::c_uint;
let mut litlengthMaxValue = MaxLL;
let mut litlengthLog: core::ffi::c_uint = 0;
let litlengthHeaderSize = FSE_readNCount(
&mut litlengthNCount,
Expand All @@ -7447,11 +7444,8 @@ pub unsafe fn ZSTD_loadCEntropy(
)) {
return Error::dictionary_corrupted.to_error_code();
}
(*bs).entropy.fse.litlength_repeatMode = ZSTD_dictNCountRepeat(
litlengthNCount.as_mut_ptr(),
litlengthMaxValue,
MaxLL as core::ffi::c_uint,
);
(*bs).entropy.fse.litlength_repeatMode =
ZSTD_dictNCountRepeat(litlengthNCount.as_mut_ptr(), litlengthMaxValue, MaxLL);
dictPtr = dictPtr.add(litlengthHeaderSize);
if dictPtr.add(12) > dictEnd {
return Error::dictionary_corrupted.to_error_code();
Expand All @@ -7461,7 +7455,7 @@ pub unsafe fn ZSTD_loadCEntropy(
*((*bs).rep).as_mut_ptr().add(2) = MEM_readLE32(dictPtr.add(8) as *const core::ffi::c_void);
dictPtr = dictPtr.add(12);
let dictContentSize = dictEnd.offset_from_unsigned(dictPtr);
let mut offcodeMax = MaxOff as u32;
let mut offcodeMax = MaxOff;
if dictContentSize
<= (-(1 as core::ffi::c_int) as u32)
.wrapping_sub((128 as core::ffi::c_int * ((1 as core::ffi::c_int) << 10)) as u32)
Expand Down
2 changes: 1 addition & 1 deletion lib/compress/zstd_compress_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub unsafe fn ZSTD_compressLiterals(
src,
srcSize,
HUF_SYMBOLVALUE_MAX as core::ffi::c_uint,
LitHufLog as core::ffi::c_uint,
LitHufLog,
entropyWorkspace,
entropyWorkspaceSize,
((*nextHuf).CTable).as_mut_ptr(),
Expand Down
2 changes: 1 addition & 1 deletion lib/compress/zstd_compress_sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ unsafe fn ZSTD_encodeSequences_body(
);
if MEM_32bits()
|| ofBits_0.wrapping_add(mlBits).wrapping_add(llBits)
>= (64 - 7 - (LLFSELog + MLFSELog + OffFSELog)) as u32
>= 64 - 7 - (LLFSELog + MLFSELog + OffFSELog)
{
BIT_flushBits(&mut blockStream);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/compress/zstd_compress_superblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,39 +736,39 @@ unsafe fn ZSTD_estimateSubBlockSize_sequences(
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateSubBlockSize_symbolType(
(*fseMetadata).ofType,
ofCodeTable,
MaxOff as core::ffi::c_uint,
MaxOff,
nbSeq,
((*fseTables).offcodeCTable).as_ptr(),
core::ptr::null(),
OF_defaultNorm.as_ptr(),
OF_defaultNormLog,
DefaultMaxOff as u32,
DefaultMaxOff,
workspace,
wkspSize,
));
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateSubBlockSize_symbolType(
(*fseMetadata).llType,
llCodeTable,
MaxLL as core::ffi::c_uint,
MaxLL,
nbSeq,
((*fseTables).litlengthCTable).as_ptr(),
LL_bits.as_ptr(),
LL_defaultNorm.as_ptr(),
LL_defaultNormLog,
MaxLL as u32,
MaxLL,
workspace,
wkspSize,
));
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateSubBlockSize_symbolType(
(*fseMetadata).mlType,
mlCodeTable,
MaxML as core::ffi::c_uint,
MaxML,
nbSeq,
((*fseTables).matchlengthCTable).as_ptr(),
ML_bits.as_ptr(),
ML_defaultNorm.as_ptr(),
ML_defaultNormLog,
MaxML as u32,
MaxML,
workspace,
wkspSize,
));
Expand Down
Loading