async_tensorrt/ffi/
error.rs1use cpp::cpp;
2
3pub fn get_last_error_message() -> String {
9 let error_boxed_ptr = cpp!(unsafe [] -> *mut std::ffi::c_void as "void*" {
12 const std::string lastError = GLOBAL_LOGGER.getLastError();
13 const char* lastErrorCstr = lastError.c_str();
14 void* lastErrorPtr = rust!(Logger_takeLastError [
15 lastErrorCstr : *const std::os::raw::c_char as "const char*"
16 ] -> *mut std::ffi::c_void as "void*" {
17 let error_boxed = Box::new(
18 std::ffi::CStr::from_ptr(lastErrorCstr)
19 .to_str()
20 .unwrap_or_default()
21 .to_owned()
22 );
23 Box::into_raw(error_boxed) as *mut std::ffi::c_void
24 });
25 return lastErrorPtr;
26 });
27 let error_boxed = unsafe { Box::from_raw(error_boxed_ptr as *mut String) };
30 let error = *error_boxed;
31 if !error.is_empty() {
32 error
33 } else {
34 "unknown error".to_string()
35 }
36}