@@ -25,14 +25,12 @@ use crate::{
25
25
26
26
impl VoicevoxOnnxruntime {
27
27
#[ cfg( feature = "load-onnxruntime" ) ]
28
- pub ( crate ) fn lib_versioned_filename ( ) -> & ' static std:: ffi:: CStr {
29
- to_cstr ! ( voicevox_core:: blocking:: Onnxruntime :: LIB_VERSIONED_FILENAME )
30
- }
28
+ pub ( crate ) const LIB_VERSIONED_FILENAME : & ' static std:: ffi:: CStr =
29
+ to_cstr ! ( voicevox_core:: blocking:: Onnxruntime :: LIB_VERSIONED_FILENAME ) ;
31
30
32
31
#[ cfg( feature = "load-onnxruntime" ) ]
33
- pub ( crate ) fn lib_unversioned_filename ( ) -> & ' static std:: ffi:: CStr {
34
- to_cstr ! ( voicevox_core:: blocking:: Onnxruntime :: LIB_UNVERSIONED_FILENAME )
35
- }
32
+ pub ( crate ) const LIB_UNVERSIONED_FILENAME : & ' static std:: ffi:: CStr =
33
+ to_cstr ! ( voicevox_core:: blocking:: Onnxruntime :: LIB_UNVERSIONED_FILENAME ) ;
36
34
37
35
#[ ref_cast_custom]
38
36
fn new ( rust : & voicevox_core:: blocking:: Onnxruntime ) -> & Self ;
@@ -61,11 +59,11 @@ impl VoicevoxOnnxruntime {
61
59
#[ cfg( feature = "load-onnxruntime" ) ]
62
60
macro_rules! to_cstr {
63
61
( $s: expr) => { {
64
- const __RUST_STR : & str = $s ;
65
- static __C_STR : & [ u8 ] = const_format :: concatcp! ( __RUST_STR , '\0' ) . as_bytes ( ) ;
66
-
67
- std:: ffi:: CStr :: from_bytes_with_nul ( __C_STR )
68
- . unwrap_or_else ( |e| panic! ( "{__RUST_STR:?} should not contain ` \\ 0`: {e}" ) )
62
+ static CSTR : & [ u8 ] = const_format :: concatcp! ( $s , '\0' ) . as_bytes ( ) ;
63
+ unsafe {
64
+ // SAFETY: added a nul with `concatcp!`
65
+ std:: ffi:: CStr :: from_bytes_with_nul_unchecked ( CSTR )
66
+ }
69
67
} } ;
70
68
}
71
69
#[ cfg( feature = "load-onnxruntime" ) ]
0 commit comments