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

Conversation

@sdroege
Copy link
Member

@sdroege sdroege commented Feb 12, 2020

We don't know the exact memory layout of the Option in relation to T
so can't easily go from a *const T to the surrounding *const Option.

Since nightly from 2020-02-12 using both pointer types interchangeably
causes segmentation faults as their memory layouts are not actually
compatible and never were, but due to some compiler changes this
actually causes crashes at runtime now.

See rust-lang/rust#69102 for details.

As an Option<_> was only used for some paranoid runtime checks that are
not really needed, simply store T directly as impl/private data of
subclasses.

This has the side-effect of having zero-sized impl/private data types to
actually occupy zero bytes of memory, and in some other cases to save a
few bytes of the allocation.


CC @EPashkin @GuillaumeGomez

We don't know the exact memory layout of the Option<T> in relation to T
so can't easily go from a *const T to the surrounding *const Option<T>.

Since nightly from 2020-02-12 using both pointer types interchangeably
causes segmentation faults as their memory layouts are not actually
compatible and never were, but due to some compiler changes this
actually causes crashes at runtime now.

See rust-lang/rust#69102 for details.

As an Option<_> was only used for some paranoid runtime checks that are
not really needed, simply store T directly as impl/private data of
subclasses.

This has the side-effect of having zero-sized impl/private data types to
actually occupy zero bytes of memory, and in some other cases to save a
few bytes of the allocation.
Instead of first reading it on the stack and the dropping it.
@sdroege
Copy link
Member Author

sdroege commented Feb 12, 2020

@GuillaumeGomez This wants another bugfix release btw, it's a quite bad bug and I don't fully understand why it didn't explode from the very beginning :)

@GuillaumeGomez
Copy link
Member

Indeed, thanks for coming up so quickly with this fix!

👍

@sdroege
Copy link
Member Author

sdroege commented Feb 12, 2020 via email

@GuillaumeGomez
Copy link
Member

It's a bit late for a release you know... We still have a few details to discuss about as well!

…te/impl data for subclasses

GLib aligns the type private data to two gsizes so we can't safely store
any type there that requires a bigger alignment.
@EPashkin
Copy link
Member

👍 Thanks.

@sdroege
Copy link
Member Author

sdroege commented Feb 13, 2020

Thanks for reviewing :)

@sdroege sdroege merged commit 28a774a into gtk-rs:master Feb 13, 2020
@sdroege sdroege deleted the subclass-no-option-impl branch February 13, 2020 06:45
@sdroege
Copy link
Member Author

sdroege commented Feb 14, 2020

Released as 0.9.3 on crates.io

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