Skip to content

Commit 3750b96

Browse files
committed
name and context should have leading underscores
1 parent 12baba9 commit 3750b96

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

Sources/System/MachPort.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ private func _machPrecondition(
2626
public enum Mach {
2727
@_moveOnly
2828
public struct Port<RightType: MachPortRight> {
29-
internal var name: mach_port_name_t
30-
internal var context: mach_port_context_t
29+
internal var _name: mach_port_name_t
30+
internal var _context: mach_port_context_t
3131

3232
/// Transfer ownership of an existing unmanaged Mach port right into a
3333
/// `Mach.Port` by name.
@@ -44,17 +44,17 @@ public enum Mach {
4444
/// This initializer makes a syscall to guard the right.
4545
public init(name: mach_port_name_t) {
4646
precondition(name != mach_port_name_t(MACH_PORT_NULL), "Mach.Port cannot be initialized with MACH_PORT_NULL")
47-
self.name = name
47+
self._name = name
4848

4949
if RightType.self == ReceiveRight.self {
5050
precondition(name != 0xFFFFFFFF /* MACH_PORT_DEAD */, "Receive rights cannot be dead names")
5151

5252
let secret = mach_port_context_t(arc4random())
5353
_machPrecondition(mach_port_guard(mach_task_self_, name, secret, 0))
54-
self.context = secret
54+
self._context = secret
5555
}
5656
else {
57-
self.context = 0
57+
self._context = 0
5858
}
5959
}
6060

@@ -69,20 +69,20 @@ public enum Mach {
6969
/// The body block may optionally return something, which will then be
7070
/// returned to the caller of withBorrowedName.
7171
public func withBorrowedName<ReturnType>(body: (mach_port_name_t) -> ReturnType) -> ReturnType {
72-
return body(name)
72+
return body(_name)
7373
}
7474

7575
deinit {
76-
if name == 0xFFFFFFFF /* MACH_PORT_DEAD */ {
76+
if _name == 0xFFFFFFFF /* MACH_PORT_DEAD */ {
7777
precondition(RightType.self != ReceiveRight.self, "Receive rights cannot be dead names")
78-
_machPrecondition(mach_port_mod_refs(mach_task_self_, name, MACH_PORT_RIGHT_DEAD_NAME, -1))
78+
_machPrecondition(mach_port_mod_refs(mach_task_self_, _name, MACH_PORT_RIGHT_DEAD_NAME, -1))
7979
} else {
8080
if RightType.self == ReceiveRight.self {
81-
_machPrecondition(mach_port_destruct(mach_task_self_, name, -1, context))
81+
_machPrecondition(mach_port_destruct(mach_task_self_, _name, -1, _context))
8282
} else if RightType.self == SendRight.self {
83-
_machPrecondition(mach_port_mod_refs(mach_task_self_, name, MACH_PORT_RIGHT_SEND, -1))
83+
_machPrecondition(mach_port_mod_refs(mach_task_self_, _name, MACH_PORT_RIGHT_SEND, -1))
8484
} else if RightType.self == SendOnceRight.self {
85-
_machPrecondition(mach_port_mod_refs(mach_task_self_, name, MACH_PORT_RIGHT_SEND_ONCE, -1))
85+
_machPrecondition(mach_port_mod_refs(mach_task_self_, _name, MACH_PORT_RIGHT_SEND_ONCE, -1))
8686
}
8787
}
8888
}
@@ -141,8 +141,8 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
141141
/// The underlying port right will be automatically deallocated when
142142
/// the Mach.Port object is destroyed.
143143
init(name: mach_port_name_t, context: mach_port_context_t) {
144-
self.name = name
145-
self.context = context
144+
self._name = name
145+
self._context = context
146146
}
147147

148148
/// Allocate a new Mach port with a receive right, creating a
@@ -172,7 +172,7 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
172172
/// After this function completes, the Mach.Port is destroyed and no longer
173173
/// usable.
174174
__consuming func relinquish() -> (name: mach_port_name_t, context: mach_port_context_t) {
175-
return (name: name, context: context)
175+
return (name: _name, context: _context)
176176
}
177177

178178
/// Remove guard and transfer ownership of the underlying port right to
@@ -190,8 +190,8 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
190190
/// Mach.ReceiveRights. Use relinquish() to avoid the syscall and extract
191191
/// the context value along with the port name.
192192
__consuming func unguardAndRelinquish() -> mach_port_name_t {
193-
_machPrecondition(mach_port_unguard(mach_task_self_, name, context))
194-
return name
193+
_machPrecondition(mach_port_unguard(mach_task_self_, _name, _context))
194+
return _name
195195
}
196196

197197
/// Borrow access to the port name in a block that can perform
@@ -204,7 +204,7 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
204204
/// The body block may optionally return something, which will then be
205205
/// returned to the caller of withBorrowedName.
206206
func withBorrowedName<ReturnType>(body: (mach_port_name_t, mach_port_context_t) -> ReturnType) -> ReturnType {
207-
body(name, context)
207+
body(_name, _context)
208208
}
209209

210210
/// Create a send-once right for a given receive right.
@@ -222,7 +222,7 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
222222
withUnsafeMutablePointer(to: &newRightType) { newRightType in
223223
_machPrecondition(
224224
mach_port_extract_right(mach_task_self_,
225-
name,
225+
_name,
226226
mach_msg_type_name_t(MACH_MSG_TYPE_MAKE_SEND_ONCE),
227227
newRight,
228228
newRightType)
@@ -246,9 +246,9 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
246246
let how = MACH_MSG_TYPE_MAKE_SEND
247247

248248
// name is the same because send and recv rights are coalesced
249-
_machPrecondition(mach_port_insert_right(mach_task_self_, name, name, mach_msg_type_name_t(how)))
249+
_machPrecondition(mach_port_insert_right(mach_task_self_, _name, _name, mach_msg_type_name_t(how)))
250250

251-
return Mach.Port(name: name)
251+
return Mach.Port(name: _name)
252252
}
253253

254254
/// Access the make-send count.
@@ -261,14 +261,14 @@ public extension Mach.Port where RightType == Mach.ReceiveRight {
261261
withUnsafeMutablePointer(to: &size) { size in
262262
withUnsafeMutablePointer(to: &status) { status in
263263
let info = UnsafeMutableRawPointer(status).bindMemory(to: integer_t.self, capacity: 1)
264-
_machPrecondition(mach_port_get_attributes(mach_task_self_, name, MACH_PORT_RECEIVE_STATUS, info, size))
264+
_machPrecondition(mach_port_get_attributes(mach_task_self_, _name, MACH_PORT_RECEIVE_STATUS, info, size))
265265
}
266266
}
267267
return status.mps_mscount
268268
}
269269

270270
set {
271-
_machPrecondition(mach_port_set_mscount(mach_task_self_, name, newValue))
271+
_machPrecondition(mach_port_set_mscount(mach_task_self_, _name, newValue))
272272
}
273273
}
274274
}
@@ -284,7 +284,7 @@ public extension Mach.Port where RightType == Mach.SendRight {
284284
/// After this function completes, the Mach.Port is destroyed and no longer
285285
/// usable.
286286
__consuming func relinquish() -> mach_port_name_t {
287-
return name
287+
return _name
288288
}
289289

290290
/// Create another send right from a given send right.
@@ -298,13 +298,13 @@ public extension Mach.Port where RightType == Mach.SendRight {
298298
let how = MACH_MSG_TYPE_COPY_SEND
299299

300300
// name is the same because send rights are coalesced
301-
let kr = mach_port_insert_right(mach_task_self_, name, name, mach_msg_type_name_t(how))
301+
let kr = mach_port_insert_right(mach_task_self_, _name, _name, mach_msg_type_name_t(how))
302302
if kr == KERN_INVALID_CAPABILITY {
303303
throw Mach.PortRightError.deadName
304304
}
305305
_machPrecondition(kr)
306306

307-
return Mach.Port(name: name)
307+
return Mach.Port(name: _name)
308308
}
309309
}
310310

@@ -320,7 +320,7 @@ public extension Mach.Port where RightType == Mach.SendOnceRight {
320320
/// After this function completes, the Mach.Port is destroyed and no longer
321321
/// usable.
322322
__consuming func relinquish() -> mach_port_name_t {
323-
return name
323+
return _name
324324
}
325325
}
326326

0 commit comments

Comments
 (0)