Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace some transmutes with safe pointer casts #795

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 10 additions & 28 deletions src/experimental/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,11 @@ impl Cell {
capabilities: vec![],
used,
permanent: false,
ready: unsafe {
std::mem::transmute(&(Node::ready as fn(RefMut<T>)) as *const fn(RefMut<T>))
},
update: unsafe {
std::mem::transmute(&(Node::update as fn(RefMut<T>)) as *const fn(RefMut<T>))
},
fixed_update: unsafe {
std::mem::transmute(&(Node::fixed_update as fn(RefMut<T>)) as *const fn(RefMut<T>))
},
draw: unsafe {
std::mem::transmute(&(Node::draw as fn(RefMut<T>)) as *const fn(RefMut<T>))
},
virtual_drop: unsafe {
std::mem::transmute(&(virtual_drop::<T> as fn(*mut ())) as *const fn(*mut ()))
},
ready: (&(Node::ready as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast(),
update: (&(Node::update as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast(),
fixed_update: (&(Node::fixed_update as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast(),
draw: (&(Node::draw as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast(),
virtual_drop: &(virtual_drop::<T> as fn(*mut ())) as *const fn(*mut ()),
data_len: std::mem::size_of::<T>(),
initialized: false,
}
Expand All @@ -312,19 +302,11 @@ impl Cell {
let (_, vtable) = unsafe { std::mem::transmute::<_, (*mut (), *mut ())>(trait_obj) };

self.vtable = vtable;
self.ready =
unsafe { std::mem::transmute(&(Node::ready as fn(RefMut<T>)) as *const fn(RefMut<T>)) };
self.update = unsafe {
std::mem::transmute(&(Node::update as fn(RefMut<T>)) as *const fn(RefMut<T>))
};
self.fixed_update = unsafe {
std::mem::transmute(&(Node::fixed_update as fn(RefMut<T>)) as *const fn(RefMut<T>))
};
self.draw =
unsafe { std::mem::transmute(&(Node::draw as fn(RefMut<T>)) as *const fn(RefMut<T>)) };
self.virtual_drop = unsafe {
std::mem::transmute(&(virtual_drop::<T> as fn(*mut ())) as *const fn(*mut ()))
};
self.ready = (&(Node::ready as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast();
self.update = (&(Node::update as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast();
self.fixed_update = (&(Node::fixed_update as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast();
self.draw = (&(Node::draw as fn(RefMut<T>)) as *const fn(RefMut<T>)).cast();
self.virtual_drop = &(virtual_drop::<T> as fn(*mut ())) as *const fn(*mut ());

unsafe {
std::ptr::copy_nonoverlapping::<T>(&data as *const _ as *mut _, self.data as *mut _, 1);
Expand Down
Loading