Skip to content

Commit

Permalink
Replace mem::uninitialized with mem::MaybeUninit
Browse files Browse the repository at this point in the history
  • Loading branch information
aldanor committed Jul 19, 2019
1 parent 986d55c commit b1ca595
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
12 changes: 6 additions & 6 deletions hdf5-types/src/string.rs
Expand Up @@ -375,9 +375,9 @@ impl<A: Array<Item = u8>> Clone for FixedAscii<A> {
#[inline]
fn clone(&self) -> Self {
unsafe {
let mut buf: A = mem::uninitialized();
ptr::copy_nonoverlapping(self.buf.as_ptr(), buf.as_mut_ptr(), A::capacity());
FixedAscii { buf }
let mut buf = mem::MaybeUninit::<A>::uninit();
ptr::copy_nonoverlapping(self.buf.as_ptr(), buf.as_mut_ptr() as *mut _, A::capacity());
FixedAscii { buf: buf.assume_init() }
}
}
}
Expand Down Expand Up @@ -469,9 +469,9 @@ impl<A: Array<Item = u8>> Clone for FixedUnicode<A> {
#[inline]
fn clone(&self) -> Self {
unsafe {
let mut buf: A = mem::uninitialized();
ptr::copy_nonoverlapping(self.buf.as_ptr(), buf.as_mut_ptr(), A::capacity());
FixedUnicode { buf }
let mut buf = mem::MaybeUninit::<A>::uninit();
ptr::copy_nonoverlapping(self.buf.as_ptr(), buf.as_mut_ptr() as *mut _, A::capacity());
FixedUnicode { buf: buf.assume_init() }
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/hl/container.rs
Expand Up @@ -206,8 +206,8 @@ impl<'a> Reader<'a> {
pub fn read_scalar<T: H5Type>(&self) -> Result<T> {
let obj_ndim = self.obj.get_shape()?.ndim();
ensure!(obj_ndim == 0, "ndim mismatch: expected scalar, got {}", obj_ndim);
let mut val: T = unsafe { mem::uninitialized() };
self.read_into_buf(&mut val as *mut _, None, None).map(|_| val)
let mut val = mem::MaybeUninit::<T>::uninit();
self.read_into_buf(val.as_mut_ptr(), None, None).map(|_| unsafe { val.assume_init() })
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/hl/dataset.rs
Expand Up @@ -140,13 +140,11 @@ impl Dataset {
H5D_fill_value_t::H5D_FILL_VALUE_UNDEFINED => Ok(None),
_ => {
let datatype = Datatype::from_type::<T>()?;
let mut value: T = mem::uninitialized();
h5try!(H5Pget_fill_value(
dcpl_id,
datatype.id(),
&mut value as *mut _ as *mut _
));
Ok(Some(value))
let mut value = mem::MaybeUninit::<T>::uninit();
h5try!(
H5Pget_fill_value(dcpl_id, datatype.id(), value.as_mut_ptr() as *mut _,)
);
Ok(Some(value.assume_init()))
}
}
})
Expand Down
8 changes: 4 additions & 4 deletions src/hl/plist/file_access.rs
Expand Up @@ -1554,10 +1554,10 @@ impl FileAccess {
#[doc(hidden)]
#[cfg(feature = "mpio")]
fn get_mpio(&self) -> Result<MpioDriver> {
let mut comm: mpi_sys::MPI_Comm = unsafe { mem::uninitialized() };
let mut info: mpi_sys::MPI_Info = unsafe { mem::uninitialized() };
h5try!(H5Pget_fapl_mpio(self.id(), &mut comm as *mut _, &mut info as *mut _));
Ok(MpioDriver { comm, info })
let mut comm = mem::MaybeUninit::<mpi_sys::MPI_Comm>::uninit();
let mut info = mem::MaybeUninit::<mpi_sys::MPI_Info>::uninit();
h5try!(H5Pget_fapl_mpio(self.id(), comm.as_mut_ptr(), info.as_mut_ptr()));
Ok(unsafe { MpioDriver { comm: comm.assume_init(), info: info.assume_init() } })
}

#[doc(hidden)]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_plist.rs
Expand Up @@ -298,9 +298,9 @@ fn test_fapl_driver_mpio() -> hdf5::Result<()> {
b.mpio(world_comm, None);

let d = check_matches!(b.finish()?.get_driver()?, d, FileDriver::Mpio(d));
let mut cmp = unsafe { mem::uninitialized() };
unsafe { MPI_Comm_compare(d.comm, world_comm, &mut cmp) };
assert_eq!(cmp, MPI_CONGRUENT as _);
let mut cmp = mem::MaybeUninit::uninit();
unsafe { MPI_Comm_compare(d.comm, world_comm, cmp.as_mut_ptr() as &mut _) };
assert_eq!(unsafe { cmp.assume_init() }, MPI_CONGRUENT as _);

Ok(())
}
Expand Down

0 comments on commit b1ca595

Please sign in to comment.