From bbdfc07dc027df53534ee55745c5f9ddb770294c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Wed, 6 Nov 2024 19:26:41 +0100 Subject: [PATCH] all: fix userdata mutability for FnMut callbacks Part-of: --- gstreamer-rtsp-server/src/rtsp_session_pool.rs | 4 ++-- gstreamer/src/buffer.rs | 10 ++++++---- gstreamer/src/bufferlist.rs | 10 ++++++---- gstreamer/src/bus.rs | 4 ++-- gstreamer/src/registry.rs | 14 +++++++------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/gstreamer-rtsp-server/src/rtsp_session_pool.rs b/gstreamer-rtsp-server/src/rtsp_session_pool.rs index b764ad08b..e6e09cd8a 100644 --- a/gstreamer-rtsp-server/src/rtsp_session_pool.rs +++ b/gstreamer-rtsp-server/src/rtsp_session_pool.rs @@ -53,9 +53,9 @@ pub trait RTSPSessionPoolExtManual: sealed::Sealed + IsA + 'sta glib::ffi::g_source_set_callback( source, Some(transmute::< - *const (), + *mut (), unsafe extern "C" fn(glib::ffi::gpointer) -> i32, - >(trampoline_watch:: as *const ())), + >(trampoline_watch:: as *mut ())), into_raw_watch(func), Some(destroy_closure_watch::), ); diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index 846c4eb50..b2ddbc4bc 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -599,12 +599,13 @@ impl BufferRef { } unsafe { - let func_ptr: &F = &func; + let mut func = func; + let func_ptr: &mut F = &mut func; from_glib(ffi::gst_buffer_foreach_meta( mut_override(self.as_ptr()), Some(trampoline::), - func_ptr as *const _ as *mut _, + func_ptr as *mut _ as *mut _, )) } } @@ -643,12 +644,13 @@ impl BufferRef { } unsafe { - let func_ptr: &F = &func; + let mut func = func; + let func_ptr: &mut F = &mut func; from_glib(ffi::gst_buffer_foreach_meta( mut_override(self.as_ptr()), Some(trampoline::), - func_ptr as *const _ as *mut _, + func_ptr as *mut _ as *mut _, )) } } diff --git a/gstreamer/src/bufferlist.rs b/gstreamer/src/bufferlist.rs index 9aa93fd35..e96e388a7 100644 --- a/gstreamer/src/bufferlist.rs +++ b/gstreamer/src/bufferlist.rs @@ -149,12 +149,13 @@ impl BufferListRef { } unsafe { - let func_ptr: &F = &func; + let mut func = func; + let func_ptr: &mut F = &mut func; from_glib(ffi::gst_buffer_list_foreach( self.as_ptr() as *mut _, Some(trampoline::), - func_ptr as *const _ as *mut _, + func_ptr as *mut _ as *mut _, )) } } @@ -198,12 +199,13 @@ impl BufferListRef { } unsafe { - let func_ptr: &F = &func; + let mut func = func; + let func_ptr: &mut F = &mut func; from_glib(ffi::gst_buffer_list_foreach( self.as_ptr() as *mut _, Some(trampoline::), - func_ptr as *const _ as *mut _, + func_ptr as *mut _ as *mut _, )) } } diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 7b1d94b02..c0eb90d8e 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -120,9 +120,9 @@ impl Bus { glib::ffi::g_source_set_callback( source, Some(transmute::< - *const (), + *mut (), unsafe extern "C" fn(glib::ffi::gpointer) -> i32, - >(trampoline_watch:: as *const ())), + >(trampoline_watch:: as *mut ())), into_raw_watch(func), Some(destroy_closure_watch::), ); diff --git a/gstreamer/src/registry.rs b/gstreamer/src/registry.rs index 826e8d4fa..148747444 100644 --- a/gstreamer/src/registry.rs +++ b/gstreamer/src/registry.rs @@ -16,7 +16,7 @@ impl Registry { filter: P, first: bool, ) -> glib::List { - let filter_data: P = filter; + let mut filter_data: P = filter; unsafe extern "C" fn filter_func bool>( feature: *mut ffi::GstPluginFeature, user_data: glib::ffi::gpointer, @@ -27,13 +27,13 @@ impl Registry { res.into_glib() } let filter = Some(filter_func::

as _); - let super_callback0: &P = &filter_data; + let super_callback0: &mut P = &mut filter_data; unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter( self.to_glib_none().0, filter, first.into_glib(), - super_callback0 as *const _ as *mut _, + super_callback0 as *mut _ as *mut _, )) } } @@ -76,24 +76,24 @@ impl Registry { filter: P, first: bool, ) -> glib::List { - let filter_data: P = filter; + let mut filter_data: P = filter; unsafe extern "C" fn filter_func bool>( plugin: *mut ffi::GstPlugin, user_data: glib::ffi::gpointer, ) -> glib::ffi::gboolean { 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); res.into_glib() } let filter = Some(filter_func::

as _); - let super_callback0: &P = &filter_data; + let super_callback0: &mut P = &mut filter_data; unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter( self.to_glib_none().0, filter, first.into_glib(), - super_callback0 as *const _ as *mut _, + super_callback0 as *mut _ as *mut _, )) } }