1 |
From efa11da26a882aaf57f7eae747e48d128c474bf3 Mon Sep 17 00:00:00 2001 |
2 |
From: Josh Stone <jistone@redhat.com> |
3 |
Date: Thu, 26 Jul 2018 17:20:02 -0700 |
4 |
Subject: [PATCH] rustc_metadata: test loading atoi instead of cos |
5 |
|
6 |
Some platforms don't actually have `libm` already linked in the test |
7 |
infrastructure, and then `dynamic_lib::tests::test_loading_cosine` would |
8 |
fail to find the "cos" symbol. Every platform running this test should |
9 |
have `libc` and "atoi" though, so try to use that symbol instead. |
10 |
|
11 |
Fixes #45410. |
12 |
--- |
13 |
src/librustc_metadata/dynamic_lib.rs | 25 ++++++++++++------------- |
14 |
1 file changed, 12 insertions(+), 13 deletions(-) |
15 |
|
16 |
diff --git a/src/librustc_metadata/dynamic_lib.rs b/src/librustc_metadata/dynamic_lib.rs |
17 |
index d7da0d00012e..182a071277ec 100644 |
18 |
--- a/src/librustc_metadata/dynamic_lib.rs |
19 |
+++ b/src/librustc_metadata/dynamic_lib.rs |
20 |
@@ -90,30 +90,29 @@ mod tests { |
21 |
use std::mem; |
22 |
|
23 |
#[test] |
24 |
- fn test_loading_cosine() { |
25 |
+ fn test_loading_atoi() { |
26 |
if cfg!(windows) { |
27 |
return |
28 |
} |
29 |
|
30 |
- // The math library does not need to be loaded since it is already |
31 |
- // statically linked in |
32 |
- let libm = match DynamicLibrary::open(None) { |
33 |
+ // The C library does not need to be loaded since it is already linked in |
34 |
+ let lib = match DynamicLibrary::open(None) { |
35 |
Err(error) => panic!("Could not load self as module: {}", error), |
36 |
- Ok(libm) => libm |
37 |
+ Ok(lib) => lib |
38 |
}; |
39 |
|
40 |
- let cosine: extern fn(libc::c_double) -> libc::c_double = unsafe { |
41 |
- match libm.symbol("cos") { |
42 |
- Err(error) => panic!("Could not load function cos: {}", error), |
43 |
- Ok(cosine) => mem::transmute::<*mut u8, _>(cosine) |
44 |
+ let atoi: extern fn(*const libc::c_char) -> libc::c_int = unsafe { |
45 |
+ match lib.symbol("atoi") { |
46 |
+ Err(error) => panic!("Could not load function atoi: {}", error), |
47 |
+ Ok(atoi) => mem::transmute::<*mut u8, _>(atoi) |
48 |
} |
49 |
}; |
50 |
|
51 |
- let argument = 0.0; |
52 |
- let expected_result = 1.0; |
53 |
- let result = cosine(argument); |
54 |
+ let argument = CString::new("1383428980").unwrap(); |
55 |
+ let expected_result = 0x52757374; |
56 |
+ let result = atoi(argument.as_ptr()); |
57 |
if result != expected_result { |
58 |
- panic!("cos({}) != {} but equaled {} instead", argument, |
59 |
+ panic!("atoi({:?}) != {} but equaled {} instead", argument, |
60 |
expected_result, result) |
61 |
} |
62 |
} |