Remove all uses of mem::uninitialized for Rust 1.38

This commit is contained in:
Mark McCaskey
2019-07-31 13:21:20 +09:00
parent 99ecfaa503
commit 0ab8a0de09
6 changed files with 38 additions and 33 deletions

View File

@ -196,18 +196,15 @@ pub fn _getaddrinfo(
let hints = hints_ptr.deref(memory).map(|hints_memory| { let hints = hints_ptr.deref(memory).map(|hints_memory| {
let hints_guest = hints_memory.get(); let hints_guest = hints_memory.get();
unsafe { addrinfo {
let mut hints_native: addrinfo = std::mem::uninitialized(); ai_flags: hints_guest.ai_flags,
hints_native.ai_flags = hints_guest.ai_flags; ai_family: hints_guest.ai_family,
hints_native.ai_family = hints_guest.ai_family; ai_socktype: hints_guest.ai_socktype,
hints_native.ai_socktype = hints_guest.ai_socktype; ai_protocol: hints_guest.ai_protocol,
hints_native.ai_protocol = hints_guest.ai_protocol; ai_addrlen: 0,
hints_native.ai_addrlen = 0; ai_addr: std::ptr::null_mut(),
hints_native.ai_addr = std::ptr::null_mut(); ai_canonname: std::ptr::null_mut(),
hints_native.ai_canonname = std::ptr::null_mut(); ai_next: std::ptr::null_mut(),
hints_native.ai_next = std::ptr::null_mut();
hints_native
} }
}); });

View File

@ -71,7 +71,7 @@ pub fn sbrk(ctx: &mut Ctx, increment: i32) -> i32 {
debug!("emscripten::sbrk"); debug!("emscripten::sbrk");
// let old_dynamic_top = 0; // let old_dynamic_top = 0;
// let new_dynamic_top = 0; // let new_dynamic_top = 0;
let mut globals = get_emscripten_data(ctx).globals; let globals = get_emscripten_data(ctx).globals;
let dynamictop_ptr = (globals.dynamictop_ptr) as usize; let dynamictop_ptr = (globals.dynamictop_ptr) as usize;
let old_dynamic_top = ctx.memory(0).view::<u32>()[dynamictop_ptr].get() as i32; let old_dynamic_top = ctx.memory(0).view::<u32>()[dynamictop_ptr].get() as i32;
let new_dynamic_top: i32 = old_dynamic_top + increment; let new_dynamic_top: i32 = old_dynamic_top + increment;

View File

@ -617,13 +617,13 @@ pub fn ___syscall102(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
unsafe { address_len.deref_mut(ctx.memory(0)).unwrap().get_mut() }; unsafe { address_len.deref_mut(ctx.memory(0)).unwrap().get_mut() };
// let mut address_len_addr: socklen_t = 0; // let mut address_len_addr: socklen_t = 0;
let (fd, host_address) = unsafe { let mut host_address: sockaddr = sockaddr {
let mut host_address: sockaddr = std::mem::uninitialized(); sa_family: Default::default(),
let fd = accept(socket, &mut host_address, address_len_addr); sa_data: Default::default(),
#[cfg(target_os = "macos")]
(fd, host_address) sa_len: Default::default(),
}; };
let fd = unsafe { accept(socket, &mut host_address, address_len_addr) };
let address_addr = unsafe { address.deref_mut(ctx.memory(0)).unwrap().get_mut() }; let address_addr = unsafe { address.deref_mut(ctx.memory(0)).unwrap().get_mut() };
address_addr.sa_family = host_address.sa_family as _; address_addr.sa_family = host_address.sa_family as _;
@ -651,15 +651,18 @@ pub fn ___syscall102(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
let address_len_addr = let address_len_addr =
unsafe { address_len.deref_mut(ctx.memory(0)).unwrap().get_mut() }; unsafe { address_len.deref_mut(ctx.memory(0)).unwrap().get_mut() };
let (ret, sock_addr_host) = unsafe { let mut sock_addr_host: sockaddr = sockaddr {
// read host data into new var sa_family: Default::default(),
let mut address: sockaddr = std::mem::uninitialized(); sa_data: Default::default(),
let ret = getsockname( #[cfg(target_os = "macos")]
sa_len: Default::default(),
};
let ret = unsafe {
getsockname(
socket, socket,
&mut address as *mut sockaddr, &mut sock_addr_host as *mut sockaddr,
address_len_addr as *mut u32, address_len_addr as *mut u32,
); )
(ret, address)
}; };
// translate from host data into emscripten data // translate from host data into emscripten data
let mut address_mut = unsafe { address.deref_mut(ctx.memory(0)).unwrap().get_mut() }; let mut address_mut = unsafe { address.deref_mut(ctx.memory(0)).unwrap().get_mut() };

View File

@ -219,7 +219,7 @@ fn __get_async_io_payload<
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Default, Copy, Clone)]
struct SockaddrIn { struct SockaddrIn {
sin_family: u16, // e.g. AF_INET sin_family: u16, // e.g. AF_INET
sin_port: u16, // e.g. htons(3490) sin_port: u16, // e.g. htons(3490)
@ -315,7 +315,7 @@ impl Tcp4Listener {
self.fd, self.fd,
EpollDirection::In, EpollDirection::In,
move |fd| -> Result<Arc<TcpStream>, i32> { move |fd| -> Result<Arc<TcpStream>, i32> {
let mut incoming_sa: SockaddrIn = unsafe { ::std::mem::uninitialized() }; let mut incoming_sa: SockaddrIn = SockaddrIn::default();
let mut real_len: usize = ::std::mem::size_of::<SockaddrIn>(); let mut real_len: usize = ::std::mem::size_of::<SockaddrIn>();
let conn = unsafe { _accept4(fd, &mut incoming_sa, &mut real_len, O_NONBLOCK) }; let conn = unsafe { _accept4(fd, &mut incoming_sa, &mut real_len, O_NONBLOCK) };
if conn >= 0 { if conn >= 0 {

View File

@ -1,4 +1,3 @@
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum MonoVecInner<T> { enum MonoVecInner<T> {
None, None,
@ -36,7 +35,7 @@ impl<T> MonoVec<T> {
} }
pub fn push(&mut self, item: T) { pub fn push(&mut self, item: T) {
let uninit = unsafe { mem::uninitialized() }; let uninit = MonoVecInner::None;
let prev = mem::replace(&mut self.inner, uninit); let prev = mem::replace(&mut self.inner, uninit);
let next = match prev { let next = match prev {
MonoVecInner::None => MonoVecInner::Inline(item), MonoVecInner::None => MonoVecInner::Inline(item),
@ -54,7 +53,7 @@ impl<T> MonoVec<T> {
match self.inner { match self.inner {
MonoVecInner::None => None, MonoVecInner::None => None,
MonoVecInner::Inline(ref mut item) => { MonoVecInner::Inline(ref mut item) => {
let uninit = unsafe { mem::uninitialized() }; let uninit = unsafe { mem::zeroed() };
let item = mem::replace(item, uninit); let item = mem::replace(item, uninit);
let uninit = mem::replace(&mut self.inner, MonoVecInner::None); let uninit = mem::replace(&mut self.inner, MonoVecInner::None);
mem::forget(uninit); mem::forget(uninit);

View File

@ -19,7 +19,10 @@ pub fn platform_clock_res_get(
}; };
let (output, timespec_out) = unsafe { let (output, timespec_out) = unsafe {
let mut timespec_out: timespec = mem::uninitialized(); let mut timespec_out: timespec = timespec {
tv_sec: 0,
tv_nsec: 0,
};
(clock_getres(unix_clock_id, &mut timespec_out), timespec_out) (clock_getres(unix_clock_id, &mut timespec_out), timespec_out)
}; };
@ -44,7 +47,10 @@ pub fn platform_clock_time_get(
}; };
let (output, timespec_out) = unsafe { let (output, timespec_out) = unsafe {
let mut timespec_out: timespec = mem::uninitialized(); let mut timespec_out: timespec = timespec {
tv_sec: 0,
tv_nsec: 0,
};
( (
clock_gettime(unix_clock_id, &mut timespec_out), clock_gettime(unix_clock_id, &mut timespec_out),
timespec_out, timespec_out,