Skip to content

Assert when creating a CFType from null #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core-foundation/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl TCFType for CFType {

#[inline]
unsafe fn wrap_under_get_rule(reference: CFTypeRef) -> CFType {
assert!(!reference.is_null(), "Attempted to create a NULL object.");
let reference: CFTypeRef = CFRetain(reference);
TCFType::wrap_under_create_rule(reference)
}
Expand All @@ -254,6 +255,7 @@ impl TCFType for CFType {

#[inline]
unsafe fn wrap_under_create_rule(obj: CFTypeRef) -> CFType {
assert!(!obj.is_null(), "Attempted to create a NULL object.");
CFType(obj)
}

Expand Down
2 changes: 2 additions & 0 deletions core-foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ macro_rules! impl_TCFType {

#[inline]
unsafe fn wrap_under_get_rule(reference: $ty_ref) -> Self {
assert!(!reference.is_null(), "Attempted to create a NULL object.");
let reference = $crate::base::CFRetain(reference as *const ::std::os::raw::c_void) as $ty_ref;
$crate::base::TCFType::wrap_under_create_rule(reference)
}
Expand All @@ -106,6 +107,7 @@ macro_rules! impl_TCFType {

#[inline]
unsafe fn wrap_under_create_rule(reference: $ty_ref) -> Self {
assert!(!reference.is_null(), "Attempted to create a NULL object.");
// we need one PhantomData for each type parameter so call ourselves
// again with @Phantom $p to produce that
$ty(reference $(, impl_TCFType!(@Phantom $p))*)
Expand Down
2 changes: 2 additions & 0 deletions core-foundation/src/propertylist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl CFPropertyList {

#[inline]
pub unsafe fn wrap_under_get_rule(reference: CFPropertyListRef) -> CFPropertyList {
assert!(!reference.is_null(), "Attempted to create a NULL object.");
let reference = CFRetain(reference);
CFPropertyList(reference)
}
Expand All @@ -147,6 +148,7 @@ impl CFPropertyList {

#[inline]
pub unsafe fn wrap_under_create_rule(obj: CFPropertyListRef) -> CFPropertyList {
assert!(!obj.is_null(), "Attempted to create a NULL object.");
CFPropertyList(obj)
}

Expand Down
2 changes: 2 additions & 0 deletions io-surface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl TCFType for IOSurface {

#[inline]
unsafe fn wrap_under_create_rule(obj: IOSurfaceRef) -> IOSurface {
assert!(!obj.is_null(), "Attempted to create a NULL object.");
IOSurface {
obj: obj,
}
Expand All @@ -92,6 +93,7 @@ impl TCFType for IOSurface {

#[inline]
unsafe fn wrap_under_get_rule(reference: IOSurfaceRef) -> IOSurface {
assert!(!reference.is_null(), "Attempted to create a NULL object.");
let reference = CFRetain(reference as *const c_void) as IOSurfaceRef;
TCFType::wrap_under_create_rule(reference)
}
Expand Down