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
#![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] use std::os::raw::c_char; use std::ffi::CStr; mod binding; pub use self::binding::*; pub fn error_message(ptr: *mut c_char) -> String { let c_str = unsafe { CStr::from_ptr(ptr) }; let s = format!("{}", c_str.to_string_lossy()); unsafe { cft_str_free(ptr); } s } #[macro_export] macro_rules! ffi_try { ($func:ident($($arg:expr),*)) => ({ use std::ptr; let mut err = ptr::null_mut(); let res = $crate::$func($($arg),*, &mut err); if !err.is_null() { return Err($crate::error_message(err)); } res }) }