mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer This adds a "mutating" initialize to UnsafePointer to make Immutable -> Mutable conversions explicit. These are quick fixes to stdlib, overlays, and test cases that are necessary in order to remove arbitrary UnsafePointer conversions. Many cases can be expressed better up by reworking the surrounding code, but we first need a working starting point.
This commit is contained in:
@@ -314,7 +314,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
|
||||
_mapUnmanaged { $0.getBytes(pointer, length: count) }
|
||||
}
|
||||
|
||||
private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: NSRange) {
|
||||
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: NSRange) {
|
||||
_mapUnmanaged { $0.getBytes(pointer, range: range) }
|
||||
}
|
||||
|
||||
@@ -355,8 +355,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
|
||||
guard !copyRange.isEmpty else { return 0 }
|
||||
|
||||
let nsRange = NSMakeRange(copyRange.lowerBound, copyRange.upperBound - copyRange.lowerBound)
|
||||
let pointer : UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer.baseAddress!)
|
||||
_copyBytesHelper(to: pointer, from: nsRange)
|
||||
_copyBytesHelper(to: buffer.baseAddress!, from: nsRange)
|
||||
return copyRange.count
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user