ffi: Use a generic wrapper for opaque Rust structs

This commit is contained in:
Dorota Czaplejewicz
2019-08-28 20:16:28 +00:00
parent e6f3b9e5be
commit 878b7ed18e
3 changed files with 91 additions and 75 deletions

View File

@ -315,9 +315,8 @@ pub mod c {
state: ::keyboard::c::CKeyState,
) -> u32 {
let button = unsafe { &*button };
let state = state.unwrap();
let state = state.clone_ref();
let equal = Rc::ptr_eq(&button.state, &state);
Rc::into_raw(state); // Prevent dropping
equal as u32
}
@ -418,13 +417,10 @@ pub mod c {
needle: ::keyboard::c::CKeyState,
) -> ButtonPlace {
let view = unsafe { &*view };
let state = needle.unwrap();
let state = needle.clone_ref();
let paths = ::layout::procedures::find_key_paths(view, &state);
// Iterators used up, can turn the reference back into pointer
Rc::into_raw(state);
// Can only return 1 entry back to C
let (row, button) = match paths.get(0) {
Some((row, button)) => (