Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

GuillaumeGomez commented Jul 11, 2019

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

cc @EPashkin @sdroege

@EPashkin

This comment has been minimized.

Copy link
Member

EPashkin commented Jul 12, 2019

Thanks, also note that this is seems done internally too rust-lang/rust#62150

@@ -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());

This comment has been minimized.

Copy link
@sdroege

sdroege Jul 12, 2019

Member

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
@@ -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);

This comment has been minimized.

Copy link
@sdroege

sdroege Jul 12, 2019

Member

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)
@@ -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);

This comment has been minimized.

Copy link
@sdroege

sdroege Jul 12, 2019

Member

See above

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

This comment has been minimized.

Copy link
@sdroege

sdroege Jul 12, 2019

Member

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.

@@ -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)

This comment has been minimized.

Copy link
@sdroege

sdroege Jul 12, 2019

Member

See above

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:zeroed branch from d274b15 to ce720f2 Jul 12, 2019
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jul 12, 2019

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

@sdroege

This comment has been minimized.

Copy link
Member

sdroege commented Jul 13, 2019

src/boxed.rs Show resolved Hide resolved
src/object.rs Outdated Show resolved Hide resolved
src/object.rs Outdated Show resolved Hide resolved
@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:zeroed branch from ce720f2 to 2ec63a3 Jul 15, 2019
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jul 15, 2019

Updated.

@sdroege sdroege merged commit 28831d1 into gtk-rs:master Jul 15, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@GuillaumeGomez GuillaumeGomez deleted the GuillaumeGomez:zeroed branch Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.