2016-01-21 01:14:01 +00:00
|
|
|
extern crate jemallocator;
|
|
|
|
|
2017-07-07 18:07:16 +00:00
|
|
|
use jemallocator::Jemalloc;
|
2018-06-13 14:36:07 +00:00
|
|
|
use std::alloc::{GlobalAlloc, Layout};
|
2017-07-07 18:07:16 +00:00
|
|
|
|
|
|
|
#[global_allocator]
|
|
|
|
static A: Jemalloc = Jemalloc;
|
|
|
|
|
2016-01-21 01:14:01 +00:00
|
|
|
#[test]
|
|
|
|
fn smoke() {
|
|
|
|
let mut a = Vec::new();
|
|
|
|
a.push(3);
|
|
|
|
}
|
2017-11-22 15:45:11 +00:00
|
|
|
|
|
|
|
/// https://github.com/rust-lang/rust/issues/45955
|
|
|
|
#[test]
|
|
|
|
fn overaligned() {
|
|
|
|
let size = 8;
|
|
|
|
let align = 16; // greater than size
|
|
|
|
let iterations = 100;
|
|
|
|
unsafe {
|
2018-10-30 19:34:36 +00:00
|
|
|
let pointers: Vec<_> = (0..iterations)
|
|
|
|
.map(|_| {
|
|
|
|
let ptr = Jemalloc.alloc(Layout::from_size_align(size, align).unwrap());
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
ptr
|
|
|
|
})
|
|
|
|
.collect();
|
2017-11-22 15:45:11 +00:00
|
|
|
for &ptr in &pointers {
|
2018-10-30 19:34:36 +00:00
|
|
|
assert_eq!(
|
|
|
|
(ptr as usize) % align,
|
|
|
|
0,
|
|
|
|
"Got a pointer less aligned than requested"
|
|
|
|
)
|
2017-11-22 15:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
for &ptr in &pointers {
|
|
|
|
Jemalloc.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|