macro: ensure bootstrap functions happen only once

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-07-25 13:31:34 +02:00
parent 7b22916567
commit b94cbb8f16

View File

@ -104,8 +104,7 @@ impl Package {
}); });
} }
let bootstrap_name = let bootstrap_name = format!("boot_{}", self.attrs.package_name).replace("::", "__");
format!("boot_{}", self.attrs.package_name).replace("::", "__");
let bootstrap_ident = Ident::new(&bootstrap_name, Span::call_site()); let bootstrap_ident = Ident::new(&bootstrap_name, Span::call_site());
quote! { quote! {
@ -113,14 +112,17 @@ impl Package {
pub extern "C" fn #bootstrap_ident( pub extern "C" fn #bootstrap_ident(
_cv: &::perlmod::ffi::CV, _cv: &::perlmod::ffi::CV,
) { ) {
unsafe { static ONCE: ::std::sync::Once = ::std::sync::Once::new();
use ::perlmod::ffi::RSPL_newXS_flags; ONCE.call_once(|| {
unsafe {
use ::perlmod::ffi::RSPL_newXS_flags;
let argmark = ::perlmod::ffi::pop_arg_mark(); let argmark = ::perlmod::ffi::pop_arg_mark();
argmark.set_stack(); argmark.set_stack();
#newxs #newxs
} }
});
} }
} }
} }