Replace various transmutes in meta code with pointer casts

This commit is contained in:
Sebastian Dröge 2018-10-11 11:31:28 +03:00
parent e2950749e8
commit 7189a6a7c1

View file

@ -8,7 +8,6 @@
use std::fmt; use std::fmt;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem;
use std::ops; use std::ops;
use miniobject::MiniObject; use miniobject::MiniObject;
@ -36,7 +35,7 @@ pub unsafe trait MetaAPI: Sized {
} }
MetaRef { MetaRef {
meta: mem::transmute(ptr), meta: &*(ptr as *const Self),
buffer, buffer,
} }
} }
@ -56,7 +55,7 @@ pub unsafe trait MetaAPI: Sized {
} }
MetaRefMut { MetaRefMut {
meta: mem::transmute(ptr), meta: &mut *(ptr as *mut Self),
buffer, buffer,
mode: PhantomData, mode: PhantomData,
} }
@ -109,7 +108,7 @@ impl<'a, T: MetaAPI, U> ops::DerefMut for MetaRefMut<'a, T, U> {
impl<'a, T: MetaAPI, U> AsRef<MetaRef<'a, T>> for MetaRefMut<'a, T, U> { impl<'a, T: MetaAPI, U> AsRef<MetaRef<'a, T>> for MetaRefMut<'a, T, U> {
fn as_ref(&self) -> &MetaRef<'a, T> { fn as_ref(&self) -> &MetaRef<'a, T> {
unsafe { mem::transmute(self) } unsafe { &*(self as *const MetaRefMut<'a, T, U> as *const MetaRef<'a, T>) }
} }
} }
@ -133,7 +132,7 @@ impl<'a> MetaRef<'a, Meta> {
let type_ = self.get_api(); let type_ = self.get_api();
if type_ == glib::Type::Invalid || target_type == type_ { if type_ == glib::Type::Invalid || target_type == type_ {
Some(unsafe { mem::transmute(self) }) Some(unsafe { &*(self as *const MetaRef<'a, Meta> as *const MetaRef<'a, T>) })
} else { } else {
None None
} }
@ -176,7 +175,7 @@ impl<'a, U> MetaRefMut<'a, Meta, U> {
let type_ = self.get_api(); let type_ = self.get_api();
if type_ == glib::Type::Invalid || target_type == type_ { if type_ == glib::Type::Invalid || target_type == type_ {
Some(unsafe { mem::transmute(self) }) Some(unsafe { &*(self as *mut MetaRefMut<'a, Meta, U> as *const MetaRefMut<'a, T, U>) })
} else { } else {
None None
} }