all: fix userdata mutability for FnMut callbacks

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1585>
This commit is contained in:
François Laignel 2024-11-06 19:26:41 +01:00
parent 2a1473d69d
commit 33781c5e65
5 changed files with 23 additions and 19 deletions

View file

@ -48,9 +48,9 @@ pub trait RTSPSessionPoolExtManual: IsA<RTSPSessionPool> + 'static {
glib::ffi::g_source_set_callback( glib::ffi::g_source_set_callback(
source, source,
Some(transmute::< Some(transmute::<
*const (), *mut (),
unsafe extern "C" fn(glib::ffi::gpointer) -> i32, unsafe extern "C" fn(glib::ffi::gpointer) -> i32,
>(trampoline_watch::<F> as *const ())), >(trampoline_watch::<F> as *mut ())),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );

View file

@ -599,12 +599,13 @@ impl BufferRef {
} }
unsafe { unsafe {
let func_ptr: &F = &func; let mut func = func;
let func_ptr: &mut F = &mut func;
from_glib(ffi::gst_buffer_foreach_meta( from_glib(ffi::gst_buffer_foreach_meta(
mut_override(self.as_ptr()), mut_override(self.as_ptr()),
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as *mut _, func_ptr as *mut _ as *mut _,
)) ))
} }
} }
@ -643,12 +644,13 @@ impl BufferRef {
} }
unsafe { unsafe {
let func_ptr: &F = &func; let mut func = func;
let func_ptr: &mut F = &mut func;
from_glib(ffi::gst_buffer_foreach_meta( from_glib(ffi::gst_buffer_foreach_meta(
mut_override(self.as_ptr()), mut_override(self.as_ptr()),
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as *mut _, func_ptr as *mut _ as *mut _,
)) ))
} }
} }

View file

@ -149,12 +149,13 @@ impl BufferListRef {
} }
unsafe { unsafe {
let func_ptr: &F = &func; let mut func = func;
let func_ptr: &mut F = &mut func;
from_glib(ffi::gst_buffer_list_foreach( from_glib(ffi::gst_buffer_list_foreach(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as *mut _, func_ptr as *mut _ as *mut _,
)) ))
} }
} }
@ -198,12 +199,13 @@ impl BufferListRef {
} }
unsafe { unsafe {
let func_ptr: &F = &func; let mut func = func;
let func_ptr: &mut F = &mut func;
from_glib(ffi::gst_buffer_list_foreach( from_glib(ffi::gst_buffer_list_foreach(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as *mut _, func_ptr as *mut _ as *mut _,
)) ))
} }
} }

View file

@ -120,9 +120,9 @@ impl Bus {
glib::ffi::g_source_set_callback( glib::ffi::g_source_set_callback(
source, source,
Some(transmute::< Some(transmute::<
*const (), *mut (),
unsafe extern "C" fn(glib::ffi::gpointer) -> i32, unsafe extern "C" fn(glib::ffi::gpointer) -> i32,
>(trampoline_watch::<F> as *const ())), >(trampoline_watch::<F> as *mut ())),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );

View file

@ -16,7 +16,7 @@ impl Registry {
filter: P, filter: P,
first: bool, first: bool,
) -> glib::List<PluginFeature> { ) -> glib::List<PluginFeature> {
let filter_data: P = filter; let mut filter_data: P = filter;
unsafe extern "C" fn filter_func<P: FnMut(&PluginFeature) -> bool>( unsafe extern "C" fn filter_func<P: FnMut(&PluginFeature) -> bool>(
feature: *mut ffi::GstPluginFeature, feature: *mut ffi::GstPluginFeature,
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
@ -27,13 +27,13 @@ impl Registry {
res.into_glib() res.into_glib()
} }
let filter = Some(filter_func::<P> as _); let filter = Some(filter_func::<P> as _);
let super_callback0: &P = &filter_data; let super_callback0: &mut P = &mut filter_data;
unsafe { unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter( FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter(
self.to_glib_none().0, self.to_glib_none().0,
filter, filter,
first.into_glib(), first.into_glib(),
super_callback0 as *const _ as *mut _, super_callback0 as *mut _ as *mut _,
)) ))
} }
} }
@ -76,24 +76,24 @@ impl Registry {
filter: P, filter: P,
first: bool, first: bool,
) -> glib::List<Plugin> { ) -> glib::List<Plugin> {
let filter_data: P = filter; let mut filter_data: P = filter;
unsafe extern "C" fn filter_func<P: FnMut(&Plugin) -> bool>( unsafe extern "C" fn filter_func<P: FnMut(&Plugin) -> bool>(
plugin: *mut ffi::GstPlugin, plugin: *mut ffi::GstPlugin,
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let plugin = from_glib_borrow(plugin); let plugin = from_glib_borrow(plugin);
let callback = user_data as *const _ as *mut P; let callback = user_data as *mut P;
let res = (*callback)(&plugin); let res = (*callback)(&plugin);
res.into_glib() res.into_glib()
} }
let filter = Some(filter_func::<P> as _); let filter = Some(filter_func::<P> as _);
let super_callback0: &P = &filter_data; let super_callback0: &mut P = &mut filter_data;
unsafe { unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter( FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter(
self.to_glib_none().0, self.to_glib_none().0,
filter, filter,
first.into_glib(), first.into_glib(),
super_callback0 as *const _ as *mut _, super_callback0 as *mut _ as *mut _,
)) ))
} }
} }