Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo test fails on macOS #11

Open
jackcmay opened this issue Sep 12, 2018 · 6 comments
Open

cargo test fails on macOS #11

jackcmay opened this issue Sep 12, 2018 · 6 comments

Comments

@jackcmay
Copy link

Interested in using this project but when I ran the tests I got failures, please advise:

thread 'test::shared::check_test_value' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("test/.build/libexamplelib.dylib"), State { next_error: Some(Error(OsError("dlopen(test/.build/libexamplelib.dylibassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::shared::create_struct_unsafe stdout ----
thread 'test::shared::create_struct_unsafe' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("test/.build/libexamplelib.dylib"), State { next_error: Some(Error(OsError("dlopen(test/.build/libexamplelib.dylibassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- test::shared::add_2_numbers stdout ----
thread 'test::shared::add_2_numbers' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("test/.build/libexamplelib.dylib"), State { next_error: Some(Error(OsError("dlopen(test/.build/libexamplelib.dylibassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::shared::create_struct_arc stdout ----
thread 'test::shared::create_struct_arc' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("test/.build/libexamplelib.dylib"), State { next_error: Some(Error(OsError("dlopen(test/.build/libexamplelib.dylibassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::shared::create_struct_safe stdout ----
thread 'test::shared::create_struct_safe' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("test/.build/libexamplelib.dylib"), State { next_error: Some(Error(OsError("dlopen(test/.build/libexamplelib.dylibassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::shared::load_examplelib stdout ----
thread 'test::shared::load_examplelib' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("test/.build/libexamplelib.dylib"), State { next_error: Some(Error(OsError("dlopen(test/.build/libexamplelib.dylibassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::unix::shared::libm_ceil stdout ----
thread 'test::unix::shared::libm_ceil' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("libm.dylib"), State { next_error: Some(Error(OsError("dlopen(libm.dylibmassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::unix::shared::new_libm stdout ----
thread 'test::unix::shared::new_libm' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("libm.dylib"), State { next_error: Some(Error(OsError("dlopen(libm.dylibmassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5

---- test::unix::shared::libm_ceil0 stdout ----
thread 'test::unix::shared::libm_ceil0' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LibraryOpen("libm.dylib"), State { next_error: Some(Error(OsError("dlopen(libm.dylibmassertion failed: `(left == right)`\n  left: ``,\n right: ``, 1): image not found", "dlopen"), State { next_error: None })) })', libcore/result.rs:945:5
@jackcmay
Copy link
Author

Friendly ping

@tyleo
Copy link
Owner

tyleo commented Sep 19, 2018 via email

@Maximiato
Copy link

Maximiato commented Sep 21, 2018

I noticed some odd path problems on macOS too. Think there might be a missing \0 termination on the library path string. Patch below fixed it for me. I can try to get a fork and pull request up if people are interested. Looks like this is a duplicate of #10 as well.

--- a/sharedlib/src/os/unix/lib.rs
+++ b/sharedlib/src/os/unix/lib.rs
@@ -3,6 +3,7 @@ use os::unix::external;
 use util;
+use std::ffi::CString;
 use std::mem;
@@ -16,11 +17,9 @@ pub struct Lib {
 impl Lib {
     pub unsafe fn new<TPath>(path_to_lib: TPath) -> Result<Lib>
         where TPath: AsRef<Path> {
-        let path_to_lib_str =
-            path_to_lib
-                .as_ref()
-                .to_string_lossy();
-        let path_to_lib_c_str = path_to_lib_str.as_ptr() as *const c_char;
+        let path_to_lib_c_string = CString::new(path_to_lib.as_ref().to_string_lossy().as_ref())
+            .chain_err(|| ErrorKind::LibraryOpen(path_to_lib.as_ref().to_path_buf()))?;
+        let path_to_lib_c_str = path_to_lib_c_string.as_ptr();

@jackcmay
Copy link
Author

Is CString preferred over PathBuf?

@Maximiato
Copy link

PathBuf is not \0 terminated like CString and CString eliminates the need for casting to *const c_char. It might be even cleaner to use as_os_str for the conversion to guarantee the right encoding, but I'm not sure. I had a brief look yesterday at fixing this for all the cargo tests (not just the use case my patch worked for), I still saw some failed tests and haven't had the time to get to the bottom yet.

@Maximiato
Copy link

Continued discussion in #10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants