mirror of
https://github.com/apple/swift-system
synced 2026-11-28 05:14:33 +00:00
simplify deinit
This commit is contained in:
1 parent
d259ef476e
commit
e4d06ae3ea
2 files changed
+24
-10
No files matched your search
@@ -81,17 +81,17 @@ public enum Mach {
|
||||
}
|
||||
|
||||
deinit {
|
||||
if _name == 0xFFFFFFFF /* MACH_PORT_DEAD */ {
|
||||
precondition(RightType.self != ReceiveRight.self, "Receive rights cannot be dead names")
|
||||
_machPrecondition(mach_port_mod_refs(mach_task_self_, _name, MACH_PORT_RIGHT_DEAD_NAME, -1))
|
||||
if RightType.self == ReceiveRight.self {
|
||||
precondition(_name != 0xffffffff, "Receive rights cannot be dead names")
|
||||
_machPrecondition(
|
||||
mach_port_destruct(mach_task_self_, _name, 0, _context)
|
||||
)
|
||||
} else {
|
||||
if RightType.self == ReceiveRight.self {
|
||||
_machPrecondition(mach_port_destruct(mach_task_self_, _name, 0, _context))
|
||||
} else if RightType.self == SendRight.self {
|
||||
_machPrecondition(mach_port_deallocate(mach_task_self_, _name))
|
||||
} else if RightType.self == SendOnceRight.self {
|
||||
_machPrecondition(mach_port_mod_refs(mach_task_self_, _name, MACH_PORT_RIGHT_SEND_ONCE, -1))
|
||||
}
|
||||
assert(
|
||||
RightType.self == SendRight.self ||
|
||||
RightType.self == SendOnceRight.self
|
||||
)
|
||||
_machPrecondition(mach_port_deallocate(mach_task_self_, _name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +210,20 @@ final class MachPortTests: XCTestCase {
|
||||
XCTAssertEqual(context, $1)
|
||||
}
|
||||
}
|
||||
|
||||
func testDeinitDeadSendRight() throws {
|
||||
let send = Mach.Port<Mach.SendRight>(name: 0xffffffff)
|
||||
send.withBorrowedName {
|
||||
XCTAssertEqual($0, .max)
|
||||
}
|
||||
_ = consume send
|
||||
|
||||
let send1 = Mach.Port<Mach.SendOnceRight>(name: 0xffffffff)
|
||||
send1.withBorrowedName {
|
||||
XCTAssertEqual($0, .max)
|
||||
}
|
||||
_ = consume send1
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user