Skip to content

Commit e842054

Browse files
authored
Merge pull request #953 from sdroege/object-from-glib-null-assert
glib: Add `NULL` debug assertion to `from_glib_full()` and others for…
2 parents dee1d23 + 1bc6244 commit e842054

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

glib/src/object.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ macro_rules! glib_object_wrapper {
878878
#[inline]
879879
#[allow(clippy::cast_ptr_alignment)]
880880
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
881+
debug_assert!(!ptr.is_null());
881882
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
882883
$name {
883884
inner: $crate::object::TypedObjectRef::new($crate::translate::from_glib_none(ptr as *mut _)),
@@ -891,6 +892,7 @@ macro_rules! glib_object_wrapper {
891892
#[inline]
892893
#[allow(clippy::cast_ptr_alignment)]
893894
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
895+
debug_assert!(!ptr.is_null());
894896
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
895897
$name {
896898
inner: $crate::object::TypedObjectRef::new($crate::translate::from_glib_none(ptr as *mut _)),
@@ -904,6 +906,7 @@ macro_rules! glib_object_wrapper {
904906
#[inline]
905907
#[allow(clippy::cast_ptr_alignment)]
906908
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
909+
debug_assert!(!ptr.is_null());
907910
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
908911
$name {
909912
inner: $crate::object::TypedObjectRef::new($crate::translate::from_glib_full(ptr as *mut _)),
@@ -917,6 +920,7 @@ macro_rules! glib_object_wrapper {
917920
#[inline]
918921
#[allow(clippy::cast_ptr_alignment)]
919922
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> $crate::translate::Borrowed<Self> {
923+
debug_assert!(!ptr.is_null());
920924
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
921925
$crate::translate::Borrowed::new(
922926
$name {

0 commit comments

Comments
 (0)