remove CString unwraps

no idea why windows needs an explicit decl, possible compiler bug?
This commit is contained in:
llama 2025-11-02 18:31:01 +08:00
parent 2c018574e1
commit 8ac763ceba
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3
2 changed files with 5 additions and 2 deletions

View file

@ -36,7 +36,7 @@ macro_rules! load_sym {
macro_rules! ffi { macro_rules! ffi {
($lib:expr, $exec:expr, $($field:ident),* $(,)?) => { ($lib:expr, $exec:expr, $($field:ident),* $(,)?) => {
#[allow(clippy::missing_transmute_annotations)] // they're not missing #[allow(clippy::missing_transmute_annotations)] // they're not missing
PyFfi { exec: $exec, $($field: load_sym!($lib, ::std::ffi::CString::new(stringify!($field)).unwrap()),)* lib: $lib, } PyFfi { exec: $exec, $($field: load_sym!($lib, ::std::ffi::CString::new(stringify!($field)).map_err(|_| anyhow::anyhow!("failed to construct symbol CString"))?),)* lib: $lib, }
}; };
} }

View file

@ -297,7 +297,10 @@ macro_rules! load_sym {
macro_rules! ffi { macro_rules! ffi {
($lib:expr, $exec:expr, $($field:ident),* $(,)?) => { ($lib:expr, $exec:expr, $($field:ident),* $(,)?) => {
#[allow(clippy::missing_transmute_annotations)] // they're not missing #[allow(clippy::missing_transmute_annotations)] // they're not missing
PyFfi { exec: $exec, $($field: load_sym!($lib, ::std::ffi::CString::new(stringify!($field)).unwrap()),)* lib: $lib.0, } PyFfi { exec: $exec, $($field: {
let sym = ::std::ffi::CString::new(stringify!($field)).map_err(|_| anyhow::anyhow!("failed to construct symbol CString"))?;
load_sym!($lib, sym)
},)* lib: $lib.0, }
}; };
} }