mirror of
https://github.com/girlbossceo/jemallocator.git
synced 2024-12-04 11:03:31 +00:00
510c5f0b84
As we are going to publish the crate to crates.io, we need a different name and version. Since native library is upgraded, all versions are bumpped to 0.4.0. To make it clear which version of jemalloc is used, I attach a build tag 5.2.1. And the project are upgraded to 2018 version. Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
union U {
|
|
x: &'static u8,
|
|
y: &'static libc::c_char,
|
|
}
|
|
|
|
#[allow(non_upper_case_globals)]
|
|
#[cfg_attr(prefixed, export_name = "_rjem_malloc_conf")]
|
|
#[cfg_attr(not(prefixed), no_mangle)]
|
|
pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe {
|
|
U {
|
|
x: &b"stats_print_opts:mdal\0"[0],
|
|
}
|
|
.y
|
|
});
|
|
|
|
#[test]
|
|
fn malloc_conf_set() {
|
|
unsafe {
|
|
assert_eq!(tikv_jemalloc_sys::malloc_conf, malloc_conf);
|
|
|
|
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 = tikv_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()
|
|
);
|
|
}
|
|
}
|