Skip to content

Commit 6c37129

Browse files
committed
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.
1 parent 06db2de commit 6c37129

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

src/macros.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -449,41 +449,14 @@ macro_rules! intrinsics {
449449
// input we were given.
450450
(
451451
$(#[$($attr:tt)*])*
452-
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
453-
$($body:tt)*
454-
}
455-
456-
$($rest:tt)*
457-
) => (
458-
$(#[$($attr)*])*
459-
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
460-
$($body)*
461-
}
462-
463-
#[cfg(not(feature = "mangled-names"))]
464-
mod $name {
465-
$(#[$($attr)*])*
466-
#[no_mangle]
467-
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
468-
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
469-
super::$name($($argname),*)
470-
}
471-
}
472-
473-
intrinsics!($($rest)*);
474-
);
475-
476-
// Same as the above for unsafe functions.
477-
(
478-
$(#[$($attr:tt)*])*
479-
pub unsafe extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
452+
pub $(unsafe $(@ $empty:tt)?)? extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
480453
$($body:tt)*
481454
}
482455

483456
$($rest:tt)*
484457
) => (
485458
$(#[$($attr)*])*
486-
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
459+
pub $(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
487460
$($body)*
488461
}
489462

@@ -492,7 +465,7 @@ macro_rules! intrinsics {
492465
$(#[$($attr)*])*
493466
#[no_mangle]
494467
#[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
495-
unsafe fn $name( $($argname: $ty),* ) $(-> $ret)? {
468+
$(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
496469
super::$name($($argname),*)
497470
}
498471
}

0 commit comments

Comments
 (0)