From 5b1b4cab5698822182010cdf125c4d09e5247eba Mon Sep 17 00:00:00 2001 From: Daniel Loffgren Date: Wed, 10 May 2023 13:52:33 -0700 Subject: [PATCH 1/4] Remove allocatePortRightPair(), as move only types are not permitted in tuples --- Sources/System/MachPort.swift | 18 ------------------ Tests/SystemTests/MachPortTests.swift | 13 ------------- 2 files changed, 31 deletions(-) diff --git a/Sources/System/MachPort.swift b/Sources/System/MachPort.swift index 5615b314..55e3514b 100644 --- a/Sources/System/MachPort.swift +++ b/Sources/System/MachPort.swift @@ -122,24 +122,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, send: Mach.Port) { - 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 { diff --git a/Tests/SystemTests/MachPortTests.swift b/Tests/SystemTests/MachPortTests.swift index 5c119d17..6c22a041 100644 --- a/Tests/SystemTests/MachPortTests.swift +++ b/Tests/SystemTests/MachPortTests.swift @@ -121,19 +121,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() let zero = recv.makeSendCount From 2d6c6a82b3e5158b5c8c320c123c38a97f2e0c98 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 8 Jun 2023 13:51:05 -0700 Subject: [PATCH 2/4] import module correctly in test file --- Tests/SystemTests/MachPortTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/SystemTests/MachPortTests.swift b/Tests/SystemTests/MachPortTests.swift index 6c22a041..49c324e9 100644 --- a/Tests/SystemTests/MachPortTests.swift +++ b/Tests/SystemTests/MachPortTests.swift @@ -12,6 +12,12 @@ 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 From 6bbed6b1991e7f16f6506eeed5e6aa51929048b3 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 8 Jun 2023 14:18:54 -0700 Subject: [PATCH 3/4] update non-copyable type declaration syntax --- Sources/System/MachPort.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/System/MachPort.swift b/Sources/System/MachPort.swift index 55e3514b..64aee276 100644 --- a/Sources/System/MachPort.swift +++ b/Sources/System/MachPort.swift @@ -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 { + public struct Port: ~Copyable { @usableFromInline internal var _name: mach_port_name_t From 7bcc01f0bfff8f33d75bc11fa099e95d3f3204e6 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Fri, 9 Jun 2023 16:46:48 -0700 Subject: [PATCH 4/4] deactivate Mach.Port Will reactivate when the following issue is fixed: https://github.com/apple/swift/issues/66299 (rdar://110496872) --- Sources/System/MachPort.swift | 2 +- Tests/SystemTests/MachPortTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/System/MachPort.swift b/Sources/System/MachPort.swift index 64aee276..04d2cc5b 100644 --- a/Sources/System/MachPort.swift +++ b/Sources/System/MachPort.swift @@ -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 diff --git a/Tests/SystemTests/MachPortTests.swift b/Tests/SystemTests/MachPortTests.swift index 49c324e9..31a654cb 100644 --- a/Tests/SystemTests/MachPortTests.swift +++ b/Tests/SystemTests/MachPortTests.swift @@ -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 XCTest import Darwin.Mach