From ebd82cb7ac76d9a3efc6d92007ff718719ab735c Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 4 Jan 2022 09:55:53 +0100 Subject: [PATCH] perlmod: ffi: support visibility in perl_fn Signed-off-by: Wolfgang Bumiller --- perlmod/src/ffi.rs | 103 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 10 deletions(-) diff --git a/perlmod/src/ffi.rs b/perlmod/src/ffi.rs index 193e409..4d30d02 100644 --- a/perlmod/src/ffi.rs +++ b/perlmod/src/ffi.rs @@ -65,6 +65,74 @@ pub struct Interpreter { _ffi: usize, } +#[macro_export] +macro_rules! perl_fn { + // inherited visibility + ($( + $(#[$attr:meta])* + extern "C" fn($($args:tt)*) $(-> $re:ty)? + )*) => { + $crate::perl_fn_impl! { + $( + $(#[$attr])* + () extern "C" fn($($args)*) $(-> $re)? + )* + } + }; + ($( + $(#[$attr:meta])* + extern "C" fn $name:ident $(<($($gen:tt)*)>)? ($($args:tt)*) $(-> $re:ty)? + $(where ($($where_clause:tt)*))? + { + $($code:tt)* + } + )*) => { + $crate::perl_fn_impl! { + $( + $(#[$attr])* + () extern "C" fn $name $(<($($gen)*)>)? ($($args)*) $(-> $re)? + $(where ($($where_clause)*))? + { + $($code)* + } + )* + } + }; + + // same with 'pub' visibility + ($( + $(#[$attr:meta])* + pub $(($($vis:tt)+))? extern "C" fn($($args:tt)*) $(-> $re:ty)? + )*) => { + $crate::perl_fn_impl! { + $( + $(#[$attr])* + (pub $(($($vis)+))?) extern "C" fn($($args)*) $(-> $re)? + )* + } + }; + ($( + $(#[$attr:meta])* + pub $(($($vis:tt)+))? + extern "C" fn $name:ident $(<($($gen:tt)*)>)? ($($args:tt)*) $(-> $re:ty)? + $(where ($($where_clause:tt)*))? + { + $($code:tt)* + } + )*) => { + $crate::perl_fn_impl! { + $( + $(#[$attr])* + (pub $(($($vis)+))?) extern "C" fn $name $(<($($gen)*)>)? ($($args)*) $(-> $re)? + $(where ($($where_clause)*))? + { + $($code)* + } + )* + } + }; +} + #[cfg(perlmod = "multiplicity")] mod vtbl_types_impl { use super::{Interpreter, MAGIC, SV}; @@ -91,23 +159,32 @@ mod vtbl_types_impl { ) -> c_int; pub type Local = extern "C" fn(_perl: *const Interpreter, sv: *mut SV, mg: *mut MAGIC) -> c_int; + #[doc(hidden)] #[macro_export] - macro_rules! perl_fn { + macro_rules! perl_fn_impl { ($( $(#[$attr:meta])* - extern "C" fn($($args:tt)*) $(-> $re:ty)? + ($($vis:tt)*) extern "C" fn($($args:tt)*) $(-> $re:ty)? )*) => {$( $(#[$attr])* - extern "C" fn(*const $crate::ffi::Interpreter, $($args)*) $(-> $re)? + $($vis)* extern "C" fn(*const $crate::ffi::Interpreter, $($args)*) $(-> $re)? )*}; ($( $(#[$attr:meta])* - extern "C" fn $name:ident ($($args:tt)*) $(-> $re:ty)? { + ($($vis:tt)*) + extern "C" fn $name:ident $(<($($gen:tt)*)>)? ($($args:tt)*) $(-> $re:ty)? + $(where ($($where_clause:tt)*))? + { $($code:tt)* } )*) => {$( $(#[$attr])* - extern "C" fn $name (_perl: *const $crate::ffi::Interpreter, $($args)*) $(-> $re)? { + $($vis)* extern "C" fn $name $(<$($gen)*>)? ( + _perl: *const $crate::ffi::Interpreter, + $($args)* + ) $(-> $re)? + $(where $($where_clause)*)? + { $($code)* } )*}; @@ -135,23 +212,29 @@ mod vtbl_types_impl { extern "C" fn(sv: *mut SV, mg: *mut MAGIC, clone_parms: *mut super::Unsupported) -> c_int; pub type Local = extern "C" fn(sv: *mut SV, mg: *mut MAGIC) -> c_int; + #[doc(hidden)] #[macro_export] - macro_rules! perl_fn { + macro_rules! perl_fn_impl { ($( $(#[$attr:meta])* - extern "C" fn($($args:tt)*) $(-> $re:ty)? + ($($vis:tt)*) extern "C" fn($($args:tt)*) $(-> $re:ty)? )*) => {$( $(#[$attr])* - extern "C" fn($($args)*) $(-> $re)? + $($vis)* extern "C" fn($($args)*) $(-> $re)? )*}; ($( $(#[$attr:meta])* - extern "C" fn $name:ident ($($args:tt)*) $(-> $re:ty)? { + ($($vis:tt)*) + extern "C" fn $name:ident $(<($($gen:tt)*)>)? ($($args:tt)*) $(-> $re:ty)? + $(where ($($where_clause:tt)*))? + { $($code:tt)* } )*) => {$( $(#[$attr])* - extern "C" fn $name ($($args)*) $(-> $re)? { + $($vis)* extern "C" fn $name $(<$($gen)*>)? ($($args)*) $(-> $re)? + $(where $($where_clause)*)? + { $($code)* } )*};