Skip to content

Commit 04e4c00

Browse files
committed
Fix C callable getter signatures
1 parent 4eb70ec commit 04e4c00

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/ark/src/debug.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub extern "C" fn ark_trace_back_rs() -> *const ffi::c_char {
7373
// https://github.com/r-lib/rlang/issues/1059
7474
unsafe {
7575
let fun =
76-
libr::R_GetCCallable(c"rlang".as_ptr(), c"rlang_print_backtrace".as_ptr()).unwrap();
76+
get_c_callable_int(c"rlang".as_ptr(), c"rlang_print_backtrace".as_ptr()).unwrap();
7777
fun(1);
7878
};
7979
})
@@ -184,3 +184,16 @@ pub fn capture_console_output(cb: impl FnOnce()) -> *const ffi::c_char {
184184
// Intentionally leaks, should only be used in the debugger
185185
ffi::CString::new(out).unwrap().into_raw()
186186
}
187+
188+
// Cast `DL_FUNC` to correct function type
189+
fn get_c_callable_int(
190+
pkg: *const std::ffi::c_char,
191+
fun: *const std::ffi::c_char,
192+
) -> Option<unsafe extern "C-unwind" fn(std::ffi::c_int) -> *mut std::ffi::c_void> {
193+
unsafe {
194+
std::mem::transmute::<
195+
Option<unsafe extern "C-unwind" fn() -> *mut std::ffi::c_void>,
196+
Option<unsafe extern "C-unwind" fn(std::ffi::c_int) -> *mut std::ffi::c_void>,
197+
>(libr::R_GetCCallable(pkg, fun))
198+
}
199+
}

crates/libr/src/r.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ functions::generate! {
4242
) -> std::ffi::c_int;
4343

4444
pub fn R_GetCCallable(pkg: *const std::ffi::c_char, fun: *const std::ffi::c_char) ->
45-
Option<unsafe extern "C-unwind" fn(std::ffi::c_int) -> *mut std::ffi::c_void>;
45+
DL_FUNC;
4646

4747
pub fn vmaxget() -> *mut std::ffi::c_void;
4848

0 commit comments

Comments
 (0)