Skip to content

Commit 13aeb42

Browse files
committed
Print error on dlopen error
1 parent a14a935 commit 13aeb42

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

gccjit_sys/src/dynload.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ pub use self::platform::Library;
44

55
#[cfg(unix)]
66
mod platform {
7-
use std::ffi::{CStr, c_int, c_void};
7+
use std::ffi::{CStr, c_char, c_int, c_void};
88

99
#[link(name="dl")]
1010
extern "C" {
1111
fn dlopen(filename: *const i8, flag: c_int) -> *mut c_void;
1212
fn dlsym(handle: *mut c_void, symbol: *const i8) -> *mut c_void;
1313
fn dlclose(handle: *mut c_void) -> c_int;
14+
fn dlerror() -> *const c_char;
1415
}
1516

1617
pub struct Library(*mut c_void);
@@ -23,9 +24,13 @@ mod platform {
2324
const RTLD_NOW: c_int = 2;
2425
let handle = dlopen(path.as_ptr(), RTLD_NOW);
2526
if handle.is_null() {
27+
let cstr = dlerror();
28+
let cstr = CStr::from_ptr(cstr);
29+
eprintln!("Dlerror: {:?}", cstr);
2630
None
2731
}
2832
else {
33+
eprintln!("Loading worked HERE");
2934
Some(Self(handle))
3035
}
3136
}

gccjit_sys/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,19 @@ macro_rules! extern_maybe_dlopen {
339339

340340
#[cfg(feature="dlopen")]
341341
pub unsafe fn open(path: &CStr) -> Option<Self> {
342-
let lib = unsafe { dynload::Library::open(path)? };
342+
let lib = unsafe { dynload::Library::open(path) };
343+
eprintln!("Opening lib: {}", lib.is_some());
344+
let lib = lib?;
343345

344346
Some(Self {
345347
$(
346348
$(#[cfg($attr_name=$attr_value)])?
347349
$func_name: unsafe { std::mem::transmute::<*mut (), unsafe extern "C" fn($($arg_type),*) $(-> $return_type)?>(
348-
lib.get(CStr::from_bytes_with_nul_unchecked(concat!(stringify!($func_name), "\0").as_bytes())
349-
)?) },
350+
{
351+
eprintln!("Attempting to load symbol: {}", stringify!($func_name));
352+
lib.get(CStr::from_bytes_with_nul_unchecked(concat!(stringify!($func_name), "\0").as_bytes()))?
353+
}
354+
) },
350355
)*
351356
_lib: lib,
352357
})

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ fn with_lib<T, F: Fn(&Libgccjit) -> T>(callback: F) -> T {
125125
pub fn load(path: &CStr) -> bool {
126126
let lib =
127127
LIB.get_or_init(|| {
128-
unsafe { Libgccjit::open(path) }
128+
let lib = unsafe { Libgccjit::open(path) };
129+
eprintln!("Is some: {}", lib.is_some());
130+
lib
129131
});
130132
lib.is_some()
131133
}

0 commit comments

Comments
 (0)