Skip to content

Commit bbf2574

Browse files
Folkert de Vriesfolkertdev
authored andcommitted
work around miri limitation, run more defalte tests with miri
1 parent 67beda3 commit bbf2574

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

.github/workflows/checks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ jobs:
458458
include:
459459
- target: x86_64-unknown-linux-gnu
460460
- target: x86_64-pc-windows-gnu
461+
env:
462+
QUICKCHECK_TESTS: 10
461463
steps:
462464
- uses: actions/checkout@v3
463465
- name: Install Miri

test-libz-rs-sys/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ mod null {
453453
..Default::default()
454454
};
455455

456-
#[cfg(not(miri))]
457456
assert_eq_rs_ng!({
458457
let mut extra = *b"banana\0";
459458
let mut name = *b"apple\0";
@@ -835,7 +834,6 @@ mod null {
835834
fn deflate_params() {
836835
assert_eq_rs_ng!({ deflateParams(core::ptr::null_mut(), 6, 0) });
837836

838-
#[cfg(not(miri))]
839837
assert_eq_rs_ng!({
840838
let mut strm = MaybeUninit::<z_stream>::zeroed();
841839
deflateInit_(
@@ -868,7 +866,6 @@ mod null {
868866
deflateSetHeader(core::ptr::null_mut(), head.as_mut_ptr())
869867
});
870868

871-
#[cfg(not(miri))]
872869
assert_eq_rs_ng!({
873870
let mut strm = MaybeUninit::<z_stream>::zeroed();
874871

@@ -899,7 +896,6 @@ mod null {
899896
)
900897
});
901898

902-
#[cfg(not(miri))]
903899
assert_eq_rs_ng!({
904900
let mut strm = MaybeUninit::<z_stream>::zeroed();
905901
deflateInit_(
@@ -939,7 +935,6 @@ mod null {
939935
);
940936
}
941937

942-
#[cfg(not(miri))]
943938
assert_eq!(
944939
unsafe {
945940
use libz_rs_sys::*;
@@ -967,7 +962,6 @@ mod null {
967962
pub const FERRIS_BYTES: [u8; 14] = [120u8, 156, 115, 75, 45, 42, 202, 44, 6, 0, 8, 6, 2, 108];
968963

969964
#[test]
970-
#[cfg_attr(miri, ignore = "slow")]
971965
fn ferris_bytes() {
972966
let input = b"Ferris";
973967
let mut buf = [0; 64];
@@ -1152,7 +1146,6 @@ mod null {
11521146
}
11531147

11541148
#[test]
1155-
#[cfg_attr(miri, ignore = "slow")]
11561149
fn deflate_init_uninitialized() {
11571150
use libz_rs_sys::*;
11581151

zlib-rs/src/deflate.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,16 @@ fn lm_init(state: &mut State) {
804804
state.window_size = 2 * state.w_size;
805805

806806
// zlib uses CLEAR_HASH here
807-
state.head.as_mut_slice().fill(0);
807+
crate::cfg_select!(
808+
miri => {
809+
// Miri does not turn `.fill(0)` into a memset
810+
// See https://github.com/rust-lang/rust/issues/147271.
811+
unsafe { core::ptr::write_bytes(state.head.as_mut_ptr(), 0u8, 1) };
812+
}
813+
_ => {
814+
state.head.as_mut_slice().fill(0);
815+
}
816+
);
808817

809818
// Set the default configuration parameters:
810819
lm_set_level(state, state.level);

zlib-rs/src/deflate/sym_buf.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ impl<'a> SymBuf<'a> {
3636
/// The number of initialized bytes is not changed, and the contents of the buffer are not modified.
3737
#[inline]
3838
pub fn clear(&mut self) {
39-
self.buf.as_mut_slice().fill(0);
39+
crate::cfg_select!(
40+
miri => {
41+
// Miri does not turn `.fill(0)` into a memset
42+
// See https://github.com/rust-lang/rust/issues/147271.
43+
unsafe { core::ptr::write_bytes(self.buf.as_mut_ptr(), 0u8, self.buf.len()) };
44+
}
45+
_ => {
46+
self.buf.as_mut_slice().fill(0);
47+
}
48+
);
4049
self.filled = 0;
4150
}
4251

zlib-rs/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ macro_rules! trace {
2626
};
2727
}
2828

29+
#[macro_export]
30+
macro_rules! cfg_select {
31+
({ $($tt:tt)* }) => {{
32+
$crate::cfg_select! { $($tt)* }
33+
}};
34+
(_ => { $($output:tt)* }) => {
35+
$($output)*
36+
};
37+
(
38+
$cfg:meta => $output:tt
39+
$($( $rest:tt )+)?
40+
) => {
41+
#[cfg($cfg)]
42+
$crate::cfg_select! { _ => $output }
43+
$(
44+
#[cfg(not($cfg))]
45+
$crate::cfg_select! { $($rest)+ }
46+
)?
47+
}
48+
}
49+
2950
/// Maximum size of the dynamic table. The maximum number of code structures is
3051
/// 1924, which is the sum of 1332 for literal/length codes and 592 for distance
3152
/// codes. These values were found by exhaustive searches using the program

0 commit comments

Comments
 (0)