mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] Make UnsafePointer conversions explicit
Previously, it was possible to write Unsafe[Mutable]Pointer(x) and have Swift deduce the pointee type based on context. Since reinterpreting memory is a fundamentally type-unsafe operation, it's better to be explicit about conversions from Unsafe[Mutable]Pointer<T> to Unsafe[Mutable]Pointer<U>. This change is consistent with the move from reinterpretCast(x) to unsafeBitCast(x, T.self). Also, we've encoded the operations of explicitly adding or removing mutability as properties, so that adding mutability can be separated from wild reinterpretCast'ing, a much more severe form of unsafety. Swift SVN r21324
This commit is contained in:
@@ -33,8 +33,8 @@ func repr(x: _StringCore) -> String {
|
||||
if x.hasContiguousStorage {
|
||||
if let b = x.nativeBuffer {
|
||||
var offset = x.elementWidth == 2
|
||||
? UnsafeMutablePointer(b.start) - x.startUTF16
|
||||
: UnsafeMutablePointer(b.start) - x.startASCII
|
||||
? b.start.asPointerTo(UTF16.CodeUnit.self) - x.startUTF16
|
||||
: b.start.asPointerTo(UTF8.CodeUnit.self) - x.startASCII
|
||||
return "Contiguous(owner: "
|
||||
+ "\(hexAddr(x._owner))[\(offset)...\(x.count + offset)]"
|
||||
+ ", capacity = \(b.capacity))"
|
||||
|
||||
Reference in New Issue
Block a user