Skip to content

Commit 0cb6147

Browse files
committed
stdlib: Fix missing unsafe operators in more places.
Add `unsafe` where it is still missing. I missed these in previous passes due to conditional compilation.
1 parent 2add2c8 commit 0cb6147

File tree

10 files changed

+31
-31
lines changed

10 files changed

+31
-31
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension std.string {
2626
// Use the 2 parameter constructor.
2727
// The MSVC standard library has a enable_if template guard
2828
// on the 3 parameter constructor, and thus it's not imported into Swift.
29-
std.string(buffer, string.utf8.count)
29+
unsafe std.string(buffer, string.utf8.count)
3030
#else
3131
unsafe std.string(buffer, string.utf8.count, .init())
3232
#endif
@@ -40,7 +40,7 @@ extension std.string {
4040
// Use the 2 parameter constructor.
4141
// The MSVC standard library has a enable_if template guard
4242
// on the 3 parameter constructor, and thus it's not imported into Swift.
43-
self.init(str, UTF8._nullCodeUnitOffset(in: str))
43+
unsafe self.init(str, UTF8._nullCodeUnitOffset(in: str))
4444
#else
4545
unsafe self.init(str, UTF8._nullCodeUnitOffset(in: str), .init())
4646
#endif

stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ fileprivate class _Lock {
255255
unsafe self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
256256
unsafe self.underlying.initialize(to: os_unfair_lock())
257257
#elseif os(Windows)
258-
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
259-
InitializeSRWLock(self.underlying)
258+
unsafe self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
259+
unsafe InitializeSRWLock(self.underlying)
260260
#elseif os(WASI)
261261
// WASI environment has only a single thread
262262
#else
263-
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
263+
unsafe self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
264264
guard unsafe pthread_mutex_init(self.underlying, nil) == 0 else {
265265
fatalError("pthread_mutex_init failed")
266266
}

stdlib/public/Synchronization/Mutex/LinuxImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ extension Atomic where Value == UInt32 {
2323
// This returns 'false' on success and 'true' on error. Check 'errno' for the
2424
// specific error value.
2525
internal borrowing func _futexLock() -> UInt32 {
26-
_swift_stdlib_futex_lock(.init(_rawAddress))
26+
unsafe _swift_stdlib_futex_lock(.init(_rawAddress))
2727
}
2828

2929
// This returns 'false' on success and 'true' on error. Check 'errno' for the
3030
// specific error value.
3131
internal borrowing func _futexTryLock() -> UInt32 {
32-
_swift_stdlib_futex_trylock(.init(_rawAddress))
32+
unsafe _swift_stdlib_futex_trylock(.init(_rawAddress))
3333
}
3434

3535
// This returns 'false' on success and 'true' on error. Check 'errno' for the
3636
// specific error value.
3737
internal borrowing func _futexUnlock() -> UInt32 {
38-
_swift_stdlib_futex_unlock(.init(_rawAddress))
38+
unsafe _swift_stdlib_futex_unlock(.init(_rawAddress))
3939
}
4040
}
4141

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,19 +716,19 @@ public func swift_unboxFromSwiftValueWithType<T>(
716716

717717
if source === _nullPlaceholder {
718718
if let unpacked = Optional<Any>.none as? T {
719-
result.initialize(to: unpacked)
719+
unsafe result.initialize(to: unpacked)
720720
return true
721721
}
722722
}
723723

724724
if let box = source as? __SwiftValue {
725725
if let value = box.value as? T {
726-
result.initialize(to: value)
726+
unsafe result.initialize(to: value)
727727
return true
728728
}
729729
} else if let box = source as? _NSSwiftValue {
730730
if let value = box.value as? T {
731-
result.initialize(to: value)
731+
unsafe result.initialize(to: value)
732732
return true
733733
}
734734
}
@@ -819,7 +819,7 @@ public func _bridgeAnythingToObjectiveC<T>(_ x: T) -> AnyObject {
819819

820820
if !done {
821821
if type(of: source) as? AnyClass != nil {
822-
result = unsafeBitCast(x, to: AnyObject.self)
822+
result = unsafe unsafeBitCast(x, to: AnyObject.self)
823823
} else if let object = _bridgeToObjectiveCUsingProtocolIfPossible(source) {
824824
result = object
825825
} else {

stdlib/public/core/CTypes.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,19 @@ public struct CVaListPointer {
314314
__vr_top: UnsafeMutablePointer<Int>?,
315315
__gr_off: Int32,
316316
__vr_off: Int32) {
317-
_value = (__stack, __gr_top, __vr_top, __gr_off, __vr_off)
317+
unsafe _value = (__stack, __gr_top, __vr_top, __gr_off, __vr_off)
318318
}
319319
}
320320

321321
@_unavailableInEmbedded
322322
extension CVaListPointer: CustomDebugStringConvertible {
323323
@safe
324324
public var debugDescription: String {
325-
return "(\(_value.__stack.debugDescription), " +
326-
"\(_value.__gr_top.debugDescription), " +
327-
"\(_value.__vr_top.debugDescription), " +
328-
"\(_value.__gr_off), " +
329-
"\(_value.__vr_off))"
325+
return "(\(unsafe _value.__stack.debugDescription), " +
326+
"\(unsafe _value.__gr_top.debugDescription), " +
327+
"\(unsafe _value.__vr_top.debugDescription), " +
328+
"\(unsafe _value.__gr_off), " +
329+
"\(unsafe _value.__vr_off))"
330330
}
331331
}
332332

stdlib/public/core/Int128.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct Int128: Sendable {
7676
public var _value: Builtin.Int128 {
7777
@_transparent
7878
get {
79-
unsafeBitCast(self, to: Builtin.Int128.self)
79+
unsafe unsafeBitCast(self, to: Builtin.Int128.self)
8080
}
8181

8282
@_transparent
@@ -88,7 +88,7 @@ public struct Int128: Sendable {
8888
@available(SwiftStdlib 6.0, *)
8989
@_transparent
9090
public init(_ _value: Builtin.Int128) {
91-
self = unsafeBitCast(_value, to: Self.self)
91+
self = unsafe unsafeBitCast(_value, to: Self.self)
9292
}
9393
#endif
9494

stdlib/public/core/KeyPath.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public class AnyKeyPath: _AppendKeyPath {
8080
unsafe _kvcKeyPathStringPtr = UnsafePointer<CChar>(bitPattern: -offset - 1)
8181
#elseif _pointerBitWidth(_32)
8282
if offset <= maximumOffsetOn32BitArchitecture {
83-
_kvcKeyPathStringPtr = UnsafePointer<CChar>(bitPattern: (offset + 1))
83+
unsafe _kvcKeyPathStringPtr = UnsafePointer<CChar>(bitPattern: (offset + 1))
8484
} else {
85-
_kvcKeyPathStringPtr = nil
85+
unsafe _kvcKeyPathStringPtr = nil
8686
}
8787
#else
8888
// Don't assign anything.
@@ -104,7 +104,7 @@ public class AnyKeyPath: _AppendKeyPath {
104104
}
105105
return offset
106106
#elseif _pointerBitWidth(_32)
107-
let offset = Int(bitPattern: _kvcKeyPathStringPtr) &- 1
107+
let offset = Int(bitPattern: unsafe _kvcKeyPathStringPtr) &- 1
108108
// Pointers above 0x7fffffff will come in as negative numbers which are
109109
// less than maximumOffsetOn32BitArchitecture, be sure to reject them.
110110
if offset >= 0, offset <= maximumOffsetOn32BitArchitecture {
@@ -4152,7 +4152,7 @@ internal func _instantiateKeyPathBuffer(
41524152
var walker = unsafe ValidatingInstantiateKeyPathBuffer(sizeVisitor: sizeWalker,
41534153
instantiateVisitor: instantiateWalker)
41544154
#else
4155-
var walker = InstantiateKeyPathBuffer(
4155+
var walker = unsafe InstantiateKeyPathBuffer(
41564156
destData: destData,
41574157
patternArgs: arguments,
41584158
root: rootType)
@@ -4165,8 +4165,8 @@ internal func _instantiateKeyPathBuffer(
41654165
let endOfReferencePrefixComponent =
41664166
unsafe walker.instantiateVisitor.endOfReferencePrefixComponent
41674167
#else
4168-
let isTrivial = walker.isTrivial
4169-
let endOfReferencePrefixComponent = walker.endOfReferencePrefixComponent
4168+
let isTrivial = unsafe walker.isTrivial
4169+
let endOfReferencePrefixComponent = unsafe walker.endOfReferencePrefixComponent
41704170
#endif
41714171

41724172
// Write out the header.

stdlib/public/core/StringObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ extension _StringObject {
12441244
discriminator: Nibbles.largeImmortal(),
12451245
countAndFlags: countAndFlags)
12461246
#elseif _pointerBitWidth(_32) || _pointerBitWidth(_16)
1247-
self.init(
1247+
unsafe self.init(
12481248
variant: .immortal(start: bufPtr.baseAddress._unsafelyUnwrappedUnchecked),
12491249
discriminator: Nibbles.largeImmortal(),
12501250
countAndFlags: countAndFlags)

stdlib/public/core/UInt128.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public struct UInt128: Sendable {
4747
#if _endian(little)
4848
self = unsafe unsafeBitCast((_low, _high), to: Self.self)
4949
#else
50-
self = unsafeBitCast((_high, _low), to: Self.self)
50+
self = unsafe unsafeBitCast((_high, _low), to: Self.self)
5151
#endif
5252
}
5353

@@ -76,7 +76,7 @@ public struct UInt128: Sendable {
7676
public var _value: Builtin.Int128 {
7777
@_transparent
7878
get {
79-
unsafeBitCast(self, to: Builtin.Int128.self)
79+
unsafe unsafeBitCast(self, to: Builtin.Int128.self)
8080
}
8181

8282
@_transparent
@@ -88,7 +88,7 @@ public struct UInt128: Sendable {
8888
@available(SwiftStdlib 6.0, *)
8989
@_transparent
9090
public init(_ _value: Builtin.Int128) {
91-
self = unsafeBitCast(_value, to: Self.self)
91+
self = unsafe unsafeBitCast(_value, to: Self.self)
9292
}
9393
#endif
9494

stdlib/public/core/VarArgs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ final internal class __VaListBuilder {
609609
// We may need to retain an object that provides a pointer value.
610610
if let obj = arg as? _CVarArgObject {
611611
arg = obj._cVarArgObject
612-
retainer.append(arg)
612+
unsafe retainer.append(arg)
613613
}
614614
#endif
615615

0 commit comments

Comments
 (0)