Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit a27bd10

Browse files
committed
Make all public APIs extern C to enforce nounwind and C API compat
1 parent a11a6fe commit a27bd10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+121
-126
lines changed

crates/libm-analyze/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,18 @@ fn get_functions(files: &[syn::File]) -> Vec<FnSig> {
212212
));
213213
}
214214
if attrs.is_empty() {
215-
err!(format!(
216-
"missing `#[inline]` and `#[no_panic]` attributes"
217-
));
215+
err!(format!("missing `#[inline]` and `#[no_panic]` attributes"));
218216
} else {
219217
let attrs = attrs
220218
.iter()
221219
.map(|a| syn_to_str!(a))
222220
.collect::<Vec<_>>()
223221
.join(",");
224222
if !attrs.contains("inline") {
225-
err!(format!(
226-
"missing `#[inline]` attribute"
227-
));
223+
err!(format!("missing `#[inline]` attribute"));
228224
}
229225
if !attrs.contains("no_panic") {
230-
err!(format!(
231-
"missing `#[no_panic]` attributes"
232-
));
226+
err!(format!("missing `#[no_panic]` attributes"));
233227
}
234228
}
235229
// Validate and parse output parameters and function arguments:

crates/libm-test/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ fn main() {
1313

1414
if profile == "release" || opt_level > 0 {
1515
match target.as_str() {
16-
"x86_64-unknown-linux-gnu" |
17-
"x86_64-apple-darwin" |
18-
"x86_64-pc-windows-msvc" => {
16+
"x86_64-unknown-linux-gnu" | "x86_64-apple-darwin" | "x86_64-pc-windows-msvc" => {
1917
println!("cargo:rustc-cfg=exhaustive32");
2018
}
2119
_ => (),

crates/libm-test/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ macro_rules! assert_approx_eq {
112112
if !$crate::WithinUlps::within_ulps($result, $expected, $ulps) {
113113
let f = format!(
114114
"{}{:?} returns = {:?} != {:?} (expected)",
115-
stringify!($id), $arg, $result, $expected
115+
stringify!($id),
116+
$arg,
117+
$result,
118+
$expected
116119
);
117120
panic!(f);
118121
}
119-
}
122+
};
120123
}

crates/libm-test/tests/exhaustive32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Exhaustively test unary APIs taking 32-bit wide arguments.
22
#![cfg(test)]
33
#![cfg(exhaustive32)]
4-
use libm_test::{assert_approx_eq};
4+
use libm_test::assert_approx_eq;
55

66
macro_rules! exhaustive32 {
77
// Skip those parts of the API that are not

crates/libm-test/tests/system_libm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![cfg(test)]
33
#![cfg(feature = "system_libm")]
44

5-
use libm_test::{adjust_input, Call, assert_approx_eq};
5+
use libm_test::{adjust_input, assert_approx_eq, Call};
66

77
// Number of tests to generate for each function
88
const NTESTS: usize = 500;

crates/libm/src/math/acos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn r(z: f64) -> f64 {
6262
/// Returns values in radians, in the range of 0 to pi.
6363
#[inline]
6464
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
65-
pub fn acos(x: f64) -> f64 {
65+
pub extern "C" fn acos(x: f64) -> f64 {
6666
let x1p_120f = f64::from_bits(0x3870000000000000); // 0x1p-120 === 2 ^ -120
6767
let z: f64;
6868
let w: f64;

crates/libm/src/math/acosf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn r(z: f32) -> f32 {
3636
/// Returns values in radians, in the range of 0 to pi.
3737
#[inline]
3838
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
39-
pub fn acosf(x: f32) -> f32 {
39+
pub extern "C" fn acosf(x: f32) -> f32 {
4040
let x1p_120 = f32::from_bits(0x03800000); // 0x1p-120 === 2 ^ (-120)
4141

4242
let z: f32;

crates/libm/src/math/acosh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa3
99
/// `x` must be a number greater than or equal to 1.
1010
#[inline]
1111
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
12-
pub fn acosh(x: f64) -> f64 {
12+
pub extern "C" fn acosh(x: f64) -> f64 {
1313
let u = x.to_bits();
1414
let e = ((u >> 52) as usize) & 0x7ff;
1515

crates/libm/src/math/acoshf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const LN2: f32 = 0.693147180559945309417232121458176568;
99
/// `x` must be a number greater than or equal to 1.
1010
#[inline]
1111
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
12-
pub fn acoshf(x: f32) -> f32 {
12+
pub extern "C" fn acoshf(x: f32) -> f32 {
1313
let u = x.to_bits();
1414
let a = u & 0x7fffffff;
1515

crates/libm/src/math/asin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn comp_r(z: f64) -> f64 {
6969
/// Returns values in radians, in the range of -pi/2 to pi/2.
7070
#[inline]
7171
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
72-
pub fn asin(mut x: f64) -> f64 {
72+
pub extern "C" fn asin(mut x: f64) -> f64 {
7373
let z: f64;
7474
let r: f64;
7575
let s: f64;

0 commit comments

Comments
 (0)