Get rid of double-boxing for some other closures

This commit is contained in:
Sebastian Dröge 2019-01-30 15:02:03 +02:00 committed by Sebastian Dröge
parent 1adb063fbc
commit 42a8b9e505
9 changed files with 308 additions and 298 deletions

View file

@ -9,25 +9,26 @@ use std::cell::RefCell;
use std::mem::transmute;
use RTSPSessionPool;
unsafe extern "C" fn trampoline_watch(
unsafe extern "C" fn trampoline_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(
pool: *mut ffi::GstRTSPSessionPool,
func: gpointer,
) -> gboolean {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>> = transmute(func);
let func: &RefCell<F> = transmute(func);
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
}
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
Box::<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _,
);
unsafe extern "C" fn destroy_closure_watch<
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static,
>(
ptr: gpointer,
) {
Box::<RefCell<F>>::from_raw(ptr as *mut _);
}
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(func: F) -> gpointer {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func: Box<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>> =
Box::new(RefCell::new(Box::new(func)));
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
Box::into_raw(func) as gpointer
}
@ -55,12 +56,11 @@ impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {
skip_assert_initialized!();
unsafe {
let source = ffi::gst_rtsp_session_pool_create_watch(self.as_ref().to_glib_none().0);
let trampoline = trampoline_watch as gpointer;
glib_ffi::g_source_set_callback(
source,
Some(transmute(trampoline)),
Some(transmute(trampoline_watch::<F> as usize)),
into_raw_watch(func),
Some(destroy_closure_watch),
Some(destroy_closure_watch::<F>),
);
glib_ffi::g_source_set_priority(source, priority.to_glib());

View file

@ -55,7 +55,7 @@ pub fn convert_sample_async<F>(
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let callback: &mut Option<Box<F>> = mem::transmute(user_data);
let callback: &mut Option<F> = mem::transmute(user_data);
let callback = callback.take().unwrap();
if error.is_null() {
@ -68,11 +68,11 @@ pub fn convert_sample_async<F>(
where
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
{
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
}
unsafe {
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
let user_data: Box<Option<F>> = Box::new(Some(func));
ffi::gst_video_convert_sample_async(
sample.to_glib_none().0,

View file

@ -20,36 +20,39 @@ use Bus;
use BusSyncReply;
use Message;
unsafe extern "C" fn trampoline_watch(
unsafe extern "C" fn trampoline_watch<F: FnMut(&Bus, &Message) -> Continue + Send + 'static>(
bus: *mut ffi::GstBus,
msg: *mut ffi::GstMessage,
func: gpointer,
) -> gboolean {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>> = transmute(func);
let func: &RefCell<F> = transmute(func);
(&mut *func.borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib()
}
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
Box::<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _,
);
unsafe extern "C" fn destroy_closure_watch<
F: FnMut(&Bus, &Message) -> Continue + Send + 'static,
>(
ptr: gpointer,
) {
Box::<RefCell<F>>::from_raw(ptr as *mut _);
}
fn into_raw_watch<F: FnMut(&Bus, &Message) -> Continue + Send + 'static>(func: F) -> gpointer {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func: Box<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>> =
Box::new(RefCell::new(Box::new(func)));
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
Box::into_raw(func) as gpointer
}
unsafe extern "C" fn trampoline_sync(
unsafe extern "C" fn trampoline_sync<
F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static,
>(
bus: *mut ffi::GstBus,
msg: *mut ffi::GstMessage,
func: gpointer,
) -> ffi::GstBusSyncReply {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static) = transmute(func);
let f: &F = transmute(func);
let res = f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib();
if res == ffi::GST_BUS_DROP {
@ -59,15 +62,18 @@ unsafe extern "C" fn trampoline_sync(
res
}
unsafe extern "C" fn destroy_closure_sync(ptr: gpointer) {
Box::<Box<Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>>::from_raw(ptr as *mut _);
unsafe extern "C" fn destroy_closure_sync<
F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static,
>(
ptr: gpointer,
) {
Box::<F>::from_raw(ptr as *mut _);
}
fn into_raw_sync<F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>(
func: F,
) -> gpointer {
let func: Box<Box<Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>> =
Box::new(Box::new(func));
let func: Box<F> = Box::new(func);
Box::into_raw(func) as gpointer
}
@ -90,12 +96,11 @@ impl Bus {
skip_assert_initialized!();
unsafe {
let source = ffi::gst_bus_create_watch(self.to_glib_none().0);
let trampoline = trampoline_watch as gpointer;
glib_ffi::g_source_set_callback(
source,
Some(transmute(trampoline)),
Some(transmute(trampoline_watch::<F> as usize)),
into_raw_watch(func),
Some(destroy_closure_watch),
Some(destroy_closure_watch::<F>),
);
glib_ffi::g_source_set_priority(source, priority.to_glib());
@ -116,9 +121,9 @@ impl Bus {
from_glib(ffi::gst_bus_add_watch_full(
self.to_glib_none().0,
glib_ffi::G_PRIORITY_DEFAULT,
Some(trampoline_watch),
Some(trampoline_watch::<F>),
into_raw_watch(func),
Some(destroy_closure_watch),
Some(destroy_closure_watch::<F>),
))
}
}
@ -130,9 +135,9 @@ impl Bus {
unsafe {
ffi::gst_bus_set_sync_handler(
self.to_glib_none().0,
Some(trampoline_sync),
Some(trampoline_sync::<F>),
into_raw_sync(func),
Some(destroy_closure_sync),
Some(destroy_closure_sync::<F>),
)
}
}

View file

@ -33,14 +33,14 @@ glib_wrapper! {
}
}
unsafe extern "C" fn trampoline_wait_async(
unsafe extern "C" fn trampoline_wait_async<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(
clock: *mut ffi::GstClock,
time: ffi::GstClockTime,
id: gpointer,
func: gpointer,
) -> gboolean {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Clock, ClockTime, &ClockId) + Send + 'static) = transmute(func);
let f: &F = transmute(func);
f(
&from_glib_borrow(clock),
from_glib(time),
@ -49,13 +49,17 @@ unsafe extern "C" fn trampoline_wait_async(
glib_ffi::GTRUE
}
unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) {
Box::<Box<Fn(&Clock, ClockTime, &ClockId) + Send + 'static>>::from_raw(ptr as *mut _);
unsafe extern "C" fn destroy_closure_wait_async<
F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static,
>(
ptr: gpointer,
) {
Box::<F>::from_raw(ptr as *mut _);
}
fn into_raw_wait_async<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(func: F) -> gpointer {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func: Box<Box<Fn(&Clock, ClockTime, &ClockId) + Send + 'static>> = Box::new(Box::new(func));
let func: Box<F> = Box::new(func);
Box::into_raw(func) as gpointer
}
@ -84,9 +88,9 @@ impl ClockId {
let ret: ClockReturn = unsafe {
from_glib(ffi::gst_clock_id_wait_async(
self.to_glib_none().0,
Some(trampoline_wait_async),
Some(trampoline_wait_async::<F>),
into_raw_wait_async(func),
Some(destroy_closure_wait_async),
Some(destroy_closure_wait_async::<F>),
))
};
ret.into_result()

View file

@ -652,13 +652,13 @@ impl<O: IsA<Element>> ElementExtManual for O {
where
F: FnOnce(&Self) + Send + 'static,
{
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
let user_data: Box<Option<F>> = Box::new(Some(func));
unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
element: *mut ffi::GstElement,
user_data: glib_ffi::gpointer,
) {
let user_data: &mut Option<Box<F>> = &mut *(user_data as *mut _);
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap();
callback(&Element::from_glib_borrow(element).unsafe_cast());
@ -667,17 +667,15 @@ impl<O: IsA<Element>> ElementExtManual for O {
unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
user_data: glib_ffi::gpointer,
) {
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
}
let trampoline = trampoline::<Self, F>;
let free_user_data = free_user_data::<Self, F>;
unsafe {
ffi::gst_element_call_async(
self.as_ref().to_glib_none().0,
Some(trampoline),
Some(trampoline::<Self, F>),
Box::into_raw(user_data) as *mut _,
Some(free_user_data),
Some(free_user_data::<Self, F>),
);
}
}

View file

@ -90,12 +90,7 @@ where
mem::forget(self);
let func_box: Box<Fn(T) -> bool + Send + Sync + 'static> = Box::new(func);
// FIXME: Use Value::from_type once we depend on new enough GLib
let mut closure_value = glib::Value::uninitialized();
gobject_ffi::g_value_init(
closure_value.to_glib_none_mut().0,
filter_boxed_get_type::<T>(),
);
let mut closure_value = glib::Value::from_type(from_glib(filter_boxed_get_type::<T>()));
gobject_ffi::g_value_set_boxed(
closure_value.to_glib_none_mut().0,
Arc::into_raw(Arc::new(func_box)) as gpointer,
@ -117,12 +112,11 @@ where
let mut elem = glib::Value::uninitialized();
let mut func = func;
let func_obj: &mut (FnMut(T) -> bool) = &mut func;
let func_ptr = &func_obj as *const &mut (FnMut(T) -> bool) as gpointer;
let func_ptr = &mut func as *mut F as gpointer;
let res = from_glib(ffi::gst_iterator_find_custom(
self.to_glib_none_mut().0,
Some(find_trampoline::<T>),
Some(find_trampoline::<T, F>),
elem.to_glib_none_mut().0,
func_ptr,
));
@ -140,12 +134,11 @@ where
{
unsafe {
let mut func = func;
let func_obj: &mut (FnMut(T)) = &mut func;
let func_ptr = &func_obj as *const &mut (FnMut(T)) as gpointer;
let func_ptr = &mut func as *mut F as gpointer;
let res = ffi::gst_iterator_foreach(
self.to_glib_none_mut().0,
Some(foreach_trampoline::<T>),
Some(foreach_trampoline::<T, F>),
func_ptr,
);
@ -163,13 +156,10 @@ where
{
unsafe {
let mut func = func;
let func_obj: &mut (FnMut(U, T) -> Result<U, U>) = &mut func;
let func_ptr = &func_obj as *const &mut (FnMut(U, T) -> Result<U, U>) as gpointer;
let func_ptr = &mut func as *mut F as gpointer;
let mut accum = Some(init);
// FIXME: Use Value::from_type once we depend on new enough GLib
let mut ret = glib::Value::uninitialized();
gobject_ffi::g_value_init(ret.to_glib_none_mut().0, gobject_ffi::G_TYPE_POINTER);
let mut ret = glib::Value::from_type(glib::Type::Pointer);
gobject_ffi::g_value_set_pointer(
ret.to_glib_none_mut().0,
&mut accum as *mut _ as gpointer,
@ -177,7 +167,7 @@ where
let res = ffi::gst_iterator_fold(
self.to_glib_none_mut().0,
Some(fold_trampoline::<T, U>),
Some(fold_trampoline::<T, U, F>),
ret.to_glib_none_mut().0,
func_ptr,
);
@ -405,13 +395,16 @@ unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_ff
TYPE
}
unsafe extern "C" fn find_trampoline<T>(value: gconstpointer, func: gconstpointer) -> i32
unsafe extern "C" fn find_trampoline<T, F: FnMut(T) -> bool>(
value: gconstpointer,
func: gconstpointer,
) -> i32
where
for<'a> T: FromValueOptional<'a> + 'static,
{
let value = value as *const gobject_ffi::GValue;
let func = func as *mut &mut (FnMut(T) -> bool);
let func = func as *mut F;
let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap();
@ -422,18 +415,20 @@ where
}
}
unsafe extern "C" fn foreach_trampoline<T>(value: *const gobject_ffi::GValue, func: gpointer)
where
unsafe extern "C" fn foreach_trampoline<T, F: FnMut(T)>(
value: *const gobject_ffi::GValue,
func: gpointer,
) where
for<'a> T: FromValueOptional<'a> + 'static,
{
let func = func as *mut &mut (FnMut(T));
let func = func as *mut F;
let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap();
(*func)(value);
}
unsafe extern "C" fn fold_trampoline<T, U>(
unsafe extern "C" fn fold_trampoline<T, U, F: FnMut(U, T) -> Result<U, U>>(
value: *const gobject_ffi::GValue,
ret: *mut gobject_ffi::GValue,
func: gpointer,
@ -441,7 +436,7 @@ unsafe extern "C" fn fold_trampoline<T, U>(
where
for<'a> T: FromValueOptional<'a> + 'static,
{
let func = func as *mut &mut (FnMut(U, T) -> Result<U, U>);
let func = func as *mut F;
let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap();

View file

@ -35,10 +35,10 @@ use std::mem::transmute;
use std::ptr;
use glib;
use glib::object::IsA;
use glib::object::{Cast, IsA};
use glib::translate::{
from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override, FromGlib, ToGlib,
ToGlibPtr,
from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override, FromGlib,
FromGlibPtrBorrow, ToGlib, ToGlibPtr,
};
use glib::StaticType;
use glib_ffi;
@ -116,7 +116,7 @@ impl Drop for StreamLock {
pub trait PadExtManual: 'static {
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
where
F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static;
F: Fn(&Self, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static;
fn remove_probe(&self, id: PadProbeId);
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
@ -165,65 +165,65 @@ pub trait PadExtManual: 'static {
fn set_activate_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
F: Fn(&Self, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
fn set_activatemode_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
F: Fn(&Self, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static;
fn set_chain_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_chain_list_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_event_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static;
F: Fn(&Self, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static;
fn set_event_full_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_getrange_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
F: Fn(&Self, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
+ Send
+ Sync
+ 'static;
fn set_iterate_internal_links_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static;
F: Fn(&Self, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static;
fn set_link_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
F: Fn(&Self, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static;
fn set_query_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static;
F: Fn(&Self, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static;
fn set_unlink_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>) + Send + Sync + 'static;
F: Fn(&Self, &Option<::Object>) + Send + Sync + 'static;
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
@ -272,18 +272,16 @@ pub trait PadExtManual: 'static {
impl<O: IsA<Pad>> PadExtManual for O {
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
where
F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
F: Fn(&Self, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
let id = ffi::gst_pad_add_probe(
self.as_ref().to_glib_none().0,
mask.to_glib(),
Some(trampoline_pad_probe),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_pad_probe::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
if id == 0 {
@ -517,224 +515,185 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_activate_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
F: Fn(&Self, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
{
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_activate_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_activate_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_activate_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_activatemode_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
F: Fn(&Self, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static,
{
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_activatemode_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_activatemode_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_activatemode_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_chain_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_chain_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_chain_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_chain_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_chain_list_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_chain_list_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_chain_list_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_chain_list_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_event_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
F: Fn(&Self, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_event_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_event_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_event_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_event_full_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
F: Fn(&Self, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_event_full_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_event_full_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_event_full_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_getrange_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
F: Fn(&Self, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send
+ Sync
+ 'static,
{
unsafe {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func_box: Box<
Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_getrange_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_getrange_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_getrange_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_iterate_internal_links_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
F: Fn(&Self, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_iterate_internal_links_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_iterate_internal_links_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_iterate_internal_links_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_link_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
F: Fn(&Self, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_link_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_link_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_link_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_query_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
F: Fn(&Self, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_query_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_query_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_query_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
fn set_unlink_function<F>(&self, func: F)
where
F: Fn(&Pad, &Option<::Object>) + Send + Sync + 'static,
F: Fn(&Self, &Option<::Object>) + Send + Sync + 'static,
{
unsafe {
let func_box: Box<Fn(&Pad, &Option<::Object>) + Send + Sync + 'static> = Box::new(func);
let func_box: Box<F> = Box::new(func);
ffi::gst_pad_set_unlink_function_full(
self.as_ref().to_glib_none().0,
Some(trampoline_unlink_function),
Box::into_raw(Box::new(func_box)) as gpointer,
Some(destroy_closure),
Some(trampoline_unlink_function::<Self, F>),
Box::into_raw(func_box) as gpointer,
Some(destroy_closure::<F>),
);
}
}
@ -744,9 +703,9 @@ impl<O: IsA<Pad>> PadExtManual for O {
glib_result_from_gboolean!(
ffi::gst_pad_start_task(
self.as_ref().to_glib_none().0,
Some(trampoline_pad_task),
Some(trampoline_pad_task::<F>),
into_raw_pad_task(func),
Some(destroy_closure_pad_task),
Some(destroy_closure::<F>),
),
"Failed to start pad task",
)
@ -1039,14 +998,19 @@ impl<O: IsA<Pad>> PadExtManual for O {
}
}
unsafe extern "C" fn trampoline_pad_probe(
unsafe extern "C" fn trampoline_pad_probe<
T,
F: Fn(&T, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
info: *mut ffi::GstPadProbeInfo,
func: gpointer,
) -> ffi::GstPadProbeReturn {
) -> ffi::GstPadProbeReturn
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static) =
transmute(func);
let func: &F = transmute(func);
let mut data_type = None;
let mut probe_info = PadProbeInfo {
@ -1085,7 +1049,7 @@ unsafe extern "C" fn trampoline_pad_probe(
},
};
let ret = func(&from_glib_borrow(pad), &mut probe_info).to_glib();
let ret = func(&Pad::from_glib_borrow(pad).unsafe_cast(), &mut probe_info).to_glib();
match probe_info.data {
Some(PadProbeData::Buffer(buffer)) => {
@ -1115,68 +1079,78 @@ unsafe extern "C" fn trampoline_pad_probe(
ret
}
unsafe extern "C" fn trampoline_activate_function(
unsafe extern "C" fn trampoline_activate_function<
T,
F: Fn(&T, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
) -> glib_ffi::gboolean {
) -> glib_ffi::gboolean
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static) = transmute((*pad).activatedata);
let func: &F = transmute((*pad).activatedata);
let pad: Pad = from_glib_borrow(pad);
match func(&pad, &from_glib_borrow(parent)) {
match func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&pad);
err.log_with_object(&Pad::from_glib_borrow(pad));
false
}
}
.to_glib()
}
unsafe extern "C" fn trampoline_activatemode_function(
unsafe extern "C" fn trampoline_activatemode_function<
T,
F: Fn(&T, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError> + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
mode: ffi::GstPadMode,
active: glib_ffi::gboolean,
) -> glib_ffi::gboolean {
) -> glib_ffi::gboolean
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static) = transmute((*pad).activatemodedata);
let func: &F = transmute((*pad).activatemodedata);
let pad: Pad = from_glib_borrow(pad);
match func(
&pad,
&&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
from_glib(mode),
from_glib(active),
) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&pad);
err.log_with_object(&Pad::from_glib_borrow(pad));
false
}
}
.to_glib()
}
unsafe extern "C" fn trampoline_chain_function(
unsafe extern "C" fn trampoline_chain_function<
T,
F: Fn(&T, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
buffer: *mut ffi::GstBuffer,
) -> ffi::GstFlowReturn {
) -> ffi::GstFlowReturn
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static) = transmute((*pad).chaindata);
let func: &F = transmute((*pad).chaindata);
let res: FlowReturn = func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
from_glib_full(buffer),
)
@ -1184,19 +1158,25 @@ unsafe extern "C" fn trampoline_chain_function(
res.to_glib()
}
unsafe extern "C" fn trampoline_chain_list_function(
unsafe extern "C" fn trampoline_chain_list_function<
T,
F: Fn(&T, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
list: *mut ffi::GstBufferList,
) -> ffi::GstFlowReturn {
) -> ffi::GstFlowReturn
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static) = transmute((*pad).chainlistdata);
let func: &F = transmute((*pad).chainlistdata);
let res: FlowReturn = func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
from_glib_full(list),
)
@ -1204,36 +1184,44 @@ unsafe extern "C" fn trampoline_chain_list_function(
res.to_glib()
}
unsafe extern "C" fn trampoline_event_function(
unsafe extern "C" fn trampoline_event_function<
T,
F: Fn(&T, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
event: *mut ffi::GstEvent,
) -> glib_ffi::gboolean {
) -> glib_ffi::gboolean
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static) =
transmute((*pad).eventdata);
let func: &F = transmute((*pad).eventdata);
func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
from_glib_full(event),
)
.to_glib()
}
unsafe extern "C" fn trampoline_event_full_function(
unsafe extern "C" fn trampoline_event_full_function<
T,
F: Fn(&T, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError> + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
event: *mut ffi::GstEvent,
) -> ffi::GstFlowReturn {
) -> ffi::GstFlowReturn
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static) = transmute((*pad).eventdata);
let func: &F = transmute((*pad).eventdata);
let res: FlowReturn = func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
from_glib_full(event),
)
@ -1241,21 +1229,24 @@ unsafe extern "C" fn trampoline_event_full_function(
res.to_glib()
}
unsafe extern "C" fn trampoline_getrange_function(
unsafe extern "C" fn trampoline_getrange_function<
T,
F: Fn(&T, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
offset: u64,
length: u32,
buffer: *mut *mut ffi::GstBuffer,
) -> ffi::GstFlowReturn {
) -> ffi::GstFlowReturn
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send
+ Sync
+ 'static) = transmute((*pad).getrangedata);
let func: &F = transmute((*pad).getrangedata);
match func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
offset,
length,
@ -1268,39 +1259,49 @@ unsafe extern "C" fn trampoline_getrange_function(
}
}
unsafe extern "C" fn trampoline_iterate_internal_links_function(
unsafe extern "C" fn trampoline_iterate_internal_links_function<
T,
F: Fn(&T, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
) -> *mut ffi::GstIterator {
) -> *mut ffi::GstIterator
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static) =
transmute((*pad).iterintlinkdata);
let func: &F = transmute((*pad).iterintlinkdata);
// Steal the iterator and return it
let ret = func(&from_glib_borrow(pad), &from_glib_borrow(parent));
let ret = func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
);
let ptr = ret.to_glib_none().0;
mem::forget(ret);
ptr as *mut _
}
unsafe extern "C" fn trampoline_link_function(
unsafe extern "C" fn trampoline_link_function<
T,
F: Fn(&T, &Option<::Object>, &::Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
peer: *mut ffi::GstPad,
) -> ffi::GstPadLinkReturn {
) -> ffi::GstPadLinkReturn
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(
&Pad,
&Option<::Object>,
&::Pad,
) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static) = transmute((*pad).linkdata);
let func: &F = transmute((*pad).linkdata);
let res: ::PadLinkReturn = func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
&from_glib_borrow(peer),
)
@ -1308,51 +1309,59 @@ unsafe extern "C" fn trampoline_link_function(
res.to_glib()
}
unsafe extern "C" fn trampoline_query_function(
unsafe extern "C" fn trampoline_query_function<
T,
F: Fn(&T, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
query: *mut ffi::GstQuery,
) -> glib_ffi::gboolean {
) -> glib_ffi::gboolean
where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static) =
transmute((*pad).querydata);
let func: &F = transmute((*pad).querydata);
func(
&from_glib_borrow(pad),
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
::QueryRef::from_mut_ptr(query),
)
.to_glib()
}
unsafe extern "C" fn trampoline_unlink_function(
unsafe extern "C" fn trampoline_unlink_function<
T,
F: Fn(&T, &Option<::Object>) + Send + Sync + 'static,
>(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
) {
) where
T: IsA<Pad>,
{
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) + Send + Sync + 'static) =
transmute((*pad).unlinkdata);
let func: &F = transmute((*pad).unlinkdata);
func(&from_glib_borrow(pad), &from_glib_borrow(parent))
func(
&Pad::from_glib_borrow(pad).unsafe_cast(),
&from_glib_borrow(parent),
)
}
unsafe extern "C" fn destroy_closure(ptr: gpointer) {
Box::<Box<Fn()>>::from_raw(ptr as *mut _);
unsafe extern "C" fn destroy_closure<F>(ptr: gpointer) {
Box::<F>::from_raw(ptr as *mut _);
}
unsafe extern "C" fn trampoline_pad_task(func: gpointer) {
unsafe extern "C" fn trampoline_pad_task<F: FnMut() + Send + 'static>(func: gpointer) {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut() + Send + 'static>> = transmute(func);
let func: &RefCell<F> = transmute(func);
(&mut *func.borrow_mut())()
}
unsafe extern "C" fn destroy_closure_pad_task(ptr: gpointer) {
Box::<RefCell<Box<FnMut() + Send + 'static>>>::from_raw(ptr as *mut _);
}
fn into_raw_pad_task<F: FnMut() + Send + 'static>(func: F) -> gpointer {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func: Box<RefCell<Box<FnMut() + Send + 'static>>> = Box::new(RefCell::new(Box::new(func)));
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
Box::into_raw(func) as gpointer
}

View file

@ -36,13 +36,13 @@ impl Promise {
where
F: FnOnce(&Promise) + Send + 'static,
{
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
let user_data: Box<Option<F>> = Box::new(Some(func));
unsafe extern "C" fn trampoline<F: FnOnce(&Promise) + Send + 'static>(
promise: *mut ffi::GstPromise,
user_data: glib_ffi::gpointer,
) {
let user_data: &mut Option<Box<F>> = &mut *(user_data as *mut _);
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap();
callback(&from_glib_borrow(promise));
@ -51,16 +51,14 @@ impl Promise {
unsafe extern "C" fn free_user_data<F: FnOnce(&Promise) + Send + 'static>(
user_data: glib_ffi::gpointer,
) {
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
}
let trampoline = trampoline::<F>;
let free_user_data = free_user_data::<F>;
unsafe {
from_glib_full(ffi::gst_promise_new_with_change_func(
Some(trampoline),
Some(trampoline::<F>),
Box::into_raw(user_data) as *mut _,
Some(free_user_data),
Some(free_user_data::<F>),
))
}
}

View file

@ -56,19 +56,18 @@ impl<'a> TypeFind<'a> {
let extensions = extensions.into();
let possible_caps = possible_caps.into();
unsafe {
let func: Box<Box<Fn(&mut TypeFind) + Send + Sync + 'static>> =
Box::new(Box::new(func));
let func: Box<F> = Box::new(func);
let func = Box::into_raw(func);
let res = ffi::gst_type_find_register(
plugin.to_glib_none().0,
name.to_glib_none().0,
rank,
Some(type_find_trampoline),
Some(type_find_trampoline::<F>),
extensions.to_glib_none().0,
possible_caps.to_glib_none().0,
func as *mut _,
Some(type_find_closure_drop),
Some(type_find_closure_drop::<F>),
);
glib_result_from_gboolean!(res, "Failed to register typefind factory")
@ -116,17 +115,19 @@ impl TypeFindFactory {
}
}
unsafe extern "C" fn type_find_trampoline(
unsafe extern "C" fn type_find_trampoline<F: Fn(&mut TypeFind) + Send + Sync + 'static>(
find: *mut ffi::GstTypeFind,
user_data: glib_ffi::gpointer,
) {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&mut TypeFind) + Send + Sync + 'static) = mem::transmute(user_data);
let func: &F = mem::transmute(user_data);
func(&mut *(find as *mut TypeFind));
}
unsafe extern "C" fn type_find_closure_drop(data: glib_ffi::gpointer) {
Box::<Box<Fn(&mut TypeFind) + Send + Sync + 'static>>::from_raw(data as *mut _);
unsafe extern "C" fn type_find_closure_drop<F: Fn(&mut TypeFind) + Send + Sync + 'static>(
data: glib_ffi::gpointer,
) {
Box::<F>::from_raw(data as *mut _);
}
unsafe extern "C" fn type_find_peek(data: glib_ffi::gpointer, offset: i64, size: u32) -> *const u8 {