Rename UnsafePointer allocate & deallocate. (#3608)

As proposed in SE-0107: UnsafeRawPointer:
Rename 'init(allocatingCapacity:)' to 'UnsafeMutablePointer.allocate(capacity:)'
Rename 'deallocateCapacity' to 'deallocate(capacity:)'

`allocate` should not be an initializer. It's primary function is to allocate
memory, not initialize a pointer.
This commit is contained in:
Andrew Trick
2016-07-19 11:48:18 -07:00
committed by GitHub
parent f95ffdef7d
commit 5a8271c621
28 changed files with 130 additions and 118 deletions

View File

@@ -356,11 +356,11 @@ public func reflect(object: AnyObject) {
/// an Any existential.
public func reflect<T>(any: T) {
let any: Any = any
let anyPointer = UnsafeMutablePointer<Any>(allocatingCapacity: sizeof(Any.self))
let anyPointer = UnsafeMutablePointer<Any>.allocate(capacity: sizeof(Any.self))
anyPointer.initialize(to: any)
let anyPointerValue = unsafeBitCast(anyPointer, to: UInt.self)
reflect(instanceAddress: anyPointerValue, kind: .Existential)
anyPointer.deallocateCapacity(sizeof(Any.self))
anyPointer.deallocate(capacity: sizeof(Any.self))
}
// Reflect an `Error`, a.k.a. an "error existential".
@@ -419,8 +419,8 @@ struct ThickFunctionParts {
/// Reflect a closure context. The given function must be a Swift-native
/// @convention(thick) function value.
public func reflect(function: () -> ()) {
let fn = UnsafeMutablePointer<ThickFunction0>(
allocatingCapacity: sizeof(ThickFunction0.self))
let fn = UnsafeMutablePointer<ThickFunction0>.allocate(
capacity: sizeof(ThickFunction0.self))
fn.initialize(to: ThickFunction0(function: function))
let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
@@ -428,14 +428,15 @@ public func reflect(function: () -> ()) {
reflect(instanceAddress: contextPointer, kind: .Object)
fn.deallocateCapacity(sizeof(ThickFunction0.self))
fn.deallocate(capacity: sizeof(ThickFunction0.self))
}
/// Reflect a closure context. The given function must be a Swift-native
/// @convention(thick) function value.
public func reflect(function: (Int) -> ()) {
let fn = UnsafeMutablePointer<ThickFunction1>(
allocatingCapacity: sizeof(ThickFunction1.self))
let fn =
UnsafeMutablePointer<ThickFunction1>.allocate(
capacity: sizeof(ThickFunction1.self))
fn.initialize(to: ThickFunction1(function: function))
let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
@@ -443,14 +444,14 @@ public func reflect(function: (Int) -> ()) {
reflect(instanceAddress: contextPointer, kind: .Object)
fn.deallocateCapacity(sizeof(ThickFunction1.self))
fn.deallocate(capacity: sizeof(ThickFunction1.self))
}
/// Reflect a closure context. The given function must be a Swift-native
/// @convention(thick) function value.
public func reflect(function: (Int, String) -> ()) {
let fn = UnsafeMutablePointer<ThickFunction2>(
allocatingCapacity: sizeof(ThickFunction2.self))
let fn = UnsafeMutablePointer<ThickFunction2>.allocate(
capacity: sizeof(ThickFunction2.self))
fn.initialize(to: ThickFunction2(function: function))
let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
@@ -458,14 +459,14 @@ public func reflect(function: (Int, String) -> ()) {
reflect(instanceAddress: contextPointer, kind: .Object)
fn.deallocateCapacity(sizeof(ThickFunction2.self))
fn.deallocate(capacity: sizeof(ThickFunction2.self))
}
/// Reflect a closure context. The given function must be a Swift-native
/// @convention(thick) function value.
public func reflect(function: (Int, String, AnyObject?) -> ()) {
let fn = UnsafeMutablePointer<ThickFunction3>(
allocatingCapacity: sizeof(ThickFunction3.self))
let fn = UnsafeMutablePointer<ThickFunction3>.allocate(
capacity: sizeof(ThickFunction3.self))
fn.initialize(to: ThickFunction3(function: function))
let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
@@ -473,7 +474,7 @@ public func reflect(function: (Int, String, AnyObject?) -> ()) {
reflect(instanceAddress: contextPointer, kind: .Object)
fn.deallocateCapacity(sizeof(ThickFunction3.self))
fn.deallocate(capacity: sizeof(ThickFunction3.self))
}
/// Call this function to indicate to the parent that there are