#[macro_export]
macro_rules! borrow_string {
($cstr:expr) => {{
if $cstr.is_null() {
""
} else {
#[allow(unused_unsafe)]
unsafe {
let c_str = std::ffi::CStr::from_ptr($cstr);
c_str.to_str().unwrap_or("")
}
}
}};
}
#[macro_export]
macro_rules! own_string {
($cstr:expr) => {{
if $cstr.is_null() {
String::new()
} else {
#[allow(unused_unsafe)]
let owned_string = unsafe { std::ffi::CString::from_raw($cstr) };
owned_string
.into_string()
.unwrap_or_else(|_| String::from("Invalid UTF-8"))
}
}};
}
#[macro_export]
macro_rules! create_raw_string {
($rstr:expr) => {{
std::ffi::CString::new($rstr).unwrap().into_raw() }};
}
#[macro_export]
macro_rules! free_raw_string {
($rptr:expr) => {{
if !$rptr.is_null() {
let _ = std::ffi::CString::from_raw($rptr);
}
}};
}
#[macro_export]
macro_rules! borrow_var {
($var:expr) => {{
unsafe{ pxs_Var::from_borrow($var) }
}};
}
#[macro_export]
macro_rules! own_var {
($var:expr) => {{
pxs_Var::from_raw($var)
}};
}