Skip to content

Commit

Permalink
gtk4: fix userdata mutability for FnMut callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
fengalin committed Nov 7, 2024
1 parent d895644 commit 3973c0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions gsk4/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Path {
flags: PathForeachFlags,
func: P,
) -> glib::ControlFlow {
let func_data: P = func;
let mut func_data: P = func;
unsafe extern "C" fn func_func<
P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow,
>(
Expand All @@ -23,17 +23,17 @@ impl Path {
) -> glib::ffi::gboolean {
let op = from_glib(op);
let pts = from_glib_borrow(pts);
let callback: *mut P = user_data as *const _ as usize as *mut P;
let callback = user_data as *mut P;
(*callback)(&op, &pts, n_pts, weight).into_glib()
}
let func = Some(func_func::<P> as _);
let super_callback0: &P = &func_data;
let super_callback0: &mut P = &mut func_data;
unsafe {
from_glib(ffi::gsk_path_foreach(
self.to_glib_none().0,
flags.into_glib(),
func,
super_callback0 as *const _ as usize as *mut _,
super_callback0 as *mut _ as *mut _,
))
}
}
Expand Down
8 changes: 4 additions & 4 deletions gsk4/src/render_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl RenderNode {
error_func: P,
) -> Option<Self> {
assert_initialized_main_thread!();
let error_func_data: P = error_func;
let mut error_func_data: P = error_func;
unsafe extern "C" fn error_func_func<
P: FnMut(&ParseLocation, &ParseLocation, &glib::Error),
>(
Expand All @@ -48,16 +48,16 @@ impl RenderNode {
let start = from_glib_borrow(start);
let end = from_glib_borrow(end);
let error = from_glib_borrow(error);
let callback: *mut P = user_data as *const _ as usize as *mut P;
let callback = user_data as *mut P;
(*callback)(&start, &end, &error);
}
let error_func = Some(error_func_func::<P> as _);
let super_callback0: &P = &error_func_data;
let super_callback0: &mut P = &mut error_func_data;
unsafe {
from_glib_full(ffi::gsk_render_node_deserialize(
bytes.to_glib_none().0,
error_func,
super_callback0 as *const _ as usize as *mut _,
super_callback0 as *mut _ as *mut _,
))
}
}
Expand Down

0 comments on commit 3973c0a

Please sign in to comment.