sharedlib
sharedlib copied to clipboard
cargo test fails on macOS
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
Friendly ping
Hey Jack,
I got your message. I will be away for a 2 weeks so I may not have time to look at this for awhile. Additionally, I do not have a Mac so I have to do all of the testing with Travis :/ However, you may be able to get by with the repository I branched from: nagisa/lib_loading. At the very least, you may be able to come up with a solution on your own if you take a look at his branch and diff any changes after my last commit.
On Sep 18, 2018, at 10:55, jackcmay [email protected] wrote:
Friendly ping
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
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();
Is CString preferred over PathBuf?
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.
Continued discussion in #10.