Skip to content

Commit 9a812b5

Browse files
authored
Merge pull request #147 from glessard/availability
2 parents 11f1c6d + 882466a commit 9a812b5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/System/MachPort.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public enum Mach {
129129
public struct SendOnceRight: MachPortRight {}
130130
}
131131

132+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
132133
extension Mach.Port where RightType == Mach.ReceiveRight {
133134
/// Transfer ownership of an existing, unmanaged, but already guarded,
134135
/// Mach port right into a Mach.Port by name.
@@ -153,6 +154,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
153154
/// This initializer will abort if the right could not be created.
154155
/// Callers may assert that a valid right is always returned.
155156
@inlinable
157+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
156158
public init() {
157159
var storage: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
158160
_machPrecondition(
@@ -175,6 +177,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
175177
/// After this function completes, the Mach.Port is destroyed and no longer
176178
/// usable.
177179
@inlinable
180+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
178181
public consuming func relinquish(
179182
) -> (name: mach_port_name_t, context: mach_port_context_t) {
180183
let destructured = (name: _name, context: _context)
@@ -197,6 +200,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
197200
/// Mach.ReceiveRights. Use relinquish() to avoid the syscall and extract
198201
/// the context value along with the port name.
199202
@inlinable
203+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
200204
public consuming func unguardAndRelinquish() -> mach_port_name_t {
201205
let (name, context) = self.relinquish()
202206
_machPrecondition(mach_port_unguard(mach_task_self_, name, context))
@@ -213,6 +217,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
213217
/// The body block may optionally return something, which will then be
214218
/// returned to the caller of withBorrowedName.
215219
@inlinable
220+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
216221
public func withBorrowedName<ReturnType>(
217222
body: (mach_port_name_t, mach_port_context_t) -> ReturnType
218223
) -> ReturnType {
@@ -226,6 +231,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
226231
/// This function will abort if the right could not be created.
227232
/// Callers may assert that a valid right is always returned.
228233
@inlinable
234+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
229235
public func makeSendOnceRight() -> Mach.Port<Mach.SendOnceRight> {
230236
// send once rights do not coalesce
231237
var newRight: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
@@ -254,6 +260,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
254260
/// This function will abort if the right could not be created.
255261
/// Callers may assert that a valid right is always returned.
256262
@inlinable
263+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
257264
public func makeSendRight() -> Mach.Port<Mach.SendRight> {
258265
let how = MACH_MSG_TYPE_MAKE_SEND
259266

@@ -271,6 +278,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
271278
///
272279
/// Each get/set of this property makes a syscall.
273280
@inlinable
281+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
274282
public var makeSendCount: mach_port_mscount_t {
275283
get {
276284
var status: mach_port_status = mach_port_status()
@@ -299,6 +307,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
299307
}
300308
}
301309

310+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
302311
extension Mach.Port where RightType == Mach.SendRight {
303312
/// Transfer ownership of the underlying port right to the caller.
304313
///
@@ -324,6 +333,7 @@ extension Mach.Port where RightType == Mach.SendRight {
324333
/// receiving side has been deallocated, then copySendRight() will throw
325334
/// a Mach.PortRightError.deadName error.
326335
@inlinable
336+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
327337
public func copySendRight() throws -> Mach.Port<Mach.SendRight> {
328338
let how = MACH_MSG_TYPE_COPY_SEND
329339

@@ -340,7 +350,7 @@ extension Mach.Port where RightType == Mach.SendRight {
340350
}
341351
}
342352

343-
353+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
344354
extension Mach.Port where RightType == Mach.SendOnceRight {
345355
/// Transfer ownership of the underlying port right to the caller.
346356
///
@@ -352,6 +362,7 @@ extension Mach.Port where RightType == Mach.SendOnceRight {
352362
/// After this function completes, the Mach.Port is destroyed and no longer
353363
/// usable.
354364
@inlinable
365+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
355366
public consuming func relinquish() -> mach_port_name_t {
356367
let name = _name
357368
discard self

Tests/SystemTests/MachPortTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import SystemPackage
1818
import System
1919
#endif
2020

21+
@available(/*System 1.3.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
2122
final class MachPortTests: XCTestCase {
2223
func refCountForMachPortName(name:mach_port_name_t, kind:mach_port_right_t) -> mach_port_urefs_t {
2324
var refCount:mach_port_urefs_t = .max

0 commit comments

Comments
 (0)