Fix missing extern "C" for unsafe functions

`unsafe` functions were being matched in a different block that did not
include `extern $abi`. This means that some intrinsics were getting
generated with the Rust ABI rather than C.

Combine the last two blocks using an optional token matcher, which fixes
this problem and is cleaner.
This commit is contained in:
Trevor Gross 2024-07-18 03:25:03 -05:00
parent 56a2c50613
commit ddd97dc19a

View file

@ -449,14 +449,14 @@ macro_rules! intrinsics {
// input we were given.
(
$(#[$($attr:tt)*])*
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
pub $(unsafe $(@ $empty:tt)?)? extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
$($body:tt)*
}
$($rest:tt)*
) => (
$(#[$($attr)*])*
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
pub $(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
$($body)*
}
@ -465,34 +465,7 @@ macro_rules! intrinsics {
$(#[$($attr)*])*
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}
intrinsics!($($rest)*);
);
// Same as the above for unsafe functions.
(
$(#[$($attr:tt)*])*
pub unsafe extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
$($body:tt)*
}
$($rest:tt)*
) => (
$(#[$($attr)*])*
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
$($body)*
}
#[cfg(not(feature = "mangled-names"))]
mod $name {
$(#[$($attr)*])*
#[no_mangle]
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
unsafe fn $name( $($argname: $ty),* ) $(-> $ret)? {
$(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
}