mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Switch a bunch of UnsafePointer<T>'s over to T*
Swift SVN r18220
This commit is contained in:
@@ -165,8 +165,8 @@ extension ArrayBuffer {
|
||||
/// starting at target. Return a pointer past-the-end of the
|
||||
/// just-initialized memory.
|
||||
func _uninitializedCopy(
|
||||
subRange: Range<Int>, target: UnsafePointer<T>
|
||||
) -> UnsafePointer<T> {
|
||||
subRange: Range<Int>, target: T*
|
||||
) -> T* {
|
||||
if _fastPath(_isNative) {
|
||||
return _native._uninitializedCopy(subRange, target: target)
|
||||
}
|
||||
@@ -225,7 +225,7 @@ extension ArrayBuffer {
|
||||
|
||||
/// If the elements are stored contiguously, a pointer to the first
|
||||
/// element. Otherwise, nil.
|
||||
var elementStorage: UnsafePointer<T> {
|
||||
var elementStorage: T* {
|
||||
if (_fastPath(_isNative)) {
|
||||
return _native.elementStorage
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ extension Array {
|
||||
count: Builtin.Word
|
||||
) -> Array {
|
||||
let elements = UnsafeArray(
|
||||
start: reinterpretCast(base) as UnsafePointer<T>,
|
||||
start: reinterpretCast(base) as T*,
|
||||
length: reinterpretCast(count) as Int
|
||||
)
|
||||
let r = Array(elements)
|
||||
@@ -556,7 +556,7 @@ func _arrayOutOfPlaceUpdate<
|
||||
}
|
||||
|
||||
struct InitializePointer<T> : PointerFunction {
|
||||
func call(rawMemory: UnsafePointer<T>) {
|
||||
func call(rawMemory: T*) {
|
||||
// FIXME: maybe we should move here instead of copying?
|
||||
rawMemory.initialize(newValue)
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ var _nilRawPointer: Builtin.RawPointer {
|
||||
/// lvalue),
|
||||
/// - an inout argument of the Array<T> type, which gets passed as a pointer
|
||||
/// to the beginning of the array,
|
||||
/// - an UnsafePointer<T>, which is passed as-is.
|
||||
/// - an T*, which is passed as-is.
|
||||
///
|
||||
/// The value consists of an owner-value pair. During bridging, a strong
|
||||
/// reference to the owner is held for the duration of the call, and the pointer
|
||||
@@ -212,7 +212,7 @@ struct CMutablePointer<T> : Equatable {
|
||||
|
||||
/// Make the pointer available as an UnsafePointer within a closure.
|
||||
@transparent
|
||||
func withUnsafePointer<U>(f: UnsafePointer<T> -> U) -> U {
|
||||
func withUnsafePointer<U>(f: T* -> U) -> U {
|
||||
let result = f(UnsafePointer<T>(value))
|
||||
// Ensure the owner pointer stays alive for the duration of the closure.
|
||||
_fixLifetime(owner)
|
||||
@@ -247,7 +247,7 @@ func == <T> (lhs: CConstPointer<T>, rhs: CMutablePointer<T>) -> Bool {
|
||||
/// lvalue),
|
||||
/// - an inout argument of Array<T> type for any T, which gets passed as a
|
||||
/// pointer to the beginning of the array,
|
||||
/// - an UnsafePointer<T> for any T or COpaquePointer, which is passed as-is.
|
||||
/// - an T* for any T or COpaquePointer, which is passed as-is.
|
||||
///
|
||||
/// The value consists of an owner-value pair. During bridging, a strong
|
||||
/// reference to the owner is held for the duration of the call, and the pointer
|
||||
@@ -293,7 +293,7 @@ struct CMutableVoidPointer : Equatable {
|
||||
|
||||
/// Make the pointer available as an UnsafePointer within a closure.
|
||||
@transparent
|
||||
func withUnsafePointer<T, U>(f: UnsafePointer<T> -> U) -> U {
|
||||
func withUnsafePointer<T, U>(f: T* -> U) -> U {
|
||||
let result = f(UnsafePointer(value))
|
||||
// Ensure the owner pointer stays alive for the duration of the closure.
|
||||
_fixLifetime(owner)
|
||||
@@ -314,10 +314,10 @@ func == (lhs: CMutableVoidPointer, rhs: CMutableVoidPointer) -> Bool {
|
||||
/// - 'nil', which gets passed as a null pointer,
|
||||
/// - an inout argument of the referenced type, which gets passed as a pointer
|
||||
/// to a writeback temporary with autoreleasing ownership semantics,
|
||||
/// - an UnsafePointer<T>, which is passed as-is.
|
||||
/// - an T*, which is passed as-is.
|
||||
///
|
||||
/// Unlike CMutablePointer, passing pointers to mutable arrays of ObjC class
|
||||
/// pointers is not directly supported. Unlike UnsafePointer<T>,
|
||||
/// pointers is not directly supported. Unlike T*,
|
||||
/// ObjCMutablePointer must reference storage that does not own a reference
|
||||
/// count to the referenced value. UnsafePointer's operations, by contrast,
|
||||
/// assume that the referenced storage owns values loaded from or stored to it.
|
||||
@@ -363,7 +363,7 @@ struct ObjCMutablePointer<T /* TODO : class */> : Equatable {
|
||||
|
||||
@transparent
|
||||
func isNull() -> Bool {
|
||||
return UnsafePointer<T>(self).isNull()
|
||||
return (T*(self)).isNull()
|
||||
}
|
||||
|
||||
/// Access the underlying raw memory, getting and
|
||||
@@ -373,7 +373,7 @@ struct ObjCMutablePointer<T /* TODO : class */> : Equatable {
|
||||
@transparent get {
|
||||
_debugPrecondition(!isNull())
|
||||
// We can do a strong load normally.
|
||||
return UnsafePointer<T>(self).pointee
|
||||
return (T*(self)).pointee
|
||||
}
|
||||
/// Set the value the pointer points to, copying over the previous value.
|
||||
///
|
||||
@@ -446,7 +446,7 @@ struct CConstPointer<T> : Equatable {
|
||||
|
||||
/// Make the pointer available as an UnsafePointer within a closure.
|
||||
@transparent
|
||||
func withUnsafePointer<U>(f: UnsafePointer<T> -> U) -> U {
|
||||
func withUnsafePointer<U>(f: T* -> U) -> U {
|
||||
let result = f(UnsafePointer<T>(value))
|
||||
// Ensure the owner pointer stays alive for the duration of the closure.
|
||||
_fixLifetime(owner)
|
||||
@@ -488,7 +488,7 @@ struct CConstVoidPointer : Equatable {
|
||||
|
||||
/// Make the pointer available as an UnsafePointer within a closure.
|
||||
@transparent
|
||||
func withUnsafePointer<T, U>(f: UnsafePointer<T> -> U) -> U {
|
||||
func withUnsafePointer<T, U>(f: T* -> U) -> U {
|
||||
let result = f(UnsafePointer(value))
|
||||
// Ensure the owner pointer stays alive for the duration of the closure.
|
||||
_fixLifetime(owner)
|
||||
@@ -550,7 +550,7 @@ extension COpaquePointer {
|
||||
|
||||
@transparent
|
||||
func _convertCConstPointerToUnsafePointer<T>(p: CConstPointer<T>)
|
||||
-> UnsafePointer<T> {
|
||||
-> T* {
|
||||
return UnsafePointer(p.value)
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ func _convertCConstVoidPointerToCOpaquePointer(p: CConstVoidPointer)
|
||||
|
||||
@transparent
|
||||
func _convertCMutablePointerToUnsafePointer<T>(p: CMutablePointer<T>)
|
||||
-> UnsafePointer<T> {
|
||||
-> T* {
|
||||
return UnsafePointer(p.value)
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ func _convertCMutableVoidPointerToCOpaquePointer(p: CMutableVoidPointer)
|
||||
|
||||
@transparent
|
||||
func _convertObjCMutablePointerToUnsafePointer<T>(p: ObjCMutablePointer<T>)
|
||||
-> UnsafePointer<T> {
|
||||
-> T* {
|
||||
return UnsafePointer(p.value)
|
||||
}
|
||||
|
||||
@@ -588,7 +588,7 @@ func _convertObjCMutablePointerToUnsafePointer<T>(p: ObjCMutablePointer<T>)
|
||||
// the arguments to C*Pointer types with nil owner references.
|
||||
|
||||
@transparent
|
||||
func _convertUnsafePointerToCConstPointer<T>(p: UnsafePointer<T>)
|
||||
func _convertUnsafePointerToCConstPointer<T>(p: T*)
|
||||
-> CConstPointer<T> {
|
||||
return CConstPointer(_nilNativeObject, p.value)
|
||||
}
|
||||
@@ -600,7 +600,7 @@ func _convertCOpaquePointerToCConstVoidPointer(p: COpaquePointer)
|
||||
}
|
||||
|
||||
@transparent
|
||||
func _convertUnsafePointerToCMutablePointer<T>(p: UnsafePointer<T>)
|
||||
func _convertUnsafePointerToCMutablePointer<T>(p: T*)
|
||||
-> CMutablePointer<T> {
|
||||
return CMutablePointer(owner: _nilNativeObject, value: p.value)
|
||||
}
|
||||
@@ -612,7 +612,7 @@ func _convertCOpaquePointerToCMutableVoidPointer(p: COpaquePointer)
|
||||
}
|
||||
|
||||
@transparent
|
||||
func _convertUnsafePointerToObjCMutablePointer<T>(p: UnsafePointer<T>)
|
||||
func _convertUnsafePointerToObjCMutablePointer<T>(p: T*)
|
||||
-> ObjCMutablePointer<T> {
|
||||
return ObjCMutablePointer(p.value)
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ extension COpaquePointer {
|
||||
// FIXME: This shouldn't have to be in an extension.
|
||||
//
|
||||
/// Convert a typed UnsafePointer to an opaque C pointer.
|
||||
init<T>(_ from : UnsafePointer<T>) {
|
||||
init<T>(_ from : T*) {
|
||||
value = from.value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,13 +63,13 @@ struct ContiguousArrayBuffer<T> : ArrayBufferType, LogicValue {
|
||||
|
||||
/// If the elements are stored contiguously, a pointer to the first
|
||||
/// element. Otherwise, nil.
|
||||
var elementStorage: UnsafePointer<T> {
|
||||
var elementStorage: T* {
|
||||
return base ? base.elementStorage : nil
|
||||
}
|
||||
|
||||
/// A pointer to the first element, assuming that the elements are stored
|
||||
/// contiguously.
|
||||
var _unsafeElementStorage: UnsafePointer<T> {
|
||||
var _unsafeElementStorage: T* {
|
||||
return base.elementStorage
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ struct ContiguousArrayBuffer<T> : ArrayBufferType, LogicValue {
|
||||
/// starting at target. Return a pointer past-the-end of the
|
||||
/// just-initialized memory.
|
||||
func _uninitializedCopy(
|
||||
subRange: Range<Int>, target: UnsafePointer<T>
|
||||
) -> UnsafePointer<T> {
|
||||
subRange: Range<Int>, target: T*
|
||||
) -> T* {
|
||||
_sanityCheck(subRange.startIndex >= 0)
|
||||
_sanityCheck(subRange.endIndex >= subRange.startIndex)
|
||||
_sanityCheck(subRange.endIndex <= count)
|
||||
|
||||
@@ -195,7 +195,7 @@ protocol Mirror {
|
||||
/// without unnecessary copying of the underlying value.
|
||||
@asmname("swift_unsafeReflectAny") func unsafeReflect<T>(
|
||||
owner: Builtin.NativeObject,
|
||||
ptr: UnsafePointer<T>
|
||||
ptr: T*
|
||||
) -> Mirror
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ struct SliceBuffer<T> : ArrayBufferType {
|
||||
|
||||
init(
|
||||
owner: AnyObject?,
|
||||
start: UnsafePointer<T>,
|
||||
start: T*,
|
||||
count: Int,
|
||||
hasNativeBuffer: Bool
|
||||
) {
|
||||
@@ -73,7 +73,7 @@ struct SliceBuffer<T> : ArrayBufferType {
|
||||
|
||||
/// An object that keeps the elements stored in this buffer alive
|
||||
var owner: AnyObject?
|
||||
var start: UnsafePointer<T>
|
||||
var start: T*
|
||||
var _countAndFlags: UInt
|
||||
|
||||
//===--- Non-essential bits ---------------------------------------------===//
|
||||
@@ -111,8 +111,8 @@ struct SliceBuffer<T> : ArrayBufferType {
|
||||
}
|
||||
|
||||
func _uninitializedCopy(
|
||||
subRange: Range<Int>, var target: UnsafePointer<T>
|
||||
) -> UnsafePointer<T> {
|
||||
subRange: Range<Int>, var target: T*
|
||||
) -> T* {
|
||||
_invariantCheck()
|
||||
_sanityCheck(subRange.startIndex >= 0)
|
||||
_sanityCheck(subRange.endIndex >= subRange.startIndex)
|
||||
@@ -123,7 +123,7 @@ struct SliceBuffer<T> : ArrayBufferType {
|
||||
return target
|
||||
}
|
||||
|
||||
var elementStorage: UnsafePointer<T> {
|
||||
var elementStorage: T* {
|
||||
return start
|
||||
}
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ extension UTF16 {
|
||||
}
|
||||
|
||||
static func copy<T: StringElement, U: StringElement>(
|
||||
source: UnsafePointer<T>, destination: UnsafePointer<U>, count: Int
|
||||
source: T*, destination: UnsafePointer<U>, count: Int
|
||||
) {
|
||||
if UWord(Builtin.strideof(T.self)) == UWord(Builtin.strideof(U.self)) {
|
||||
c_memcpy(
|
||||
|
||||
@@ -32,7 +32,7 @@ struct UnsafeArray<T> : Collection, Generator {
|
||||
return (_position + i).pointee
|
||||
}
|
||||
|
||||
init(start: UnsafePointer<T>, length: Int) {
|
||||
init(start: T*, length: Int) {
|
||||
_position = start
|
||||
_end = start + length
|
||||
}
|
||||
@@ -48,5 +48,5 @@ struct UnsafeArray<T> : Collection, Generator {
|
||||
return self
|
||||
}
|
||||
|
||||
var _position, _end: UnsafePointer<T>
|
||||
var _position, _end: T*
|
||||
}
|
||||
|
||||
@@ -285,34 +285,34 @@ struct UnsafePointer<T> : BidirectionalIndex, Comparable, Hashable {
|
||||
}
|
||||
|
||||
@transparent
|
||||
func == <T> (lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Bool {
|
||||
func == <T> (lhs: T*, rhs: T*) -> Bool {
|
||||
return Bool(Builtin.cmp_eq_RawPointer(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
func < <T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Bool {
|
||||
func < <T>(lhs: T*, rhs: T*) -> Bool {
|
||||
return Bool(Builtin.cmp_ult_RawPointer(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
func + <T>(lhs: UnsafePointer<T>, rhs: Int) -> UnsafePointer<T> {
|
||||
func + <T>(lhs: T*, rhs: Int) -> T* {
|
||||
return UnsafePointer(
|
||||
Builtin.gep_Word(lhs.value, (rhs * Int(Builtin.strideof(T.self))).value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
func + <T>(lhs: Int,
|
||||
rhs: UnsafePointer<T>) -> UnsafePointer<T> {
|
||||
rhs: T*) -> T* {
|
||||
return rhs + lhs
|
||||
}
|
||||
|
||||
@transparent
|
||||
func - <T>(lhs: UnsafePointer<T>, rhs: Int) -> UnsafePointer<T> {
|
||||
func - <T>(lhs: T*, rhs: Int) -> T* {
|
||||
return lhs + -rhs
|
||||
}
|
||||
|
||||
@transparent
|
||||
func - <T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Int {
|
||||
func - <T>(lhs: T*, rhs: T*) -> Int {
|
||||
return
|
||||
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(lhs.value),
|
||||
Builtin.ptrtoint_Word(rhs.value)))
|
||||
@@ -320,12 +320,12 @@ func - <T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Int {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@assignment func += <T>(inout lhs: UnsafePointer<T>, rhs: Int) {
|
||||
@assignment func += <T>(inout lhs: T*, rhs: Int) {
|
||||
lhs = lhs + rhs
|
||||
}
|
||||
|
||||
@transparent
|
||||
@assignment func -= <T>(inout lhs: UnsafePointer<T>, rhs: Int) {
|
||||
@assignment func -= <T>(inout lhs: T*, rhs: Int) {
|
||||
lhs = lhs - rhs
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ struct RawByte {
|
||||
// Make nil work with UnsafePointer
|
||||
extension _Nil {
|
||||
@transparent
|
||||
@conversion func __conversion<T>() -> UnsafePointer<T> {
|
||||
@conversion func __conversion<T>() -> T* {
|
||||
return .null()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func __swift_initializeCocoaStringBridge() -> COpaquePointer {
|
||||
// buffer copying.
|
||||
//
|
||||
func _cocoaStringReadAllImpl(
|
||||
source: _CocoaString, destination: UnsafePointer<UTF16.CodeUnit>) {
|
||||
source: _CocoaString, destination: UTF16.CodeUnit*) {
|
||||
let cfSelf: CFString = reinterpretCast(source)
|
||||
CFStringGetCharacters(
|
||||
cfSelf, CFRange(location: 0, length: CFStringGetLength(cfSelf)), destination)
|
||||
@@ -239,7 +239,7 @@ class _NSContiguousString : NSString {
|
||||
}
|
||||
|
||||
@objc
|
||||
func _fastCharacterContents() -> UnsafePointer<unichar> {
|
||||
func _fastCharacterContents() -> unichar* {
|
||||
return value.elementWidth == 2 ? UnsafePointer(value.startUTF16) : nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user