1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Information about the jemalloc compile-time configuration
use std::io;
use std::os::raw::c_char;

use {get_str, get_str_mib, name_to_mib};

const MALLOC_CONF: *const c_char = b"config.malloc_conf\0" as *const _ as *const _;

/// Returns the embeddec configure-time-specified run-time options config.
///
/// The string will be empty unless `--with-malloc-conf` was specified during build configuration.
///
/// # Examples
///
/// ```
/// println!("default malloc conf: {}", jemalloc_ctl::config::malloc_conf().unwrap());
/// ```
pub fn malloc_conf() -> io::Result<&'static str> {
    unsafe { get_str(MALLOC_CONF) }
}

/// A type providing access to the embedded configure-time-specified run-time options config.
///
/// The string will be empty unless `--with-malloc-conf` was specified during build configuration.
///
/// # Examples
///
/// ```
/// use jemalloc_ctl::config::MallocConf;
///
/// let malloc_conf = MallocConf::new().unwrap();
///
/// println!("default malloc conf: {}", malloc_conf.get().unwrap());
/// ```
#[derive(Copy, Clone)]
pub struct MallocConf([usize; 2]);

impl MallocConf {
    /// Returns a new `MallocConf`.
    pub fn new() -> io::Result<MallocConf> {
        unsafe {
            let mut mib = [0; 2];
            name_to_mib(MALLOC_CONF, &mut mib)?;
            Ok(MallocConf(mib))
        }
    }

    /// Returns the embedded configure-time-specified run-time options config.
    pub fn get(&self) -> io::Result<&'static str> {
        unsafe { get_str_mib(&self.0) }
    }
}