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

Commit

Permalink
Don't allow using types with bigger alignment than two usize as priva…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
sdroege committed Feb 13, 2020
1 parent f53a3de commit 148050e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/subclass/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ pub fn register_type<T: ObjectSubclass>() -> Type
where
<<T as ObjectSubclass>::ParentType as ObjectType>::RustClassType: IsSubclassable<T>,
{
// GLib aligns the type private data to two gsizes so we can't safely store any type there that
// requires a bigger alignment.
if mem::align_of::<T>() > 2 * mem::size_of::<usize>() {
panic!(
"Alignment {} of type not supported, bigger than {}",
mem::align_of::<T>(),
2 * mem::size_of::<usize>(),
);
}

unsafe {
use std::ffi::CString;

Expand Down

0 comments on commit 148050e

Please sign in to comment.