macro: export: copy use chosen visibility

when using the export macro directly without a package we
previously always used
    #[no_mangle]
    pub extern "C"
now instead of 'pub' we copy the original function's
visibility

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-12-22 10:12:48 +01:00
parent 100414d678
commit 9bf583ca64

View File

@ -69,6 +69,7 @@ pub fn handle_function(
} }
let name = func.sig.ident.clone(); let name = func.sig.ident.clone();
let export_public = export_public.then(|| &func.vis);
let xs_name = attr let xs_name = attr
.xs_name .xs_name
.clone() .clone()
@ -283,16 +284,15 @@ fn handle_return_kind(
xs_name: &Ident, xs_name: &Ident,
impl_xs_name: &Ident, impl_xs_name: &Ident,
passed_arguments: TokenStream, passed_arguments: TokenStream,
export_public: bool, export_public: Option<&syn::Visibility>,
) -> Result<ReturnHandling, Error> { ) -> Result<ReturnHandling, Error> {
let return_type; let return_type;
let mut handle_return; let mut handle_return;
let wrapper_func; let wrapper_func;
let vis = if export_public { let vis = match export_public {
quote! { #[no_mangle] pub } Some(vis) => quote! { #[no_mangle] #vis },
} else { None => quote! { #[allow(non_snake_case)] },
quote! { #[allow(non_snake_case)] }
}; };
let pthx = crate::pthx_param(); let pthx = crate::pthx_param();