From 821bfc0b0984065f05cfd762ae43e2e593a8305f Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 16 Oct 2025 14:49:26 +0200 Subject: [PATCH] a slice fill is now turned into a memset even when using miri --- zlib-rs/src/deflate.rs | 11 +---------- zlib-rs/src/deflate/sym_buf.rs | 11 +---------- zlib-rs/src/lib.rs | 21 --------------------- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/zlib-rs/src/deflate.rs b/zlib-rs/src/deflate.rs index 33ddd420..4b96d74d 100644 --- a/zlib-rs/src/deflate.rs +++ b/zlib-rs/src/deflate.rs @@ -804,16 +804,7 @@ fn lm_init(state: &mut State) { state.window_size = 2 * state.w_size; // zlib uses CLEAR_HASH here - crate::cfg_select!( - miri => { - // Miri does not turn `.fill(0)` into a memset - // See https://github.com/rust-lang/rust/issues/147271. - unsafe { core::ptr::write_bytes(state.head.as_mut_ptr(), 0u8, 1) }; - } - _ => { - state.head.as_mut_slice().fill(0); - } - ); + state.head.as_mut_slice().fill(0); // Set the default configuration parameters: lm_set_level(state, state.level); diff --git a/zlib-rs/src/deflate/sym_buf.rs b/zlib-rs/src/deflate/sym_buf.rs index 314569e3..1659d044 100644 --- a/zlib-rs/src/deflate/sym_buf.rs +++ b/zlib-rs/src/deflate/sym_buf.rs @@ -36,16 +36,7 @@ impl<'a> SymBuf<'a> { /// The number of initialized bytes is not changed, and the contents of the buffer are not modified. #[inline] pub fn clear(&mut self) { - crate::cfg_select!( - miri => { - // Miri does not turn `.fill(0)` into a memset - // See https://github.com/rust-lang/rust/issues/147271. - unsafe { core::ptr::write_bytes(self.buf.as_mut_ptr(), 0u8, self.buf.len()) }; - } - _ => { - self.buf.as_mut_slice().fill(0); - } - ); + self.buf.as_mut_slice().fill(0); self.filled = 0; } diff --git a/zlib-rs/src/lib.rs b/zlib-rs/src/lib.rs index bbcbeb4d..8ee01820 100644 --- a/zlib-rs/src/lib.rs +++ b/zlib-rs/src/lib.rs @@ -26,27 +26,6 @@ macro_rules! trace { }; } -#[macro_export] -macro_rules! cfg_select { - ({ $($tt:tt)* }) => {{ - $crate::cfg_select! { $($tt)* } - }}; - (_ => { $($output:tt)* }) => { - $($output)* - }; - ( - $cfg:meta => $output:tt - $($( $rest:tt )+)? - ) => { - #[cfg($cfg)] - $crate::cfg_select! { _ => $output } - $( - #[cfg(not($cfg))] - $crate::cfg_select! { $($rest)+ } - )? - } -} - /// Maximum size of the dynamic table. The maximum number of code structures is /// 1924, which is the sum of 1332 for literal/length codes and 592 for distance /// codes. These values were found by exhaustive searches using the program