mirror of
https://github.com/apple/swift-system
synced 2026-11-25 04:47:55 +00:00
Merge pull request #127 from loffgren/no-tuple-api
This commit is contained in:
2 files changed
+9
-35
No files matched your search
@@ -7,7 +7,7 @@
|
||||
See https://swift.org/LICENSE.txt for license information
|
||||
*/
|
||||
|
||||
#if swift(>=5.8) && $MoveOnly && (os(macOS) || os(iOS) || os(watchOS) || os(tvOS))
|
||||
#if false && swift(>=5.8) && $MoveOnly && (os(macOS) || os(iOS) || os(watchOS) || os(tvOS))
|
||||
|
||||
import Darwin.Mach
|
||||
|
||||
@@ -27,8 +27,7 @@ internal func _machPrecondition(
|
||||
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
||||
@frozen
|
||||
public enum Mach {
|
||||
@_moveOnly
|
||||
public struct Port<RightType: MachPortRight> {
|
||||
public struct Port<RightType: MachPortRight>: ~Copyable {
|
||||
@usableFromInline
|
||||
internal var _name: mach_port_name_t
|
||||
|
||||
@@ -122,24 +121,6 @@ public enum Mach {
|
||||
/// receiving end.
|
||||
@frozen
|
||||
public struct SendOnceRight: MachPortRight {}
|
||||
|
||||
/// Create a connected pair of rights, one receive, and one send.
|
||||
///
|
||||
/// This function will abort if the rights could not be created.
|
||||
/// Callers may assert that valid rights are always returned.
|
||||
public static func allocatePortRightPair() ->
|
||||
(receive: Mach.Port<Mach.ReceiveRight>, send: Mach.Port<Mach.SendRight>) {
|
||||
var name = mach_port_name_t(MACH_PORT_NULL)
|
||||
let secret = mach_port_context_t(arc4random())
|
||||
withUnsafeMutablePointer(to: &name) { name in
|
||||
var options = mach_port_options_t()
|
||||
options.flags = UInt32(MPO_INSERT_SEND_RIGHT);
|
||||
withUnsafeMutablePointer(to: &options) { options in
|
||||
_machPrecondition(mach_port_construct(mach_task_self_, options, secret, name))
|
||||
}
|
||||
}
|
||||
return (Mach.Port(name: name, context: secret), Mach.Port(name: name))
|
||||
}
|
||||
}
|
||||
|
||||
extension Mach.Port where RightType == Mach.ReceiveRight {
|
||||
|
||||
@@ -7,11 +7,17 @@
|
||||
See https://swift.org/LICENSE.txt for license information
|
||||
*/
|
||||
|
||||
#if swift(>=5.8) && $MoveOnly && (os(macOS) || os(iOS) || os(watchOS) || os(tvOS))
|
||||
#if false && swift(>=5.8) && $MoveOnly && (os(macOS) || os(iOS) || os(watchOS) || os(tvOS))
|
||||
|
||||
import XCTest
|
||||
import Darwin.Mach
|
||||
|
||||
#if SYSTEM_PACKAGE
|
||||
import SystemPackage
|
||||
#else
|
||||
import System
|
||||
#endif
|
||||
|
||||
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
|
||||
@@ -121,19 +127,6 @@ final class MachPortTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testMakePair() throws {
|
||||
let (recv, send) = Mach.allocatePortRightPair()
|
||||
XCTAssert(recv.makeSendCount == 1)
|
||||
recv.withBorrowedName { rName in
|
||||
send.withBorrowedName { sName in
|
||||
XCTAssert(rName != 0xFFFFFFFF)
|
||||
XCTAssert(rName != MACH_PORT_NULL)
|
||||
// send and recv port names coalesce
|
||||
XCTAssert(rName == sName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testCopySend() throws {
|
||||
let recv = Mach.Port<Mach.ReceiveRight>()
|
||||
let zero = recv.makeSendCount
|
||||
|
||||
Reference in new issue
Block a user