Skip to content

Commit

Permalink
use MaybeUninit properly, updated cgmath
Browse files Browse the repository at this point in the history
  • Loading branch information
DasEtwas authored and zakarumych committed Mar 28, 2020
1 parent af477d0 commit 119f5ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
bigger-arrays = []

[dependencies]
cgmath = { version = "0.16", optional = true }
cgmath = { version = "0.17", optional = true }
nalgebra = { version = "0.20", optional = true }
glsl-layout-derive = { path = "glsl-layout-derive" }

Expand Down
32 changes: 21 additions & 11 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ macro_rules! impl_array {
// Each element of `values` read once and then forgotten.
// Hence safe in case `f` never panics.
// TODO: Make it panic-safe.
let mut result: [U; $size] = ::std::mem::MaybeUninit::zeroed().assume_init();
let mut result: ::std::mem::MaybeUninit<[U; $size]> =
::std::mem::MaybeUninit::zeroed();
for i in 0..$size {
write(&mut result[i], f(read(&mut values[i])));
write(
result.as_mut_ptr().cast::<U>().add(i),
f(read(&mut values[i])),
);
}
forget(values);
result
result.assume_init()
}
}
}
Expand Down Expand Up @@ -226,12 +230,15 @@ macro_rules! impl_array {
use std::ptr::write;
unsafe {
// All elements of `result` is written.
let mut result: [Element<T::Std140>; $size] =
::std::mem::MaybeUninit::zeroed().assume_init();
let mut result: ::std::mem::MaybeUninit<[Element<T::Std140>; $size]> =
::std::mem::MaybeUninit::zeroed();
for i in 0..$size {
write(&mut result[i], self[i].std140().into());
write(
result.as_mut_ptr().cast::<Element<T::Std140>>().add(i),
self[i].std140().into(),
);
}
Array(result, PhantomData)
Array(result.assume_init(), PhantomData)
}
}
}
Expand All @@ -247,12 +254,15 @@ macro_rules! impl_array {
use std::ptr::write;
unsafe {
// All elements of `result` is written.
let mut result: [Element<T::Std140>; $size] =
::std::mem::MaybeUninit::zeroed().assume_init();
let mut result: ::std::mem::MaybeUninit<[Element<T::Std140>; $size]> =
::std::mem::MaybeUninit::zeroed();
for i in 0..$size {
write(&mut result[i], self.0[i].0.std140().into());
write(
result.as_mut_ptr().cast::<Element<T::Std140>>().add(i),
self.0[i].0.std140().into(),
);
}
Array(result, PhantomData)
Array(result.assume_init(), PhantomData)
}
}
}
Expand Down

0 comments on commit 119f5ec

Please sign in to comment.