Skip to content

Commit 3c2ccf3

Browse files
authored
Merge pull request #22 from mach-kernel/120423/xpc-object-default
xpc-sys: Don't xpc_release NULLs
2 parents d99a5ba + 6a71d69 commit 3c2ccf3

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xpc-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "xpc-sys"
33
description = "Conveniently call routines with wrappers for xpc_pipe_routine() and go from Rust types to XPC objects and back!"
4-
version = "0.4.2"
4+
version = "0.5.0"
55
authors = ["David Stancu <dstancu@nyu.edu>"]
66
license = "MIT"
77
edition = "2018"

xpc-sys/src/objects/xpc_object.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,14 @@ impl XPCObject {
8585
}
8686
}
8787

88-
impl Default for XPCObject {
89-
fn default() -> Self {
90-
Self(null_mut(), XPCType(null_mut()))
91-
}
92-
}
93-
9488
impl fmt::Display for XPCObject {
9589
/// Use xpc_copy_description to show as a string, for
9690
/// _xpc_type_dictionary contents are shown!
9791
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9892
let XPCObject(ptr, _) = self;
9993

10094
if *ptr == null_mut() {
101-
write!(f, "XPCObject is NULL")
95+
write!(f, "{:?} xpc_object_t is NULL", self)
10296
} else {
10397
let xpc_desc = unsafe { xpc_copy_description(*ptr) };
10498
let cstr = unsafe { CStr::from_ptr(xpc_desc) };
@@ -220,6 +214,12 @@ impl Drop for XPCObject {
220214
/// https://developer.apple.com/documentation/xpc/1505851-xpc_release
221215
fn drop(&mut self) {
222216
let XPCObject(ptr, _) = &self;
217+
218+
if *ptr == null_mut() {
219+
log::info!("XPCObject xpc_object_t is NULL, not calling xpc_release()");
220+
return
221+
}
222+
223223
log::info!(
224224
"XPCObject drop ({:p}, {}, {})",
225225
*ptr,
@@ -229,6 +229,7 @@ impl Drop for XPCObject {
229229
.map(|(r, xr)| format!("refs {} xrefs {}", r, xr))
230230
.unwrap_or("refs ???".to_string()),
231231
);
232+
232233
unsafe { xpc_release(*ptr) }
233234
}
234235
}

xpc-sys/src/objects/xpc_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
_xpc_type_array, _xpc_type_bool, _xpc_type_dictionary, _xpc_type_double, _xpc_type_fd,
33
_xpc_type_int64, _xpc_type_mach_recv, _xpc_type_mach_send, _xpc_type_s, _xpc_type_shmem,
4-
_xpc_type_string, _xpc_type_uint64, xpc_get_type, xpc_object_t, xpc_type_get_name, xpc_type_t,
4+
_xpc_type_string, _xpc_type_uint64, xpc_get_type, xpc_object_t, xpc_type_get_name, xpc_type_t, _xpc_type_null,
55
};
66

77
use crate::objects::xpc_error::XPCError;
@@ -93,6 +93,7 @@ lazy_static! {
9393
unsafe { (&_xpc_type_mach_recv as *const _xpc_type_s).into() };
9494
pub static ref Fd: XPCType = unsafe { (&_xpc_type_fd as *const _xpc_type_s).into() };
9595
pub static ref Shmem: XPCType = unsafe { (&_xpc_type_shmem as *const _xpc_type_s).into() };
96+
pub static ref Null: XPCType = unsafe { (&_xpc_type_null as *const _xpc_type_s).into() };
9697
}
9798

9899
/// Runtime type check for XPC object.

0 commit comments

Comments
 (0)