diff --git a/src/session/builder/impl_options.rs b/src/session/builder/impl_options.rs index 24a7f8d5..ee55935a 100644 --- a/src/session/builder/impl_options.rs +++ b/src/session/builder/impl_options.rs @@ -1,4 +1,10 @@ -use std::{borrow::Cow, ffi::c_char, path::Path, rc::Rc, sync::Arc}; +use std::{ + borrow::Cow, + ffi::{CString, c_char}, + path::Path, + rc::Rc, + sync::Arc +}; use super::SessionBuilder; use crate::{ @@ -139,9 +145,9 @@ impl SessionBuilder { } pub fn with_external_initializer(mut self, name: impl AsRef, value: DynValue) -> Result { - let name = name.as_ref(); + let name = CString::new(name.as_ref())?; let value = Rc::new(value); - ortsys![unsafe AddExternalInitializers(self.session_options_ptr.as_ptr(), &name.as_ptr().cast::(), &value.ptr().cast_const(), 1)?]; + ortsys![unsafe AddExternalInitializers(self.session_options_ptr.as_ptr(), &name.as_ptr(), &value.ptr().cast_const(), 1)?]; self.external_initializers.push(value); Ok(self) }