Skip to content

Commit

Permalink
fix(miniz_oxide): update edition, make more functions const, fix warn…
Browse files Browse the repository at this point in the history
…ing, update to adler2
  • Loading branch information
oyvindln committed Aug 8, 2024
1 parent 084c21b commit b212371
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
11 changes: 8 additions & 3 deletions miniz_oxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ repository = "https://github.com/Frommi/miniz_oxide/tree/master/miniz_oxide"
homepage = "https://github.com/Frommi/miniz_oxide/tree/master/miniz_oxide"
documentation = "https://docs.rs/miniz_oxide"
description = "DEFLATE compression and decompression library rewritten in Rust based on miniz"
edition = "2018"
edition = "2021"
exclude = ["benches/*", "tests/*"]

[lib]
name = "miniz_oxide"

[dependencies]
adler = { version = "1.0", default-features = false }
adler2 = { version = "2.0", default-features = false}
simd-adler32 = { version = "0.3.3", default-features = false, optional = true }

# Internal feature, only used when building as part of libstd, not part of the
Expand All @@ -33,6 +33,11 @@ std = []

# Internal feature, only used when building as part of libstd, not part of the
# stable interface of this crate.
rustc-dep-of-std = ['core', 'alloc', 'compiler_builtins', 'adler/rustc-dep-of-std']
rustc-dep-of-std = ['core', 'alloc', 'compiler_builtins', 'adler2/rustc-dep-of-std']

simd = ['simd-adler32']

# Disable unexpected cfg name warning from to !cfg(fuzzing) - compiler is not aware of the fuzzing feature since it comes from the environment
# see https://github.com/rust-fuzz/cargo-fuzz/issues/372
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
6 changes: 3 additions & 3 deletions miniz_oxide/src/deflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl From<MZFlush> for TDEFLFlush {
}

impl TDEFLFlush {
pub fn new(flush: i32) -> Result<Self, MZError> {
pub const fn new(flush: i32) -> Result<Self, MZError> {
match flush {
0 => Ok(TDEFLFlush::None),
2 => Ok(TDEFLFlush::Sync),
Expand Down Expand Up @@ -320,7 +320,7 @@ mod zlib {
flg + (FCHECK_DIVISOR - rem as u8)
}

fn zlib_level_from_flags(flags: u32) -> u8 {
const fn zlib_level_from_flags(flags: u32) -> u8 {
use super::NUM_PROBES;

let num_probes = flags & (super::MAX_PROBES_MASK as u32);
Expand Down Expand Up @@ -454,7 +454,7 @@ impl CompressorOxide {
}

/// Returns whether the compressor is wrapping the data in a zlib format or not.
pub fn data_format(&self) -> DataFormat {
pub const fn data_format(&self) -> DataFormat {
if (self.params.flags & TDEFL_WRITE_ZLIB_HEADER) != 0 {
DataFormat::Zlib
} else {
Expand Down
6 changes: 3 additions & 3 deletions miniz_oxide/src/inflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ enum State {
}

impl State {
fn is_failure(self) -> bool {
const fn is_failure(self) -> bool {
matches!(
self,
BlockTypeUnexpected
Expand Down Expand Up @@ -445,7 +445,7 @@ fn fill_bit_buffer(l: &mut LocalVars, in_iter: &mut slice::Iter<u8>) {
///
/// See https://tools.ietf.org/html/rfc1950
#[inline]
fn validate_zlib_header(cmf: u32, flg: u32, flags: u32, mask: usize) -> Action {
const fn validate_zlib_header(cmf: u32, flg: u32, flags: u32, mask: usize) -> Action {
let mut failed =
// cmf + flg should be divisible by 31.
(((cmf * 256) + flg) % 31 != 0) ||
Expand Down Expand Up @@ -653,7 +653,7 @@ where
}

#[inline]
fn end_of_input(flags: u32) -> Action {
const fn end_of_input(flags: u32) -> Action {
Action::End(if flags & TINFL_FLAG_HAS_MORE_INPUT != 0 {
TINFLStatus::NeedsMoreInput
} else {
Expand Down
2 changes: 1 addition & 1 deletion miniz_oxide/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const HUFFMAN_LENGTH_ORDER: [u8; 19] = [
#[doc(hidden)]
#[cfg(not(feature = "simd"))]
pub fn update_adler32(adler: u32, data: &[u8]) -> u32 {
let mut hash = adler::Adler32::from_checksum(adler);
let mut hash = adler2::Adler32::from_checksum(adler);
hash.write_slice(data);
hash.checksum()
}
Expand Down

0 comments on commit b212371

Please sign in to comment.