use crate::util::access_sys_fn;
use std::ffi::CString;
#[derive(PartialEq, Eq, Debug)]
pub struct StringHandle(*mut ittapi_sys::__itt_string_handle);
impl StringHandle {
pub fn new(name: &str) -> Self {
#[cfg(unix)]
let create_fn = access_sys_fn!(__itt_string_handle_create_ptr__3_0);
#[cfg(windows)]
let create_fn = access_sys_fn!(__itt_string_handle_createA_ptr__3_0);
let c_string =
CString::new(name).expect("unable to create a CString; does it contain a 0 byte?");
let handle = unsafe { create_fn(c_string.as_ptr()) };
Self(handle)
}
pub(crate) fn as_ptr(&self) -> *mut ittapi_sys::__itt_string_handle {
self.0
}
}
impl From<&str> for StringHandle {
fn from(name: &str) -> Self {
Self::new(name)
}
}
mod tests {
#[test]
fn with_dynamic_part_specified() {
let _env_path = scoped_env::ScopedEnv::remove("INTEL_LIBITTNOTIFY64");
let sh = super::StringHandle::new("test2");
assert!(sh.as_ptr().is_null());
}
}