Skip to content

Commit 28d83c8

Browse files
committed
glib: Assert immediately after type registration that the returned type is valid
This avoids checking for that in every caller.
1 parent 3273b19 commit 28d83c8

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

glib/src/subclass/boxed.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ pub fn register_boxed_type<T: BoxedType>() -> crate::Type {
5353
type_name.to_str().unwrap()
5454
);
5555

56-
from_glib(gobject_ffi::g_boxed_type_register_static(
56+
let type_ = crate::Type::from_glib(gobject_ffi::g_boxed_type_register_static(
5757
type_name.as_ptr(),
5858
Some(boxed_copy::<T>),
5959
Some(boxed_free::<T>),
60-
))
60+
));
61+
assert!(type_.is_valid());
62+
63+
type_
6164
}
6265
}
6366

glib/src/subclass/interface.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ pub fn register_interface<T: ObjectInterface>() -> Type {
197197
gobject_ffi::g_type_interface_add_prerequisite(type_, prerequisite);
198198
}
199199

200-
let type_ = from_glib(type_);
200+
let type_ = Type::from_glib(type_);
201+
assert!(type_.is_valid());
201202

202203
T::type_init(&mut InitializingType::<T>(type_, marker::PhantomData));
203204

glib/src/subclass/shared.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ pub fn register_shared_type<T: SharedType>() -> crate::Type {
135135
type_name.to_str().unwrap()
136136
);
137137

138-
from_glib(gobject_ffi::g_boxed_type_register_static(
138+
let type_ = crate::Type::from_glib(gobject_ffi::g_boxed_type_register_static(
139139
type_name.as_ptr(),
140140
Some(shared_ref::<T>),
141141
Some(shared_unref::<T>),
142-
))
142+
));
143+
assert!(type_.is_valid());
144+
145+
type_
143146
}
144147
}
145148

glib/src/subclass/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ pub fn register_type<T: ObjectSubclass>() -> Type {
936936
type_name.to_str().unwrap()
937937
);
938938

939-
let type_ = from_glib(gobject_ffi::g_type_register_static_simple(
939+
let type_ = Type::from_glib(gobject_ffi::g_type_register_static_simple(
940940
<T::ParentType as StaticType>::static_type().into_glib(),
941941
type_name.as_ptr(),
942942
mem::size_of::<T::Class>() as u32,
@@ -949,6 +949,7 @@ pub fn register_type<T: ObjectSubclass>() -> Type {
949949
0
950950
},
951951
));
952+
assert!(type_.is_valid());
952953

953954
let mut data = T::type_data();
954955
data.as_mut().type_ = type_;

0 commit comments

Comments
 (0)