Skip to content

Commit 8d50476

Browse files
fix CI: Miri compatibility, benchmark shard count
- num_cpus(): use cfg(miri) to return static 4 instead of available_parallelism() (Miri doesn't support sched_getaffinity) - benches: concurrent_insert uses with_shards(t*2) instead of new() - node tests: use real allocations instead of integer-to-pointer casts (Miri strict provenance)
1 parent 06ad00f commit 8d50476

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

benches/skiplist_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn bench_concurrent_insert(c: &mut Criterion) {
212212
for &threads in &[4, 8] {
213213
group.bench_with_input(BenchmarkId::new("fastskip", threads), &threads, |b, &t| {
214214
b.iter(|| {
215-
let sl = Arc::new(ConcurrentSkipList::new());
215+
let sl = Arc::new(ConcurrentSkipList::with_shards(t * 2));
216216

217217
let mut handles = vec![];
218218
for tid in 0..t {

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,16 @@ impl std::fmt::Debug for ConcurrentSkipList {
544544

545545
/// Simple CPU count detection.
546546
fn num_cpus() -> usize {
547-
std::thread::available_parallelism()
548-
.map(|n| n.get())
549-
.unwrap_or(4)
547+
#[cfg(miri)]
548+
{
549+
4
550+
}
551+
#[cfg(not(miri))]
552+
{
553+
std::thread::available_parallelism()
554+
.map(|n| n.get())
555+
.unwrap_or(4)
556+
}
550557
}
551558

552559
// ─── FrozenMemtable ────────────────────────────────────────────────────────────

src/node.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,16 @@ mod tests {
312312

313313
#[test]
314314
fn test_tower_ptr_basic() {
315-
let p = TowerPtr::new(0x1234_5678 as *const u8);
315+
// Use a real allocation to avoid integer-to-pointer casts under Miri
316+
let dummy = Box::into_raw(Box::new(42u8));
317+
let p = TowerPtr::new(dummy);
316318
assert!(!p.is_null());
317-
assert_eq!(p.ptr(), 0x1234_5678 as *const u8);
319+
assert_eq!(p.ptr(), dummy);
318320

319321
assert!(TowerPtr::NULL.is_null());
320322
assert_eq!(TowerPtr::NULL.ptr(), std::ptr::null());
323+
324+
unsafe { drop(Box::from_raw(dummy)) };
321325
}
322326

323327
#[test]
@@ -326,7 +330,9 @@ mod tests {
326330
unsafe {
327331
init_node(ptr, 2, b"", b"", false, 1);
328332

329-
let target = TowerPtr::new(0x1000 as *const u8);
333+
// Use a real allocation to avoid integer-to-pointer casts under Miri
334+
let dummy = Box::into_raw(Box::new(99u8));
335+
let target = TowerPtr::new(dummy);
330336
tower_store(ptr, 0, target);
331337
assert_eq!(tower_load(ptr, 0), target);
332338

@@ -335,6 +341,7 @@ mod tests {
335341
let atomic = ptr.add(offset).cast::<AtomicU64>();
336342
assert_eq!((*atomic).load(Ordering::Acquire), target.raw());
337343

344+
drop(Box::from_raw(dummy));
338345
std::alloc::dealloc(ptr, layout);
339346
}
340347
}

0 commit comments

Comments
 (0)