-
-
Notifications
You must be signed in to change notification settings - Fork 62
Conversation
Thanks, also note that this is seems done internally too rust-lang/rust#62150 |
src/boxed.rs
Outdated
@@ -366,7 +366,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> Uninitialized for Boxed<T, MM> { | |||
unsafe fn uninitialized() -> Self { | |||
Boxed { | |||
inner: { | |||
let mut inner = Box::<T>::new(mem::zeroed()); | |||
let mut inner = Box::<T>::new(mem::MaybeUninit::zeroed().assume_init()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong again and defeats the purpose of MaybeUninit
. This code here has to be
let mut inner = Box::<T>::new(mem::MaybeUninit::zeroed();
MM::init(inner.as_mut_ptr());
AnyBox::Native(inner.assume_init());
src/object.rs
Outdated
@@ -1436,7 +1438,7 @@ impl<T: ObjectType> ObjectExt for T { | |||
|
|||
fn downgrade(&self) -> WeakRef<T> { | |||
unsafe { | |||
let w = WeakRef(Box::new(mem::zeroed()), PhantomData); | |||
let w = WeakRef(Box::new(mem::MaybeUninit::zeroed().assume_init()), PhantomData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
let w = Box::new(mem::MaybeUninit::zeroed());
gobject_sys::g_weak_ref_init(
mut_override((&mut *w).as_mut_ptr()),
self.as_object_ref().to_glib_none().0,
);
// Or maybe this line can be *w = (&mut *w).assume_init()?
ptr::write(&mut *w, ptr::read(&*w).assume_init());
WeakRef(w)
src/object.rs
Outdated
@@ -1530,7 +1532,7 @@ pub struct WeakRef<T: ObjectType>(Box<gobject_sys::GWeakRef>, PhantomData<*const | |||
impl<T: ObjectType> WeakRef<T> { | |||
pub fn new() -> WeakRef<T> { | |||
unsafe { | |||
let w = WeakRef(Box::new(mem::zeroed()), PhantomData); | |||
let w = WeakRef(Box::new(mem::MaybeUninit::zeroed().assume_init()), PhantomData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
src/time_val.rs
Outdated
@@ -27,6 +27,6 @@ impl<'a> ToGlibPtrMut<'a, *mut glib_sys::GTimeVal> for TimeVal { | |||
|
|||
impl Uninitialized for TimeVal { | |||
unsafe fn uninitialized() -> TimeVal { | |||
mem::zeroed() | |||
mem::MaybeUninit::zeroed().assume_init() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we want to get rid of this trait anyway, just leave it as mem::zeroed()
. What you write is exactly equivalent to it apart from being more keypresses.
src/value.rs
Outdated
@@ -273,7 +273,7 @@ impl From<SendValue> for Value { | |||
|
|||
impl Uninitialized for Value { | |||
unsafe fn uninitialized() -> Value { | |||
Value(mem::zeroed(), PhantomData) | |||
Value(mem::MaybeUninit::zeroed().assume_init(), PhantomData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
Updated. However, I'm absolutely not sure that this code is correct. I find this new rust API very bad... |
On 12 July 2019 23:56:13 EEST, Guillaume Gomez ***@***.***> wrote:
Updated. However, I'm **absolutely** not sure that this code is
correct. I find this new rust API very bad...
I'll review this and the other ones tomorrow evening.
Personally I think the new API is much clearer. You can't accidentally use something uninitialized and it's absolutely clear at which point things are actually initialized. It's much safer compared to before, which was basically like in C and not very Rust-like.
…--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Updated. |
I'll resume the regenerations of all other crates tomorrow.
cc @EPashkin @sdroege