1 union U {
2     x: &'static u8,
3     y: &'static libc::c_char,
4 }
5 
6 #[allow(non_upper_case_globals)]
7 #[cfg_attr(prefixed, export_name = "_rjem_malloc_conf")]
8 #[cfg_attr(not(prefixed), no_mangle)]
9 pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe {
10     U {
11         x: &b"stats_print_opts:mdal\0"[0],
12     }
13     .y
14 });
15 
16 #[test]
malloc_conf_set()17 fn malloc_conf_set() {
18     unsafe {
19         assert_eq!(tikv_jemalloc_sys::malloc_conf, malloc_conf);
20 
21         let mut ptr: *const libc::c_char = std::ptr::null();
22         let mut ptr_len: libc::size_t = std::mem::size_of::<*const libc::c_char>() as libc::size_t;
23         let r = tikv_jemalloc_sys::mallctl(
24             &b"opt.stats_print_opts\0"[0] as *const _ as *const libc::c_char,
25             &mut ptr as *mut *const _ as *mut libc::c_void,
26             &mut ptr_len as *mut _,
27             std::ptr::null_mut(),
28             0,
29         );
30         assert_eq!(r, 0);
31         assert!(!ptr.is_null());
32 
33         let s = std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned();
34         assert!(
35             s.contains("mdal"),
36             "opt.stats_print_opts: \"{}\" (len = {})",
37             s,
38             s.len()
39         );
40     }
41 }
42