Skip to content

Commit

Permalink
rust: Use c_char for ffi.
Browse files Browse the repository at this point in the history
  • Loading branch information
hgaiser committed Oct 26, 2023
1 parent 2a1fd25 commit be2bdca
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions rust/onnxruntime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ to download.
//! See the [`sample.rs`](https://github.com/nbigaouette/onnxruntime-rs/blob/main/onnxruntime/examples/sample.rs)
//! example for more details.
use std::ffi::c_char;

use onnxruntime_sys as sys;

// Make functions `extern "stdcall"` for Windows 32bit.
Expand Down Expand Up @@ -187,7 +189,7 @@ use sys::OnnxEnumInt;
// Re-export ndarray as it's part of the public API anyway
pub use ndarray;

fn char_p_to_string(raw: *const i8) -> Result<String> {
fn char_p_to_string(raw: *const c_char) -> Result<String> {
let c_string = unsafe { std::ffi::CStr::from_ptr(raw as *mut i8).to_owned() };

match c_string.into_string() {
Expand All @@ -201,7 +203,7 @@ mod onnxruntime {
//! Module containing a custom logger, used to catch the runtime's own logging and send it
//! to Rust's tracing logging instead.
use std::ffi::CStr;
use std::ffi::{CStr, c_char};
use tracing::{debug, error, info, span, trace, warn, Level};

use onnxruntime_sys as sys;
Expand Down Expand Up @@ -240,10 +242,10 @@ mod onnxruntime {
pub(crate) fn custom_logger(
_params: *mut std::ffi::c_void,
severity: sys::OrtLoggingLevel,
category: *const i8,
logid: *const i8,
code_location: *const i8,
message: *const i8,
category: *const c_char,
logid: *const c_char,
code_location: *const c_char,
message: *const c_char,
) {
let log_level = match severity {
sys::OrtLoggingLevel::ORT_LOGGING_LEVEL_VERBOSE => Level::TRACE,
Expand Down

0 comments on commit be2bdca

Please sign in to comment.