Skip to content

Commit 42e92d9

Browse files
authored
Rollup merge of rust-lang#52760 - cuviper:test_loading_atoi, r=alexcrichton
rustc_metadata: test loading atoi instead of cos Some platforms don't actually have `libm` already linked in the test infrastructure, and then `dynamic_lib::tests::test_loading_cosine` would fail to find the "cos" symbol. Every platform running this test should have `libc` and "atoi" though, so try to use that symbol instead. Fixes rust-lang#45410.
2 parents b326319 + efa11da commit 42e92d9

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/librustc_metadata/dynamic_lib.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,29 @@ mod tests {
9090
use std::mem;
9191

9292
#[test]
93-
fn test_loading_cosine() {
93+
fn test_loading_atoi() {
9494
if cfg!(windows) {
9595
return
9696
}
9797

98-
// The math library does not need to be loaded since it is already
99-
// statically linked in
100-
let libm = match DynamicLibrary::open(None) {
98+
// The C library does not need to be loaded since it is already linked in
99+
let lib = match DynamicLibrary::open(None) {
101100
Err(error) => panic!("Could not load self as module: {}", error),
102-
Ok(libm) => libm
101+
Ok(lib) => lib
103102
};
104103

105-
let cosine: extern fn(libc::c_double) -> libc::c_double = unsafe {
106-
match libm.symbol("cos") {
107-
Err(error) => panic!("Could not load function cos: {}", error),
108-
Ok(cosine) => mem::transmute::<*mut u8, _>(cosine)
104+
let atoi: extern fn(*const libc::c_char) -> libc::c_int = unsafe {
105+
match lib.symbol("atoi") {
106+
Err(error) => panic!("Could not load function atoi: {}", error),
107+
Ok(atoi) => mem::transmute::<*mut u8, _>(atoi)
109108
}
110109
};
111110

112-
let argument = 0.0;
113-
let expected_result = 1.0;
114-
let result = cosine(argument);
111+
let argument = CString::new("1383428980").unwrap();
112+
let expected_result = 0x52757374;
113+
let result = atoi(argument.as_ptr());
115114
if result != expected_result {
116-
panic!("cos({}) != {} but equaled {} instead", argument,
115+
panic!("atoi({:?}) != {} but equaled {} instead", argument,
117116
expected_result, result)
118117
}
119118
}

0 commit comments

Comments
 (0)