unsafe fn init_state() -> *mut backtrace_state {
        static mut STATE: *mut backtrace_state = ptr::null_mut();
        static mut LAST_FILENAME: [libc::c_char; 256] = [0; 256];
        if !STATE.is_null() { return STATE }
        let selfname = if cfg!(target_os = "freebsd") ||
            cfg!(target_os = "dragonfly") ||
            cfg!(target_os = "bitrig") ||
            cfg!(target_os = "openbsd") ||
            cfg!(target_os = "windows") {
                env::current_exe().ok()
            } else {
                None
            };
        let filename = match selfname.as_ref().and_then(|s| s.as_os_str().to_bytes()) {
            Some(path) => {
                let bytes = path;
                if bytes.len() < LAST_FILENAME.len() {
                    let i = bytes.iter();
                    for (slot, val) in LAST_FILENAME.iter_mut().zip(i) {
                        *slot = *val as libc::c_char;
                    }
                    LAST_FILENAME.as_ptr()
                } else {
                    ptr::null()
                }
            }
            None => ptr::null(),
        };
        STATE = backtrace_create_state(filename, 0, error_cb,
                                       ptr::null_mut());
        return STATE
    }
// The libbacktrace API supports creating a state, but it does not
// support destroying a state. I personally take this to mean that a
// state is meant to be created and then live forever.
//
// I would love to register an at_exit() handler which cleans up this
// state, but libbacktrace provides no way to do so.
//
// With these constraints, this function has a statically cached state
// that is calculated the first time this is requested. Remember that
// backtracing all happens serially (one global lock).
//
// An additionally oddity in this function is that we initialize the
// filename via self_exe_name() to pass to libbacktrace. It turns out
// that on Linux libbacktrace seamlessly gets the filename of the
// current executable, but this fails on freebsd. by always providing
// it, we make sure that libbacktrace never has a reason to not look up
// the symbols. The libbacktrace API also states that the filename must
// be in "permanent memory", so we copy it to a static and then use the
// static as the pointer.
//
// FIXME: We also call self_exe_name() on DragonFly BSD. I haven't
//        tested if this is required or not.
The libbacktrace API supports creating a state, but it does not
support destroying a state. I personally take this to mean that a
state is meant to be created and then live forever.

I would love to register an at_exit() handler which cleans up this
state, but libbacktrace provides no way to do so.

With these constraints, this function has a statically cached state
that is calculated the first time this is requested. Remember that
backtracing all happens serially (one global lock).

An additionally oddity in this function is that we initialize the
filename via self_exe_name() to pass to libbacktrace. It turns out
that on Linux libbacktrace seamlessly gets the filename of the
current executable, but this fails on freebsd. by always providing
it, we make sure that libbacktrace never has a reason to not look up
the symbols. The libbacktrace API also states that the filename must
be in "permanent memory", so we copy it to a static and then use the
static as the pointer.

We also call self_exe_name() on DragonFly BSD. I haven't
tested if this is required or not.
The libbacktrace API supports creating a state but it does not support destroying a state . I personally take this to mean that a state is meant to be created and then live forever . I would love to register an at_exit () handler which cleans up this state but libbacktrace provides no way to do so . With these constraints this function has a statically cached state that is calculated the first time this is requested . Remember that backtracing all happens serially ( one global lock ) . An additionally oddity in this function is that we initialize the filename via self_exe_name () to pass to libbacktrace . It turns out that on Linux libbacktrace seamlessly gets the filename of the current executable but this fails on freebsd . by always providing it we make sure that libbacktrace never has a reason to not look up the symbols . The libbacktrace API also states that the filename must be in " permanent memory " so we copy it to a static and then use the static as the pointer . We also call self_exe_name () on DragonFly BSD . I haven ' t tested if this is required or not .
unsafe fn init_state() -> *mut backtrace_state {
        static mut STATE: *mut backtrace_state = ptr::null_mut();
        static mut LAST_FILENAME: [libc::c_char; 256] = [0; 256];
        if !STATE.is_null() { return STATE }
        let selfname = if cfg!(target_os = "freebsd") ||
            cfg!(target_os = "dragonfly") ||
            cfg!(target_os = "bitrig") ||
            cfg!(target_os = "openbsd") ||
            cfg!(target_os = "windows") {
                env::current_exe().ok()
            } else {
                None
            };
        let filename = match selfname.as_ref().and_then(|s| s.as_os_str().to_bytes()) {
            Some(path) => {
                let bytes = path;
                if bytes.len() < LAST_FILENAME.len() {
                    let i = bytes.iter();
                    for (slot, val) in LAST_FILENAME.iter_mut().zip(i) {
                        *slot = *val as libc::c_char;
                    }
                    LAST_FILENAME.as_ptr()
                } else {
                    ptr::null()
                }
            }
            None => ptr::null(),
        };
        STATE = backtrace_create_state(filename, 0, error_cb,
                                       ptr::null_mut());
        return STATE
    }
unsafe fn init_state ( ) -> * mut backtrace_state { static mut STATE : * mut backtrace_state = ptr :: null_mut ( ) ; static mut LAST_FILENAME : [ libc :: c_char ; 256 ] = [ 0 ; 256 ] ; if ! STATE . is_null ( ) { return STATE } let selfname = if cfg ! ( target_os " " ) || cfg ! ( target_os " " ) || cfg ! ( target_os " " ) || cfg ! ( target_os " " ) || cfg ! ( target_os " " ) { env :: current_exe ( ) . ok ( ) } else { None } ; let filename = match selfname . as_ref ( ) . and_then ( | s | s . as_os_str ( ) . to_bytes ( ) ) { Some ( path ) => { let bytes = path ; if bytes . len ( ) < LAST_FILENAME . len ( ) { let i = bytes . iter ( ) ; for ( slot , val ) in LAST_FILENAME . iter_mut ( ) . zip ( i ) { * slot = * val as libc :: c_char ; } LAST_FILENAME . as_ptr ( ) } else { ptr :: null ( ) } } None => ptr :: null ( ) , } ; STATE = backtrace_create_state ( filename , 0 , error_cb , ptr :: null_mut ( ) ) ; return STATE }
The libbacktrace API supports creating a state, but it does not
support destroying a state.
The libbacktrace API supports creating a state but it does not support destroying a state .