about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-07-28 16:25:01 +0800
committerGitHub <noreply@github.com>2018-07-28 16:25:01 +0800
commit42e92d9ee53e6c9c66e811dca03c4584a7b4354c (patch)
tree9cfe3bd38d8106ad753bbc631dbf71f6cb5e4271 /src
parentb326319f156dc1aea0b3389eeee4e8ef1b073c2a (diff)
parentefa11da26a882aaf57f7eae747e48d128c474bf3 (diff)
downloadrust-42e92d9ee53e6c9c66e811dca03c4584a7b4354c.tar.gz
rust-42e92d9ee53e6c9c66e811dca03c4584a7b4354c.zip
Rollup merge of #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 #45410.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/dynamic_lib.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/librustc_metadata/dynamic_lib.rs b/src/librustc_metadata/dynamic_lib.rs
index d7da0d00012..182a071277e 100644
--- a/src/librustc_metadata/dynamic_lib.rs
+++ b/src/librustc_metadata/dynamic_lib.rs
@@ -90,30 +90,29 @@ mod tests {
     use std::mem;
 
     #[test]
-    fn test_loading_cosine() {
+    fn test_loading_atoi() {
         if cfg!(windows) {
             return
         }
 
-        // The math library does not need to be loaded since it is already
-        // statically linked in
-        let libm = match DynamicLibrary::open(None) {
+        // The C library does not need to be loaded since it is already linked in
+        let lib = match DynamicLibrary::open(None) {
             Err(error) => panic!("Could not load self as module: {}", error),
-            Ok(libm) => libm
+            Ok(lib) => lib
         };
 
-        let cosine: extern fn(libc::c_double) -> libc::c_double = unsafe {
-            match libm.symbol("cos") {
-                Err(error) => panic!("Could not load function cos: {}", error),
-                Ok(cosine) => mem::transmute::<*mut u8, _>(cosine)
+        let atoi: extern fn(*const libc::c_char) -> libc::c_int = unsafe {
+            match lib.symbol("atoi") {
+                Err(error) => panic!("Could not load function atoi: {}", error),
+                Ok(atoi) => mem::transmute::<*mut u8, _>(atoi)
             }
         };
 
-        let argument = 0.0;
-        let expected_result = 1.0;
-        let result = cosine(argument);
+        let argument = CString::new("1383428980").unwrap();
+        let expected_result = 0x52757374;
+        let result = atoi(argument.as_ptr());
         if result != expected_result {
-            panic!("cos({}) != {} but equaled {} instead", argument,
+            panic!("atoi({:?}) != {} but equaled {} instead", argument,
                    expected_result, result)
         }
     }