Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 58d2d1c

Browse files
committed
Merge pull request #116 from EPashkin/trampoline_cast
Don't use transmute on trampoline
2 parents 5e94494 + 52b1b6d commit 58d2d1c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/source.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ impl Drop for CallbackGuard {
4545
}
4646
}
4747

48-
extern "C" fn trampoline(func: &RefCell<Box<FnMut() -> Continue + 'static>>) -> gboolean {
48+
unsafe extern "C" fn trampoline(func: gpointer) -> gboolean {
4949
let _guard = CallbackGuard::new();
50+
let func: &RefCell<Box<FnMut() -> Continue + 'static>> = transmute(func);
5051
(&mut *func.borrow_mut())().to_glib()
5152
}
5253

@@ -70,7 +71,7 @@ fn into_raw<F: FnMut() -> Continue + Send + 'static>(func: F) -> gpointer {
7071
pub fn idle_add<F>(func: F) -> u32
7172
where F: FnMut() -> Continue + Send + 'static {
7273
unsafe {
73-
glib_ffi::g_idle_add_full(glib_ffi::G_PRIORITY_DEFAULT_IDLE, transmute(trampoline),
74+
glib_ffi::g_idle_add_full(glib_ffi::G_PRIORITY_DEFAULT_IDLE, Some(trampoline),
7475
into_raw(func), Some(destroy_closure))
7576
}
7677
}
@@ -88,7 +89,7 @@ where F: FnMut() -> Continue + Send + 'static {
8889
pub fn timeout_add<F>(interval: u32, func: F) -> u32
8990
where F: FnMut() -> Continue + Send + 'static {
9091
unsafe {
91-
glib_ffi::g_timeout_add_full(glib_ffi::G_PRIORITY_DEFAULT, interval, transmute(trampoline),
92+
glib_ffi::g_timeout_add_full(glib_ffi::G_PRIORITY_DEFAULT, interval, Some(trampoline),
9293
into_raw(func), Some(destroy_closure))
9394
}
9495
}
@@ -106,6 +107,6 @@ pub fn timeout_add_seconds<F>(interval: u32, func: F) -> u32
106107
where F: FnMut() -> Continue + Send + 'static {
107108
unsafe {
108109
glib_ffi::g_timeout_add_seconds_full(glib_ffi::G_PRIORITY_DEFAULT, interval,
109-
transmute(trampoline), into_raw(func), Some(destroy_closure))
110+
Some(trampoline), into_raw(func), Some(destroy_closure))
110111
}
111112
}

0 commit comments

Comments
 (0)