Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Zeroed #505

Merged
merged 2 commits into from
Jul 15, 2019
Merged

Zeroed #505

merged 2 commits into from
Jul 15, 2019

Conversation

GuillaumeGomez
Copy link
Member

I'll resume the regenerations of all other crates tomorrow.

cc @EPashkin @sdroege

@EPashkin
Copy link
Member

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());
Copy link
Member

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/closure.rs Outdated Show resolved Hide resolved
src/object.rs Outdated Show resolved Hide resolved
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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

src/object.rs Outdated Show resolved Hide resolved
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()
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@GuillaumeGomez
Copy link
Member Author

Updated. However, I'm absolutely not sure that this code is correct. I find this new rust API very bad...

@sdroege
Copy link
Member

sdroege commented Jul 13, 2019 via email

src/boxed.rs Show resolved Hide resolved
src/object.rs Outdated Show resolved Hide resolved
src/object.rs Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member Author

Updated.

@sdroege sdroege merged commit 28831d1 into gtk-rs:master Jul 15, 2019
@GuillaumeGomez GuillaumeGomez deleted the zeroed branch July 15, 2019 12:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants