2018-10-24 12:34:48 +00:00
|
|
|
extern crate jemalloc_sys;
|
|
|
|
extern crate libc;
|
|
|
|
|
|
|
|
union U {
|
|
|
|
x: &'static u8,
|
2018-10-30 19:34:36 +00:00
|
|
|
y: &'static libc::c_char,
|
2018-10-24 12:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_upper_case_globals)]
|
|
|
|
#[cfg_attr(prefixed, export_name = "_rjem_malloc_conf")]
|
|
|
|
#[cfg_attr(not(prefixed), no_mangle)]
|
2018-10-30 19:34:36 +00:00
|
|
|
pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe {
|
|
|
|
U {
|
2018-10-30 18:56:52 +00:00
|
|
|
x: &b"stats_print_opts:mdal\0"[0],
|
2018-10-30 19:34:36 +00:00
|
|
|
}
|
|
|
|
.y
|
|
|
|
});
|
2018-10-24 12:34:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn malloc_conf_set() {
|
|
|
|
unsafe {
|
|
|
|
assert_eq!(jemalloc_sys::malloc_conf, malloc_conf);
|
2018-10-30 18:56:52 +00:00
|
|
|
|
|
|
|
let mut ptr: *const libc::c_char = std::ptr::null();
|
|
|
|
let mut ptr_len: libc::size_t = std::mem::size_of::<*const libc::c_char>() as libc::size_t;
|
|
|
|
let r = jemalloc_sys::mallctl(
|
|
|
|
&b"opt.stats_print_opts\0"[0] as *const _ as *const libc::c_char,
|
|
|
|
&mut ptr as *mut *const _ as *mut libc::c_void,
|
|
|
|
&mut ptr_len as *mut _,
|
|
|
|
std::ptr::null_mut(),
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
assert_eq!(r, 0);
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
|
|
|
|
let s = std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned();
|
|
|
|
assert!(
|
|
|
|
s.contains("mdal"),
|
|
|
|
"opt.stats_print_opts: \"{}\" (len = {})",
|
|
|
|
s,
|
|
|
|
s.len()
|
|
|
|
);
|
2018-10-24 12:34:48 +00:00
|
|
|
}
|
|
|
|
}
|