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