mirror of
https://github.com/apple/swift-system
synced 2026-11-26 04:57:54 +00:00
use inout conversion
- this is the situation where it is appropriate
This commit is contained in:
1 parent
6ee96ffdb5
commit
e8bb779909
2 files changed
+21
-27
No files matched your search
@@ -147,9 +147,9 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
||||
@inlinable
|
||||
public init() {
|
||||
var storage: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
|
||||
withUnsafeMutablePointer(to: &storage) { storage in
|
||||
_machPrecondition(mach_port_allocate(mach_task_self_, MACH_PORT_RIGHT_RECEIVE, storage))
|
||||
}
|
||||
_machPrecondition(
|
||||
mach_port_allocate(mach_task_self_, MACH_PORT_RIGHT_RECEIVE, &storage)
|
||||
)
|
||||
|
||||
// name-only init will guard ReceiveRights
|
||||
self.init(name: storage)
|
||||
@@ -224,17 +224,15 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
||||
var newRight: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
|
||||
var newRightType: mach_port_type_t = MACH_PORT_TYPE_NONE
|
||||
|
||||
withUnsafeMutablePointer(to: &newRight) { newRight in
|
||||
withUnsafeMutablePointer(to: &newRightType) { newRightType in
|
||||
_machPrecondition(
|
||||
mach_port_extract_right(mach_task_self_,
|
||||
_name,
|
||||
mach_msg_type_name_t(MACH_MSG_TYPE_MAKE_SEND_ONCE),
|
||||
newRight,
|
||||
newRightType)
|
||||
)
|
||||
}
|
||||
}
|
||||
_machPrecondition(
|
||||
mach_port_extract_right(
|
||||
mach_task_self_,
|
||||
_name,
|
||||
mach_msg_type_name_t(MACH_MSG_TYPE_MAKE_SEND_ONCE),
|
||||
&newRight,
|
||||
&newRightType
|
||||
)
|
||||
)
|
||||
|
||||
// The value of newRight is validated by the Mach.Port initializer
|
||||
precondition(newRightType == MACH_MSG_TYPE_MOVE_SEND_ONCE)
|
||||
|
||||
@@ -20,14 +20,12 @@ import System
|
||||
|
||||
final class MachPortTests: XCTestCase {
|
||||
func refCountForMachPortName(name:mach_port_name_t, kind:mach_port_right_t) -> mach_port_urefs_t {
|
||||
var refCount:mach_port_urefs_t = 0
|
||||
withUnsafeMutablePointer(to: &refCount) { refCount in
|
||||
let kr = mach_port_get_refs(mach_task_self_, name, kind, refCount)
|
||||
if kr == KERN_INVALID_NAME {
|
||||
refCount.pointee = 0
|
||||
} else {
|
||||
XCTAssertEqual(kr, KERN_SUCCESS)
|
||||
}
|
||||
var refCount:mach_port_urefs_t = .max
|
||||
let kr = mach_port_get_refs(mach_task_self_, name, kind, &refCount)
|
||||
if kr == KERN_INVALID_NAME {
|
||||
refCount = 0
|
||||
} else {
|
||||
XCTAssertEqual(kr, KERN_SUCCESS)
|
||||
}
|
||||
return refCount
|
||||
}
|
||||
@@ -39,11 +37,9 @@ final class MachPortTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testReceiveRightDeallocation() throws {
|
||||
var name:mach_port_name_t = 0 // Never read
|
||||
withUnsafeMutablePointer(to:&name) { name in
|
||||
let kr = mach_port_allocate(mach_task_self_, MACH_PORT_RIGHT_RECEIVE, name)
|
||||
XCTAssertEqual(kr, KERN_SUCCESS)
|
||||
}
|
||||
var name: mach_port_name_t = 0xFFFFFFFF
|
||||
let kr = mach_port_allocate(mach_task_self_, MACH_PORT_RIGHT_RECEIVE, &name)
|
||||
XCTAssertEqual(kr, KERN_SUCCESS)
|
||||
|
||||
XCTAssertNotEqual(name, 0xFFFFFFFF)
|
||||
|
||||
|
||||
Reference in new issue
Block a user