Skip to content

Commit f3ef70b

Browse files
committed
[test] rebind byte types safely
1 parent a77a331 commit f3ef70b

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

Tests/SystemTests/FilePathTests/FilePathTest.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ func filePathFromUnterminatedBytes<S: Sequence>(_ bytes: S) -> FilePath where S.
2222
array += [0]
2323

2424
return array.withUnsafeBufferPointer {
25-
FilePath(platformString: $0.baseAddress!._asCChar)
25+
$0.withMemoryRebound(to: CChar.self) {
26+
FilePath(platformString: $0.baseAddress!)
27+
}
2628
}
2729
}
2830
let invalidBytes: [UInt8] = [0x2F, 0x61, 0x2F, 0x62, 0x2F, 0x83]

Tests/SystemTests/SystemStringTests.swift

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,6 @@
1010
// Tests for PlatformString, SystemString, and FilePath's forwarding APIs
1111

1212
// TODO: Adapt test to Windows
13-
extension UnsafePointer where Pointee == UInt8 {
14-
internal var _asCChar: UnsafePointer<CChar> {
15-
UnsafeRawPointer(self).assumingMemoryBound(to: CChar.self)
16-
}
17-
}
18-
extension UnsafePointer where Pointee == CChar {
19-
internal var _asUInt8: UnsafePointer<UInt8> {
20-
UnsafeRawPointer(self).assumingMemoryBound(to: UInt8.self)
21-
}
22-
}
23-
extension UnsafeBufferPointer where Element == UInt8 {
24-
internal var _asCChar: UnsafeBufferPointer<CChar> {
25-
let base = baseAddress?._asCChar
26-
return UnsafeBufferPointer<CChar>(start: base, count: self.count)
27-
}
28-
}
29-
extension UnsafeBufferPointer where Element == CChar {
30-
internal var _asUInt8: UnsafeBufferPointer<UInt8> {
31-
let base = baseAddress?._asUInt8
32-
return UnsafeBufferPointer<UInt8>(start: base, count: self.count)
33-
}
34-
}
35-
3613

3714
import XCTest
3815

@@ -46,7 +23,7 @@ private func makeRaw(
4623
_ str: String
4724
) -> [CInterop.PlatformChar] {
4825
var str = str
49-
var array = str.withUTF8 { Array($0._asCChar) }
26+
var array = str.withUTF8 { $0.withMemoryRebound(to: CChar.self, Array.init) }
5027
array.append(0)
5128
return array
5229
}

0 commit comments

Comments
 (0)