Skip to content

Commit 3a66328

Browse files
Fix miri (#25)
1 parent 1749cd9 commit 3a66328

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

src/lfu/wtinylfu.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ mod test {
725725
}
726726

727727
#[test]
728-
#[cfg_attr(miri, ignore)]
729728
fn test_wtinylfu_custom_hasher() {
730729
let mut cache: WTinyLFUCache<
731730
u64,
@@ -823,7 +822,6 @@ mod test {
823822
}
824823

825824
#[test]
826-
#[cfg_attr(miri, ignore)]
827825
fn test_wtinylfu() {
828826
let mut cache = WTinyLFUCache::with_sizes(1, 2, 2, 5).unwrap();
829827
assert_eq!(cache.cap(), 5);
@@ -908,7 +906,6 @@ mod test {
908906
}
909907

910908
#[test]
911-
#[cfg_attr(miri, ignore)]
912909
fn test_wtinylfu_clone() {
913910
let mut cache = WTinyLFUCache::with_sizes(1, 2, 2, 5).unwrap();
914911
assert_eq!(cache.cap(), 5);

src/lru/adaptive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ mod test {
17641764
use rand::seq::SliceRandom;
17651765
use rand::{thread_rng, Rng};
17661766

1767+
#[cfg_attr(miri, ignore)]
17671768
#[test]
17681769
fn test_arc_cache_random_ops() {
17691770
let size = 128;

src/lru/raw.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> Cache<K, V> for RawLRU
501501
{
502502
match self.map.get_mut(KeyWrapper::from_ref(k)) {
503503
None => None,
504-
Some(node) => Some(unsafe { &mut *node.as_mut().val.as_mut_ptr() }),
504+
Some(node) => Some(unsafe { &mut *(*node.as_ptr()).val.as_mut_ptr() }),
505505
}
506506
}
507507

@@ -557,10 +557,10 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> Cache<K, V> for RawLRU
557557
Some(old_node) => unsafe {
558558
let node_ptr = &mut *old_node.as_ptr();
559559
self.detach(node_ptr);
560-
let node = *Box::from_raw(old_node.as_ptr());
560+
let mut node = *Box::from_raw(old_node.as_ptr());
561561
let val = node.val.assume_init();
562-
self.cb(&*node_ptr.key.as_ptr(), &val);
563-
ptr::drop_in_place(node_ptr.key.as_mut_ptr());
562+
self.cb(&*node.key.as_ptr(), &val);
563+
ptr::drop_in_place(node.key.assume_init_mut());
564564
Some(val)
565565
},
566566
}
@@ -1363,7 +1363,7 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
13631363
{
13641364
match self.map.get_mut(KeyWrapper::from_ref(k)) {
13651365
None => None,
1366-
Some(node) => Some(unsafe { &mut *node.as_mut().val.as_mut_ptr() }),
1366+
Some(node) => Some(unsafe { &mut *(*node.as_ptr()).val.as_mut_ptr() }),
13671367
}
13681368
}
13691369

@@ -1375,7 +1375,7 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
13751375
{
13761376
self.map
13771377
.get(KeyWrapper::from_ref(k))
1378-
.map(|node| unsafe { &*node.as_ref().val.as_ptr() })
1378+
.map(|node| unsafe { &*(*node.as_ptr()).val.as_ptr() })
13791379
}
13801380

13811381
// used for avoiding borrow checker issues
@@ -1414,22 +1414,22 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
14141414
}
14151415
}
14161416

1417-
pub(crate) fn put_nonnull(&mut self, mut bks: NonNull<EntryNode<K, V>>) -> PutResult<K, V> {
1417+
// let old_key = KeyRef {
1418+
// k: unsafe { &(*(*(*self.tail).prev).key.as_ptr()) },
1419+
// };
1420+
// let old_node = self.map.remove(&old_key).unwrap();
1421+
pub(crate) fn put_nonnull(&mut self, bks: NonNull<EntryNode<K, V>>) -> PutResult<K, V> {
14181422
if self.len() >= self.cap() {
14191423
unsafe {
14201424
// Safety: the cache length is not zero, so the cache must have a tail node.
1421-
let node = ((*self.tail).prev).as_mut().unwrap();
1422-
self.detach(node);
1423-
1425+
let old_key = KeyRef {
1426+
k: &(*(*(*self.tail).prev).key.as_ptr()),
1427+
};
14241428
// Safety: the node is in cache, so the cache map must have the node.
1425-
let node = self
1426-
.map
1427-
.remove(&KeyRef {
1428-
k: node.key.as_ptr(),
1429-
})
1430-
.unwrap();
1431-
1432-
self.attach(bks.as_mut());
1429+
let node = self.map.remove(&old_key).unwrap();
1430+
self.detach(node.as_ptr());
1431+
1432+
self.attach(bks.as_ptr());
14331433
self.map.insert(
14341434
KeyRef {
14351435
k: bks.as_ref().key.as_ptr(),
@@ -1464,23 +1464,19 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
14641464

14651465
pub(crate) fn put_or_evict_nonnull(
14661466
&mut self,
1467-
mut bks: NonNull<EntryNode<K, V>>,
1467+
bks: NonNull<EntryNode<K, V>>,
14681468
) -> Option<NonNull<EntryNode<K, V>>> {
14691469
if self.len() >= self.cap() {
14701470
unsafe {
14711471
// Safety: the cache length is not zero, so the cache must have a tail node.
1472-
let node = ((*self.tail).prev).as_mut().unwrap();
1473-
self.detach(node);
1474-
1472+
let old_key = KeyRef {
1473+
k: &(*(*(*self.tail).prev).key.as_ptr()),
1474+
};
14751475
// Safety: the node is in cache, so the cache map must have the node.
1476-
let node = self
1477-
.map
1478-
.remove(&KeyRef {
1479-
k: node.key.as_ptr(),
1480-
})
1481-
.unwrap();
1482-
1483-
self.attach(bks.as_mut());
1476+
let node = self.map.remove(&old_key).unwrap();
1477+
self.detach(node.as_ptr());
1478+
1479+
self.attach(bks.as_ptr());
14841480
self.map.insert(
14851481
KeyRef {
14861482
k: bks.as_ref().key.as_ptr(),

src/lru/two_queue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ mod test {
16181618
use rand::{thread_rng, Rng};
16191619
use std::format;
16201620

1621+
#[cfg_attr(miri, ignore)]
16211622
#[test]
16221623
fn test_2q_cache_random_ops() {
16231624
let size = 128;

0 commit comments

Comments
 (0)