From 8b05b629ae1a8f73cbd70acdf0239c7a9b699827 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sun, 6 Aug 2023 13:20:58 +0100 Subject: [PATCH] Adjust binding macro --- src/abi.rs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/abi.rs b/src/abi.rs index ff22f47..7e1529b 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -97,17 +97,24 @@ pub type PersonalityRoutine = unsafe extern "C" fn( #[cfg(not(feature = "unwinder"))] macro_rules! binding { - ($(extern $abi: literal $([$t:tt])? fn $name: ident ($($arg: ident : $arg_ty: ty),*$(,)?) $(-> $ret: ty)?;)*) => { - $( - #[allow(non_snake_case)] - #[inline] - pub $($t)? fn $name($($arg: $arg_ty),*) $(-> $ret)? { - extern $abi { - fn $name($($arg: $arg_ty),*) $(-> $ret)?; - } - unsafe { $name($($arg),*) } + () => {}; + (unsafe extern $abi: literal fn $name: ident ($($arg: ident : $arg_ty: ty),*$(,)?) $(-> $ret: ty)?; $($rest: tt)*) => { + extern $abi { + pub fn $name($($arg: $arg_ty),*) $(-> $ret)?; + } + binding!($($rest)*); + }; + + (extern $abi: literal fn $name: ident ($($arg: ident : $arg_ty: ty),*$(,)?) $(-> $ret: ty)?; $($rest: tt)*) => { + #[allow(non_snake_case)] + #[inline] + pub fn $name($($arg: $arg_ty),*) $(-> $ret)? { + extern $abi { + fn $name($($arg: $arg_ty),*) $(-> $ret)?; } - )* + unsafe { $name($($arg),*) } + } + binding!($($rest)*); }; } @@ -134,19 +141,19 @@ binding! { extern "C" fn _Unwind_GetTextRelBase(unwind_ctx: &UnwindContext<'_>) -> usize; extern "C" fn _Unwind_GetDataRelBase(unwind_ctx: &UnwindContext<'_>) -> usize; extern "C" fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void; - extern "C-unwind" [unsafe] fn _Unwind_RaiseException( + unsafe extern "C-unwind" fn _Unwind_RaiseException( exception: *mut UnwindException, ) -> UnwindReasonCode; - extern "C-unwind" [unsafe] fn _Unwind_ForcedUnwind( + unsafe extern "C-unwind" fn _Unwind_ForcedUnwind( exception: *mut UnwindException, stop: UnwindStopFn, stop_arg: *mut c_void, ) -> UnwindReasonCode; - extern "C-unwind" [unsafe] fn _Unwind_Resume(exception: *mut UnwindException) -> !; - extern "C-unwind" [unsafe] fn _Unwind_Resume_or_Rethrow( + unsafe extern "C-unwind" fn _Unwind_Resume(exception: *mut UnwindException) -> !; + unsafe extern "C-unwind" fn _Unwind_Resume_or_Rethrow( exception: *mut UnwindException, ) -> UnwindReasonCode; - extern "C" [unsafe] fn _Unwind_DeleteException(exception: *mut UnwindException); + unsafe extern "C" fn _Unwind_DeleteException(exception: *mut UnwindException); extern "C-unwind" fn _Unwind_Backtrace( trace: UnwindTraceFn, trace_argument: *mut c_void,