Skip to content

Commit eec2f6c

Browse files
committed
bugfix: Fix a bug that MIRI spotted
Signed-off-by: John Nunley <[email protected]>
1 parent 7963c1b commit eec2f6c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Diff for: src/linked_list/no_std.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ impl<T> Link<T> {
517517
let old_state = self.state.fetch_or(REGISTERING, Ordering::SeqCst);
518518
if old_state & NOTIFIED != 0 {
519519
// poll() somehow missed the notification. Wake the event loop and try again.
520+
let _guard = CallOnDrop(|| {
521+
self.state.fetch_and(!REGISTERING, Ordering::SeqCst);
522+
});
520523
waker.wake_by_ref();
521524
return;
522525
}
@@ -624,7 +627,7 @@ impl<T> Slots<T> {
624627
}
625628
};
626629

627-
unsafe { slice::from_raw_parts_mut(ptr.as_ptr(), size) }
630+
unsafe { slice::from_raw_parts(ptr.as_ptr(), size) }
628631
}
629632
}
630633

@@ -744,6 +747,11 @@ mod tests {
744747

745748
type HashSet<K> = hashbrown::HashSet<K, ahash::RandomState>;
746749

750+
#[cfg(not(miri))]
751+
const MAX: usize = 0xFFFF;
752+
#[cfg(miri)]
753+
const MAX: usize = 0xFF;
754+
747755
#[test]
748756
fn lock() {
749757
let lock = Lock::new(());
@@ -760,8 +768,7 @@ mod tests {
760768
let mut seen_ptrs: HashSet<usize> = HashSet::with_hasher(ahash::RandomState::default());
761769

762770
// Don't exhaust our memory; only do this many.
763-
let count = 0xFFFF;
764-
for i in 1..count {
771+
for i in 1..MAX {
765772
let not_yet_seen = seen_ptrs.insert(slots.get(i) as *const Link<()> as usize);
766773
assert!(not_yet_seen);
767774
}
@@ -772,7 +779,7 @@ mod tests {
772779
let index = Indexes::new();
773780
let mut last = 0;
774781

775-
for _ in 0..0xFFFF {
782+
for _ in 0..MAX {
776783
let val = index.alloc();
777784
assert_eq!(val, last + 1);
778785
last = val;

0 commit comments

Comments
 (0)