Expose from_raw for Status

This commit is contained in:
Christopher Chalmers 2020-05-30 11:56:09 +01:00
parent 4d1f3edd5d
commit be0e5eb9da
2 changed files with 7 additions and 9 deletions

View File

@ -16,7 +16,7 @@ macro_rules! call {
// the checked call that returns Ok(res) on success
($name:ident, $($arg:expr),* => $res:expr) => {{
let status = call!(@raw $name, $($arg),*);
match crate::Status::new(status) {
match crate::Status::from_raw(status) {
Some(status) => std::result::Result::Err(crate::Error::OrtError(status)),
None => std::result::Result::Ok($res),
}

View File

@ -90,19 +90,17 @@ impl From<ffi::NulError> for Error {
pub type Result<T> = std::result::Result<T, Error>;
impl Status {
fn new(raw: *mut sys::Status) -> Option<Status> {
pub unsafe fn from_raw(raw: *mut sys::Status) -> Option<Status> {
if raw.is_null() {
return None;
}
let error_code = call!(@unsafe @raw GetErrorCode, raw);
let error_msg = unsafe {
CStr::from_ptr(call!(@raw GetErrorMessage, raw))
.to_string_lossy()
.into_owned()
};
let error_code = call!(@raw GetErrorCode, raw);
let error_msg = CStr::from_ptr(call!(@raw GetErrorMessage, raw))
.to_string_lossy()
.into_owned();
call!(@unsafe @raw ReleaseStatus, raw);
call!(@raw ReleaseStatus, raw);
Some(Status {
error_code,