Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check err status for rust #192

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches: [ main ]
paths:
- 'binding/rust/**'
- 'binding/rust/**/*.rs'
- '!binding/rust/README.md'
- 'lib/beaglebone/**'
- 'lib/jetson/**'
Expand All @@ -18,6 +19,7 @@ on:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'binding/rust/**'
- 'binding/rust/**/*.rs'
- '!binding/rust/README.md'
- 'lib/beaglebone/**'
- 'lib/jetson/**'
Expand Down
11 changes: 9 additions & 2 deletions binding/rust/src/cobra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type PvCobraProcessFn =
unsafe extern "C" fn(object: *mut CCobra, pcm: *const i16, is_voiced: *mut f32) -> PvStatus;
type PvCobraDeleteFn = unsafe extern "C" fn(object: *mut CCobra);
type PvGetErrorStackFn =
unsafe extern "C" fn(message_stack: *mut *mut *mut c_char, message_stack_depth: *mut i32);
unsafe extern "C" fn(message_stack: *mut *mut *mut c_char, message_stack_depth: *mut i32)-> PvStatus;
type PvFreeErrorStackFn = unsafe extern "C" fn(message_stack: *mut *mut c_char);
type PvSetSdkFn = unsafe extern "C" fn(sdk: *const c_char);

Expand Down Expand Up @@ -183,11 +183,18 @@ fn check_fn_call_status(
let mut message_stack_ptr_ptr = addr_of_mut!(message_stack_ptr);

let mut message_stack_depth: i32 = 0;
(vtable.pv_get_error_stack)(
let err_status = (vtable.pv_get_error_stack)(
addr_of_mut!(message_stack_ptr_ptr),
addr_of_mut!(message_stack_depth),
);

if err_status != PvStatus::SUCCESS {
return Err(CobraError::new(
CobraErrorStatus::LibraryError(err_status),
"Unable to get Cobra error state",
));
};

let mut message_stack = Vec::new();
for i in 0..message_stack_depth as usize {
let message = CStr::from_ptr(*message_stack_ptr_ptr.add(i));
Expand Down
Loading