Skip to content

Commit a4eaaca

Browse files
committed
Speculative update for UnsafeRawPointer.
Update for SE-0107: UnsafeRawPointer. This is speculative because I haven't been able to build playgroundlogger with the fixes yet.
1 parent 75784aa commit a4eaaca

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

PlaygroundLogger/PlaygroundLogger/BytesStorage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ final class BytesStorage {
1818
var index: Int
1919

2020
init(_ _bytes: NSData) {
21-
data = _bytes
22-
bytes = UnsafeMutablePointer(data.bytes.bindMemory(to: UInt8.self, capacity: data.length))
23-
index = 0
21+
data = _bytes
22+
bytes = UnsafeMutablePointer(mutating: data.bytes.bindMemory(to: UInt8.self, capacity: data.length))
23+
index = 0
2424
}
2525

2626
func get() -> UInt8 {

PlaygroundLogger/PlaygroundLogger/ExtensionDouble.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ extension Double : Serializable {
1616
var udPtr = UnsafeMutablePointer<Double>.allocate(capacity: 1)
1717
defer { udPtr.deallocate(capacity: 1) }
1818
udPtr.pointee = self
19-
let ubPtr = UnsafeMutablePointer<UInt8>(udPtr)
19+
let ubPtr = UnsafeMutableRawPointer(udPtr)
2020
var arr = Array<UInt8>(repeating: 0, count: 8)
2121
8.doFor {
22-
arr[$0] = ubPtr[$0]
22+
arr[$0] = ubPtr.load(fromByteOffset: $0, as: UInt8.self)
2323
}
2424
return arr
2525
}
@@ -31,7 +31,8 @@ extension Double : Serializable {
3131
8.doFor {
3232
ubPtr[$0] = storage.get()
3333
}
34-
let udPtr = UnsafeMutablePointer<Double>(ubPtr)
34+
let udPtr = UnsafeMutableRawPointer(ubPtr).bindMemory(
35+
to: Double.self, capacity: 1)
3536
self = udPtr.pointee
3637
}
3738

PlaygroundLogger/PlaygroundLogger/ExtensionFloat.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ extension Float : Serializable {
1616
var udPtr = UnsafeMutablePointer<Float>.allocate(capacity: 1)
1717
defer { udPtr.deallocate(capacity: 1) }
1818
udPtr.pointee = self
19-
let ubPtr = UnsafeMutablePointer<UInt8>(udPtr)
19+
let ubPtr = UnsafeMutableRawPointer(udPtr)
2020
var arr = Array<UInt8>(repeating: 0, count: 4)
2121
4.doFor {
22-
arr[$0] = ubPtr[$0]
22+
arr[$0] = ubPtr.load(fromByteOffset: $0, as: UInt8.self)
2323
}
2424
return arr
2525
}
@@ -31,7 +31,8 @@ extension Float : Serializable {
3131
4.doFor {
3232
ubPtr[$0] = storage.get()
3333
}
34-
let udPtr = UnsafeMutablePointer<Float>(ubPtr)
34+
let udPtr = UnsafeMutableRawPointer(ubPtr).bindMemory(
35+
to: Float.self, capacity: 1)
3536
self = udPtr.pointee
3637
}
3738

PlaygroundLogger/PlaygroundLogger/ExtensionUInt64.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ extension UInt64 : Serializable {
2323
var up_int = UnsafeMutablePointer<UInt64>.allocate(capacity: 1)
2424
defer { up_int.deallocate(capacity: 1) }
2525
up_int.pointee = self
26-
var up_byte: UnsafePointer<UInt8> = UnsafePointer(up_int)
26+
var up_byte = UnsafeRawPointer(up_int)
2727
8.doFor {
28-
ret.append(up_byte.pointee)
28+
ret.append(up_byte.load(as: UInt8.self))
2929
up_byte = up_byte.successor()
3030
}
3131
return ret
@@ -36,9 +36,9 @@ extension UInt64 : Serializable {
3636
var up_int = UnsafeMutablePointer<UInt64>.allocate(capacity: 1)
3737
defer { up_int.deallocate(capacity: 1) }
3838
up_int.pointee = self
39-
var up_byte: UnsafePointer<UInt8> = UnsafePointer(up_int)
39+
var up_byte = UnsafeRawPointer(up_int)
4040
8.doFor {
41-
ret.append(up_byte.pointee)
41+
ret.append(up_byte.load(as: UInt8.self))
4242
up_byte = up_byte.successor()
4343
}
4444
return ret
@@ -64,7 +64,8 @@ extension UInt64 : Serializable {
6464
8.doFor {
6565
up_byte[$0] = eightBytesStorage.get()
6666
}
67-
let up_int: UnsafePointer<UInt64> = UnsafePointer(up_byte)
67+
let up_int: UnsafePointer<UInt64> = UnsafeRawPointer(up_byte).bindMemory(
68+
to: UInt64.self, capacity: 1)
6869
self = up_int.pointee
6970
}
7071
}

0 commit comments

Comments
 (0)