forked from mirrors/gstreamer-rs
Replace unneeded transmute calls with a safer alternative
This commit is contained in:
parent
d1665b8114
commit
76a0410d41
12 changed files with 16 additions and 30 deletions
|
@ -17,7 +17,6 @@ use gst_app_sys;
|
|||
use gst_sys;
|
||||
use std::boxed::Box as Box_;
|
||||
use std::cell::RefCell;
|
||||
use std::mem::transmute;
|
||||
use std::panic;
|
||||
use std::ptr;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
@ -295,7 +294,7 @@ impl AppSink {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"new-sample\0".as_ptr() as *const _,
|
||||
Some(transmute(new_sample_trampoline::<F> as usize)),
|
||||
Some(*(&new_sample_trampoline::<F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
@ -312,7 +311,7 @@ impl AppSink {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"new-preroll\0".as_ptr() as *const _,
|
||||
Some(transmute(new_preroll_trampoline::<F> as usize)),
|
||||
Some(*(&new_preroll_trampoline::<F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -24,10 +24,8 @@ impl AudioChannelPosition {
|
|||
if pos < 0 {
|
||||
return 0;
|
||||
}
|
||||
unsafe {
|
||||
let val = mem::transmute::<gst_audio_sys::GstAudioChannelPosition, u32>(pos);
|
||||
1 << val
|
||||
}
|
||||
|
||||
1 << (pos as u32)
|
||||
}
|
||||
|
||||
pub fn positions_to_mask(
|
||||
|
|
|
@ -100,9 +100,7 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"notify::min-upstream-latency\0".as_ptr() as *const _,
|
||||
Some(mem::transmute(
|
||||
notify_min_upstream_latency_trampoline::<Self, F> as usize,
|
||||
)),
|
||||
Some(*(¬ify_min_upstream_latency_trampoline::<Self, F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ use gobject_sys;
|
|||
use gst_pbutils_sys;
|
||||
|
||||
use std::boxed::Box as Box_;
|
||||
use std::mem::transmute;
|
||||
|
||||
impl Discoverer {
|
||||
pub fn set_property_timeout(&self, timeout: gst::ClockTime) {
|
||||
|
@ -60,7 +59,7 @@ impl Discoverer {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"notify::timeout\0".as_ptr() as *const _,
|
||||
Some(transmute(notify_timeout_trampoline::<Self, F> as usize)),
|
||||
Some(*(¬ify_timeout_trampoline::<Self, F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ use glib_sys;
|
|||
use gst;
|
||||
use gst_player_sys;
|
||||
use std::boxed::Box as Box_;
|
||||
use std::mem::transmute;
|
||||
use Player;
|
||||
use PlayerSignalDispatcher;
|
||||
use PlayerVideoRenderer;
|
||||
|
@ -72,7 +71,7 @@ impl Player {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"duration-changed\0".as_ptr() as *const _,
|
||||
Some(transmute(duration_changed_trampoline::<F> as usize)),
|
||||
Some(*(&duration_changed_trampoline::<F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ impl Player {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"position-updated\0".as_ptr() as *const _,
|
||||
Some(transmute(position_updated_trampoline::<F> as usize)),
|
||||
Some(*(&position_updated_trampoline::<F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
@ -104,7 +103,7 @@ impl Player {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"seek-done\0".as_ptr() as *const _,
|
||||
Some(transmute(seek_done_trampoline::<F> as usize)),
|
||||
Some(*(&seek_done_trampoline::<F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use glib::translate::*;
|
|||
use gst_rtsp_server_sys;
|
||||
|
||||
use std::boxed::Box as Box_;
|
||||
use std::mem::transmute;
|
||||
|
||||
use RTSPAuth;
|
||||
use RTSPToken;
|
||||
|
@ -59,7 +58,7 @@ impl<O: IsA<RTSPAuth>> RTSPAuthExtManual for O {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"accept-certificate\0".as_ptr() as *const _,
|
||||
Some(transmute(accept_certificate_trampoline::<Self, F> as usize)),
|
||||
Some(*(&accept_certificate_trampoline::<Self, F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use glib_sys;
|
|||
use glib_sys::{gboolean, gpointer};
|
||||
use gst_rtsp_server_sys;
|
||||
use std::cell::RefCell;
|
||||
use std::mem::transmute;
|
||||
use RTSPSessionPool;
|
||||
|
||||
unsafe extern "C" fn trampoline_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(
|
||||
|
@ -49,7 +48,7 @@ impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {
|
|||
);
|
||||
glib_sys::g_source_set_callback(
|
||||
source,
|
||||
Some(transmute(trampoline_watch::<F> as usize)),
|
||||
Some(*(&trampoline_watch::<F> as *const _ as *const _)),
|
||||
into_raw_watch(func),
|
||||
Some(destroy_closure_watch::<F>),
|
||||
);
|
||||
|
|
|
@ -273,7 +273,6 @@ where
|
|||
T: RTSPMediaFactoryImpl,
|
||||
{
|
||||
use once_cell::sync::Lazy;
|
||||
use std::mem;
|
||||
|
||||
static PIPELINE_QUARK: Lazy<glib::Quark> =
|
||||
Lazy::new(|| glib::Quark::from_string("gstreamer-rs-rtsp-media-pipeline"));
|
||||
|
@ -291,7 +290,7 @@ where
|
|||
media as *mut _,
|
||||
PIPELINE_QUARK.to_glib(),
|
||||
pipeline as *mut _,
|
||||
Some(mem::transmute(gobject_sys::g_object_unref as usize)),
|
||||
Some(*(&gobject_sys::g_object_unref as *const _ as *const _)),
|
||||
);
|
||||
|
||||
pipeline as *mut _
|
||||
|
|
|
@ -14,7 +14,6 @@ use glib;
|
|||
use glib::translate::{from_glib_full, ToGlib, ToGlibPtr};
|
||||
use gst;
|
||||
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
pub fn convert_sample(
|
||||
|
@ -106,7 +105,7 @@ unsafe fn convert_sample_async_unsafe<F>(
|
|||
timeout.to_glib(),
|
||||
Some(convert_sample_async_trampoline::<F>),
|
||||
Box::into_raw(user_data) as glib_sys::gpointer,
|
||||
Some(mem::transmute(convert_sample_async_free::<F> as usize)),
|
||||
Some(convert_sample_async_free::<F>),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ use glib::GString;
|
|||
use gst_sys;
|
||||
|
||||
use std::boxed::Box as Box_;
|
||||
use std::mem::transmute;
|
||||
use std::path;
|
||||
|
||||
pub trait GstBinExtManual: 'static {
|
||||
|
@ -99,7 +98,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
|||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"do-latency\0".as_ptr() as *const _,
|
||||
Some(transmute(do_latency_trampoline::<Self, F> as usize)),
|
||||
Some(*(&do_latency_trampoline::<Self, F> as *const _ as *const _)),
|
||||
Box_::into_raw(f),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ use glib_sys;
|
|||
use glib_sys::{gboolean, gpointer};
|
||||
use gst_sys;
|
||||
use std::cell::RefCell;
|
||||
use std::mem::transmute;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
|
@ -94,7 +93,7 @@ impl Bus {
|
|||
let source = gst_sys::gst_bus_create_watch(self.to_glib_none().0);
|
||||
glib_sys::g_source_set_callback(
|
||||
source,
|
||||
Some(transmute(trampoline_watch::<F> as usize)),
|
||||
Some(*(&trampoline_watch::<F> as *const _ as *const _)),
|
||||
into_raw_watch(func),
|
||||
Some(destroy_closure_watch::<F>),
|
||||
);
|
||||
|
|
|
@ -328,8 +328,7 @@ where
|
|||
|
||||
let func = func as *const gobject_sys::GValue;
|
||||
let func = gobject_sys::g_value_get_boxed(func);
|
||||
#[allow(clippy::transmute_ptr_to_ref)]
|
||||
let func: &&(dyn Fn(T) -> bool + Send + Sync + 'static) = mem::transmute(func);
|
||||
let func = &*(func as *const &(dyn Fn(T) -> bool + Send + Sync + 'static));
|
||||
|
||||
let value = &*(value as *const glib::Value);
|
||||
let value = value
|
||||
|
|
Loading…
Reference in a new issue