Skip to content

Commit bb0ba85

Browse files
committed
Revert "Update for SE-0107: Migrate Void->Raw."
This reverts commit 030661c.
1 parent 848fbc8 commit bb0ba85

40 files changed

+264
-276
lines changed

Foundation/Data.swift

+18-20
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import Darwin
1616
import Glibc
1717
#endif
1818

19-
internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutableRawPointer, _ length: Int) -> Void {
19+
internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutablePointer<Void>, _ length: Int) -> Void {
2020
munmap(mem, length)
2121
}
2222

23-
internal func __NSDataInvokeDeallocatorFree(_ mem: UnsafeMutableRawPointer, _ length: Int) -> Void {
23+
internal func __NSDataInvokeDeallocatorFree(_ mem: UnsafeMutablePointer<Void>, _ length: Int) -> Void {
2424
free(mem)
2525
}
2626

@@ -34,30 +34,30 @@ internal final class _SwiftNSData : NSData, _SwiftNativeFoundationType {
3434
// Take ownership.
3535
__wrapped = .Immutable(Unmanaged.passRetained(_unsafeReferenceCast(immutableObject, to: ImmutableType.self)))
3636

37-
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutableRawPointer.self)
37+
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutablePointer<Void>.self)
3838
super.init(bytes: dummyPointer, length: 0, copy: false, deallocator: nil)
3939
}
4040

4141
init(mutableObject: AnyObject) {
4242
// Take ownership.
4343
__wrapped = .Mutable(Unmanaged.passRetained(_unsafeReferenceCast(mutableObject, to: MutableType.self)))
44-
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutableRawPointer.self)
44+
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutablePointer<Void>.self)
4545
super.init(bytes: dummyPointer, length: 0, copy: false, deallocator: nil)
4646
}
4747

4848
internal required init(unmanagedImmutableObject: Unmanaged<ImmutableType>) {
4949
// Take ownership.
5050
__wrapped = .Immutable(unmanagedImmutableObject)
5151

52-
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutableRawPointer.self)
52+
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutablePointer<Void>.self)
5353
super.init(bytes: dummyPointer, length: 0, copy: false, deallocator: nil)
5454
}
5555

5656
internal required init(unmanagedMutableObject: Unmanaged<MutableType>) {
5757
// Take ownership.
5858
__wrapped = .Mutable(unmanagedMutableObject)
5959

60-
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutableRawPointer.self)
60+
let dummyPointer = unsafeBitCast(NSData.self, to: UnsafeMutablePointer<Void>.self)
6161
super.init(bytes: dummyPointer, length: 0, copy: false, deallocator: nil)
6262
}
6363

@@ -82,19 +82,19 @@ internal final class _SwiftNSData : NSData, _SwiftNativeFoundationType {
8282
}
8383
}
8484

85-
override var bytes : UnsafeRawPointer {
85+
override var bytes : UnsafePointer<Void> {
8686
return _mapUnmanaged { $0.bytes }
8787
}
8888

8989
// override func subdata(with range: NSRange) -> Data {
9090
// return _mapUnmanaged { $0.subdata(with: range) }
9191
// }
9292
//
93-
// override func getBytes(_ buffer: UnsafeMutableRawPointer, length: Int) {
93+
// override func getBytes(_ buffer: UnsafeMutablePointer<Void>, length: Int) {
9494
// return _mapUnmanaged { $0.getBytes(buffer, length: length) }
9595
// }
9696
//
97-
// override func getBytes(_ buffer: UnsafeMutableRawPointer, range: NSRange) {
97+
// override func getBytes(_ buffer: UnsafeMutablePointer<Void>, range: NSRange) {
9898
// return _mapUnmanaged { $0.getBytes(buffer, range: range) }
9999
// }
100100
//
@@ -112,7 +112,7 @@ internal final class _SwiftNSData : NSData, _SwiftNativeFoundationType {
112112
// }
113113
// }
114114
//
115-
// override func enumerateByteRanges(using block: @noescape (UnsafeRawPointer, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
115+
// override func enumerateByteRanges(using block: @noescape (UnsafePointer<Void>, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
116116
// return _mapUnmanaged { $0.enumerateBytes(block) }
117117
// }
118118
//
@@ -163,7 +163,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
163163
/// A custom deallocator.
164164
case custom((UnsafeMutablePointer<UInt8>, Int) -> Void)
165165

166-
fileprivate var _deallocator : ((UnsafeMutableRawPointer, Int) -> Void)? {
166+
fileprivate var _deallocator : ((UnsafeMutablePointer<Void>, Int) -> Void)? {
167167
switch self {
168168
case .unmap:
169169
return { __NSDataInvokeDeallocatorUnmap($0, $1) }
@@ -186,7 +186,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
186186
///
187187
/// - parameter bytes: A pointer to the memory. It will be copied.
188188
/// - parameter count: The number of bytes to copy.
189-
public init(bytes: UnsafeRawPointer, count: Int) {
189+
public init(bytes: UnsafePointer<Void>, count: Int) {
190190
_wrapped = _SwiftNSData(immutableObject: NSData(bytes: bytes, length: count))
191191
}
192192

@@ -279,8 +279,8 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
279279
}
280280

281281
public init?(count: Int) {
282-
if let memory = malloc(count)?.bindMemory(to: UInt8.self, capacity: count) {
283-
self.init(bytesNoCopy: memory, count: count, deallocator: .free)
282+
if let memory = malloc(count) {
283+
self.init(bytesNoCopy: UnsafeMutablePointer<UInt8>(memory), count: count, deallocator: .free)
284284
} else {
285285
return nil
286286
}
@@ -304,7 +304,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
304304
}
305305
}
306306

307-
private func _getUnsafeBytesPointer() -> UnsafeRawPointer {
307+
private func _getUnsafeBytesPointer() -> UnsafePointer<Void> {
308308
return _mapUnmanaged { return $0.bytes }
309309
}
310310

@@ -314,11 +314,10 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
314314
public func withUnsafeBytes<ResultType, ContentType>(_ body: @noescape (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType {
315315
let bytes = _getUnsafeBytesPointer()
316316
defer { _fixLifetime(self)}
317-
let contentPtr = bytes.bindMemory(to: ContentType.self, capacity: count / strideof(ContentType.self))
318-
return try body(contentPtr)
317+
return try body(UnsafePointer(bytes))
319318
}
320319

321-
private mutating func _getUnsafeMutableBytesPointer() -> UnsafeMutableRawPointer {
320+
private mutating func _getUnsafeMutableBytesPointer() -> UnsafeMutablePointer<Void> {
322321
return _applyUnmanagedMutation {
323322
return $0.mutableBytes
324323
}
@@ -331,8 +330,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
331330
public mutating func withUnsafeMutableBytes<ResultType, ContentType>(_ body: @noescape (UnsafeMutablePointer<ContentType>) throws -> ResultType) rethrows -> ResultType {
332331
let mutableBytes = _getUnsafeMutableBytesPointer()
333332
defer { _fixLifetime(self)}
334-
let contentPtr = mutableBytes.bindMemory(to: ContentType.self, capacity: count / strideof(ContentType.self))
335-
return try body(contentPtr)
333+
return try body(UnsafeMutablePointer(mutableBytes))
336334
}
337335

338336
// MARK: -

Foundation/NSArray.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
7070
// because that's the way the code was originally written, unless
7171
// we go to a new version of the class, which has its own problems.
7272
withUnsafeMutablePointer(&cnt) { (ptr: UnsafeMutablePointer<UInt32>) -> Void in
73-
aDecoder.decodeValue(ofObjCType: "i", at: UnsafeMutableRawPointer(ptr))
73+
aDecoder.decodeValue(ofObjCType: "i", at: UnsafeMutablePointer<Void>(ptr))
7474
}
7575
let objects = UnsafeMutablePointer<AnyObject?>.allocate(capacity: Int(cnt))
7676
for idx in 0..<cnt {
@@ -388,13 +388,13 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
388388
}))
389389
}
390390

391-
public func sortedArray(_ comparator: @noescape @convention(c) (AnyObject, AnyObject, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?) -> [AnyObject] {
391+
public func sortedArray(_ comparator: @noescape @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Swift.Void>?) -> Int, context: UnsafeMutablePointer<Swift.Void>?) -> [AnyObject] {
392392
return sortedArray([]) { lhs, rhs in
393393
return ComparisonResult(rawValue: comparator(lhs, rhs, context))!
394394
}
395395
}
396396

397-
public func sortedArray(_ comparator: @noescape @convention(c) (AnyObject, AnyObject, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?, hint: Data?) -> [AnyObject] {
397+
public func sortedArray(_ comparator: @noescape @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Swift.Void>?) -> Int, context: UnsafeMutablePointer<Swift.Void>?, hint: Data?) -> [AnyObject] {
398398
return sortedArray([]) { lhs, rhs in
399399
return ComparisonResult(rawValue: comparator(lhs, rhs, context))!
400400
}
@@ -834,7 +834,7 @@ public class NSMutableArray : NSArray {
834834
}
835835
}
836836

837-
public func sortUsingFunction(_ compare: @convention(c) (AnyObject, AnyObject, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?) {
837+
public func sortUsingFunction(_ compare: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>?) -> Int, context: UnsafeMutablePointer<Void>?) {
838838
self.setArray(self.sortedArray(compare, context: context))
839839
}
840840

Foundation/NSCFArray.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal final class _NSCFArray : NSMutableArray {
3434
}
3535

3636
override func insert(_ anObject: AnyObject, at index: Int) {
37-
CFArrayInsertValueAtIndex(_cfMutableObject, index, unsafeBitCast(anObject, to: UnsafeRawPointer.self))
37+
CFArrayInsertValueAtIndex(_cfMutableObject, index, unsafeBitCast(anObject, to: UnsafePointer<Void>.self))
3838
}
3939

4040
override func removeObject(at index: Int) {

Foundation/NSCFDictionary.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal final class _NSCFDictionary : NSMutableDictionary {
3737
}
3838

3939
override func objectForKey(_ aKey: AnyObject) -> AnyObject? {
40-
let value = CFDictionaryGetValue(_cfObject, unsafeBitCast(aKey, to: UnsafeRawPointer.self))
40+
let value = CFDictionaryGetValue(_cfObject, unsafeBitCast(aKey, to: UnsafePointer<Void>.self))
4141
if value != nil {
4242
return unsafeBitCast(value, to: AnyObject.self)
4343
} else {
@@ -64,7 +64,7 @@ internal final class _NSCFDictionary : NSMutableDictionary {
6464
let cf = dict._cfObject
6565
count = CFDictionaryGetCount(cf)
6666

67-
let keys = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: count)
67+
let keys = UnsafeMutablePointer<UnsafePointer<Void>?>.allocate(capacity: count)
6868
CFDictionaryGetKeysAndValues(cf, keys, nil)
6969

7070
for idx in 0..<count {
@@ -81,11 +81,11 @@ internal final class _NSCFDictionary : NSMutableDictionary {
8181
}
8282

8383
override func removeObject(forKey aKey: AnyObject) {
84-
CFDictionaryRemoveValue(_cfMutableObject, unsafeBitCast(aKey, to: UnsafeRawPointer.self))
84+
CFDictionaryRemoveValue(_cfMutableObject, unsafeBitCast(aKey, to: UnsafePointer<Void>.self))
8585
}
8686

8787
override func setObject(_ anObject: AnyObject, forKey aKey: NSObject) {
88-
CFDictionarySetValue(_cfMutableObject, unsafeBitCast(aKey, to: UnsafeRawPointer.self), unsafeBitCast(anObject, to: UnsafeRawPointer.self))
88+
CFDictionarySetValue(_cfMutableObject, unsafeBitCast(aKey, to: UnsafePointer<Void>.self), unsafeBitCast(anObject, to: UnsafePointer<Void>.self))
8989
}
9090

9191
override var classForCoder: AnyClass {
@@ -152,7 +152,7 @@ internal func _CFSwiftDictionaryGetValuesAndKeys(_ dictionary: AnyObject, valueb
152152
}
153153
}
154154

155-
internal func _CFSwiftDictionaryApplyFunction(_ dictionary: AnyObject, applier: @convention(c) (AnyObject, AnyObject, UnsafeMutableRawPointer) -> Void, context: UnsafeMutableRawPointer) {
155+
internal func _CFSwiftDictionaryApplyFunction(_ dictionary: AnyObject, applier: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Void, context: UnsafeMutablePointer<Void>) {
156156
(dictionary as! NSDictionary).enumerateKeysAndObjects([]) { key, value, _ in
157157
applier(key, value, context)
158158
}

Foundation/NSCFString.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ internal class _NSCFString : NSMutableString {
5959

6060
internal final class _NSCFConstantString : _NSCFString {
6161
internal var _ptr : UnsafePointer<UInt8> {
62-
let offset = sizeof(OpaquePointer.self) + sizeof(Int32.self) + sizeof(Int32.self) + sizeof(_CFInfo.self)
63-
let ptr = Unmanaged.passUnretained(self).toOpaque()
64-
return ptr.load(fromByteOffset: offset, as: UnsafePointer<UInt8>.self)
62+
let ptr = unsafeAddress(of: self) + sizeof(OpaquePointer.self) + sizeof(Int32.self) + sizeof(Int32.self) + sizeof(_CFInfo.self)
63+
return UnsafePointer<UnsafePointer<UInt8>>(ptr).pointee
6564
}
6665
internal var _length : UInt32 {
6766
let offset = sizeof(OpaquePointer.self) + sizeof(Int32.self) + sizeof(Int32.self) + sizeof(_CFInfo.self) + sizeof(UnsafePointer<UInt8>.self)
68-
let ptr = Unmanaged.passUnretained(self).toOpaque()
69-
return ptr.load(fromByteOffset: offset, as: UInt32.self)
67+
let ptr = unsafeAddress(of: self) + offset
68+
return UnsafePointer<UInt32>(ptr).pointee
7069
}
7170

7271
required init(characters: UnsafePointer<unichar>, length: Int) {

Foundation/NSCache.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Cache: NSObject {
2222
}
2323
}
2424

25-
private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry>()
25+
private var _entries = Dictionary<UnsafePointer<Void>, NSCacheEntry>()
2626
private let _lock = Lock()
2727
private var _totalCost = 0
2828
private var _byCost: NSCacheEntry?
@@ -41,7 +41,7 @@ public class Cache: NSObject {
4141
public func object(forKey key: AnyObject) -> AnyObject? {
4242
var object: AnyObject?
4343

44-
let keyRef = unsafeBitCast(key, to: UnsafeRawPointer.self)
44+
let keyRef = unsafeBitCast(key, to: UnsafePointer<Void>.self)
4545

4646
_lock.lock()
4747
if let entry = _entries[keyRef] {
@@ -84,7 +84,7 @@ public class Cache: NSObject {
8484
}
8585

8686
public func setObject(_ obj: AnyObject, forKey key: AnyObject, cost g: Int) {
87-
let keyRef = unsafeBitCast(key, to: UnsafeRawPointer.self)
87+
let keyRef = unsafeBitCast(key, to: UnsafePointer<Void>.self)
8888

8989
_lock.lock()
9090
_totalCost += g
@@ -152,13 +152,13 @@ public class Cache: NSObject {
152152

153153
_lock.lock()
154154
for entry in toRemove {
155-
_entries.removeValue(forKey: unsafeBitCast(entry.key, to: UnsafeRawPointer.self)) // the cost list is already fixed up in the purge routines
155+
_entries.removeValue(forKey: unsafeBitCast(entry.key, to: UnsafePointer<Void>.self)) // the cost list is already fixed up in the purge routines
156156
}
157157
_lock.unlock()
158158
}
159159

160160
public func removeObject(forKey key: AnyObject) {
161-
let keyRef = unsafeBitCast(key, to: UnsafeRawPointer.self)
161+
let keyRef = unsafeBitCast(key, to: UnsafePointer<Void>.self)
162162

163163
_lock.lock()
164164
if let entry = _entries.removeValue(forKey: keyRef) {

Foundation/NSCalendar.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ extension Calendar {
100100
public class Calendar: NSObject, NSCopying, NSSecureCoding {
101101
typealias CFType = CFCalendar
102102
private var _base = _CFInfo(typeID: CFCalendarGetTypeID())
103-
private var _identifier: UnsafeMutableRawPointer? = nil
104-
private var _locale: UnsafeMutableRawPointer? = nil
105-
private var _localeID: UnsafeMutableRawPointer? = nil
106-
private var _tz: UnsafeMutableRawPointer? = nil
107-
private var _cal: UnsafeMutableRawPointer? = nil
103+
private var _identifier: UnsafeMutablePointer<Void>? = nil
104+
private var _locale: UnsafeMutablePointer<Void>? = nil
105+
private var _localeID: UnsafeMutablePointer<Void>? = nil
106+
private var _tz: UnsafeMutablePointer<Void>? = nil
107+
private var _cal: UnsafeMutablePointer<Void>? = nil
108108

109109
internal var _cfObject: CFType {
110110
return unsafeBitCast(self, to: CFCalendar.self)

Foundation/NSCharacterSet.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSCoding {
3333
typealias CFType = CFCharacterSet
3434
private var _base = _CFInfo(typeID: CFCharacterSetGetTypeID())
3535
private var _hashValue = CFHashCode(0)
36-
private var _buffer: UnsafeMutableRawPointer? = nil
36+
private var _buffer: UnsafeMutablePointer<Void>? = nil
3737
private var _length = CFIndex(0)
38-
private var _annex: UnsafeMutableRawPointer? = nil
38+
private var _annex: UnsafeMutablePointer<Void>? = nil
3939

4040
internal var _cfObject: CFType {
4141
return unsafeBitCast(self, to: CFType.self)

0 commit comments

Comments
 (0)