Replace unneeded transmute calls with a safer alternative

This commit is contained in:
Sebastian Dröge 2020-04-12 19:10:47 +03:00
parent d1665b8114
commit 76a0410d41
12 changed files with 16 additions and 30 deletions

View file

@ -17,7 +17,6 @@ use gst_app_sys;
use gst_sys; use gst_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem::transmute;
use std::panic; use std::panic;
use std::ptr; use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -295,7 +294,7 @@ impl AppSink {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"new-sample\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }
@ -312,7 +311,7 @@ impl AppSink {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"new-preroll\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }

View file

@ -24,10 +24,8 @@ impl AudioChannelPosition {
if pos < 0 { if pos < 0 {
return 0; return 0;
} }
unsafe {
let val = mem::transmute::<gst_audio_sys::GstAudioChannelPosition, u32>(pos); 1 << (pos as u32)
1 << val
}
} }
pub fn positions_to_mask( pub fn positions_to_mask(

View file

@ -100,9 +100,7 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"notify::min-upstream-latency\0".as_ptr() as *const _, b"notify::min-upstream-latency\0".as_ptr() as *const _,
Some(mem::transmute( Some(*(&notify_min_upstream_latency_trampoline::<Self, F> as *const _ as *const _)),
notify_min_upstream_latency_trampoline::<Self, F> as usize,
)),
Box_::into_raw(f), Box_::into_raw(f),
) )
} }

View file

@ -23,7 +23,6 @@ use gobject_sys;
use gst_pbutils_sys; use gst_pbutils_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem::transmute;
impl Discoverer { impl Discoverer {
pub fn set_property_timeout(&self, timeout: gst::ClockTime) { pub fn set_property_timeout(&self, timeout: gst::ClockTime) {
@ -60,7 +59,7 @@ impl Discoverer {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"notify::timeout\0".as_ptr() as *const _, b"notify::timeout\0".as_ptr() as *const _,
Some(transmute(notify_timeout_trampoline::<Self, F> as usize)), Some(*(&notify_timeout_trampoline::<Self, F> as *const _ as *const _)),
Box_::into_raw(f), Box_::into_raw(f),
) )
} }

View file

@ -15,7 +15,6 @@ use glib_sys;
use gst; use gst;
use gst_player_sys; use gst_player_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem::transmute;
use Player; use Player;
use PlayerSignalDispatcher; use PlayerSignalDispatcher;
use PlayerVideoRenderer; use PlayerVideoRenderer;
@ -72,7 +71,7 @@ impl Player {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"duration-changed\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }
@ -88,7 +87,7 @@ impl Player {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"position-updated\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }
@ -104,7 +103,7 @@ impl Player {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"seek-done\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }

View file

@ -6,7 +6,6 @@ use glib::translate::*;
use gst_rtsp_server_sys; use gst_rtsp_server_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem::transmute;
use RTSPAuth; use RTSPAuth;
use RTSPToken; use RTSPToken;
@ -59,7 +58,7 @@ impl<O: IsA<RTSPAuth>> RTSPAuthExtManual for O {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"accept-certificate\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }

View file

@ -6,7 +6,6 @@ use glib_sys;
use glib_sys::{gboolean, gpointer}; use glib_sys::{gboolean, gpointer};
use gst_rtsp_server_sys; use gst_rtsp_server_sys;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem::transmute;
use RTSPSessionPool; use RTSPSessionPool;
unsafe extern "C" fn trampoline_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>( 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( glib_sys::g_source_set_callback(
source, source,
Some(transmute(trampoline_watch::<F> as usize)), Some(*(&trampoline_watch::<F> as *const _ as *const _)),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );

View file

@ -273,7 +273,6 @@ where
T: RTSPMediaFactoryImpl, T: RTSPMediaFactoryImpl,
{ {
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::mem;
static PIPELINE_QUARK: Lazy<glib::Quark> = static PIPELINE_QUARK: Lazy<glib::Quark> =
Lazy::new(|| glib::Quark::from_string("gstreamer-rs-rtsp-media-pipeline")); Lazy::new(|| glib::Quark::from_string("gstreamer-rs-rtsp-media-pipeline"));
@ -291,7 +290,7 @@ where
media as *mut _, media as *mut _,
PIPELINE_QUARK.to_glib(), PIPELINE_QUARK.to_glib(),
pipeline as *mut _, 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 _ pipeline as *mut _

View file

@ -14,7 +14,6 @@ use glib;
use glib::translate::{from_glib_full, ToGlib, ToGlibPtr}; use glib::translate::{from_glib_full, ToGlib, ToGlibPtr};
use gst; use gst;
use std::mem;
use std::ptr; use std::ptr;
pub fn convert_sample( pub fn convert_sample(
@ -106,7 +105,7 @@ unsafe fn convert_sample_async_unsafe<F>(
timeout.to_glib(), timeout.to_glib(),
Some(convert_sample_async_trampoline::<F>), Some(convert_sample_async_trampoline::<F>),
Box::into_raw(user_data) as glib_sys::gpointer, 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>),
); );
} }

View file

@ -22,7 +22,6 @@ use glib::GString;
use gst_sys; use gst_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem::transmute;
use std::path; use std::path;
pub trait GstBinExtManual: 'static { pub trait GstBinExtManual: 'static {
@ -99,7 +98,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
connect_raw( connect_raw(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
b"do-latency\0".as_ptr() as *const _, 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), Box_::into_raw(f),
) )
} }

View file

@ -16,7 +16,6 @@ use glib_sys;
use glib_sys::{gboolean, gpointer}; use glib_sys::{gboolean, gpointer};
use gst_sys; use gst_sys;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem::transmute;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
@ -94,7 +93,7 @@ impl Bus {
let source = gst_sys::gst_bus_create_watch(self.to_glib_none().0); let source = gst_sys::gst_bus_create_watch(self.to_glib_none().0);
glib_sys::g_source_set_callback( glib_sys::g_source_set_callback(
source, source,
Some(transmute(trampoline_watch::<F> as usize)), Some(*(&trampoline_watch::<F> as *const _ as *const _)),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );

View file

@ -328,8 +328,7 @@ where
let func = func as *const gobject_sys::GValue; let func = func as *const gobject_sys::GValue;
let func = gobject_sys::g_value_get_boxed(func); let func = gobject_sys::g_value_get_boxed(func);
#[allow(clippy::transmute_ptr_to_ref)] let func = &*(func as *const &(dyn Fn(T) -> bool + Send + Sync + 'static));
let func: &&(dyn Fn(T) -> bool + Send + Sync + 'static) = mem::transmute(func);
let value = &*(value as *const glib::Value); let value = &*(value as *const glib::Value);
let value = value let value = value