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

Commit 155ea11

Browse files
committed
Don't allow using types with bigger alignment than two usize as private/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.
1 parent 85daeab commit 155ea11

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/subclass/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ pub fn register_type<T: ObjectSubclass>() -> Type
454454
where
455455
<<T as ObjectSubclass>::ParentType as ObjectType>::RustClassType: IsSubclassable<T>,
456456
{
457+
// GLib aligns the type private data to two gsizes so we can't safely store any type there that
458+
// requires a bigger alignment.
459+
if mem::align_of::<T>() > 2 * mem::size_of::<usize>() {
460+
panic!(
461+
"Alignment {} of type not supported, bigger than {}",
462+
mem::align_of::<T>(),
463+
2 * mem::size_of::<usize>(),
464+
);
465+
}
466+
457467
unsafe {
458468
use std::ffi::CString;
459469

0 commit comments

Comments
 (0)