Skip to content

Commit 62fcab1

Browse files
committed
Revert "Merge pull request #1247 from kelvin13/se-0184a"
This reverts commit 1b12e83, reversing changes made to c13b850.
1 parent 87e96fa commit 62fcab1

26 files changed

+74
-68
lines changed

Foundation/AffineTransform.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ open class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
369369
preconditionFailure("Unkeyed coding is unsupported.")
370370
}
371371

372-
let pointer = UnsafeMutableRawPointer.allocate(byteCount: MemoryLayout<Float>.stride * 6, alignment: 1)
372+
let pointer = UnsafeMutableRawPointer.allocate(bytes: MemoryLayout<Float>.stride * 6, alignedTo: 1)
373373
defer {
374-
pointer.deallocate()
374+
pointer.deallocate(bytes: MemoryLayout<Float>.stride * 6, alignedTo: 1)
375375
}
376376
aDecoder.decodeValue(ofObjCType: "[6f]", at: pointer)
377377

Foundation/Data.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public final class _DataStorage {
153153
}
154154
return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len)))
155155
} else {
156-
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
156+
var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count)
157157
defer { buffer.deallocate() }
158158
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
159159
var enumerated = 0
@@ -184,7 +184,7 @@ public final class _DataStorage {
184184
}
185185
return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len)))
186186
} else {
187-
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
187+
var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count)
188188
defer { buffer.deallocate() }
189189
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
190190
var enumerated = 0

Foundation/Dictionary.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ extension Dictionary : _ObjectTypeBridgeable {
3030

3131
keyBuffer.deinitialize(count: count)
3232
valueBuffer.deinitialize(count: count)
33-
keyBuffer.deallocate()
34-
valueBuffer.deallocate()
33+
keyBuffer.deallocate(capacity: count)
34+
valueBuffer.deallocate(capacity: count)
3535

3636
return dict
3737

@@ -75,8 +75,8 @@ extension Dictionary : _ObjectTypeBridgeable {
7575
}
7676
keys.deinitialize(count: cnt)
7777
values.deinitialize(count: cnt)
78-
keys.deallocate()
79-
values.deallocate()
78+
keys.deallocate(capacity: cnt)
79+
values.deallocate(capacity: cnt)
8080
}
8181
if !failedConversion {
8282
result = dict

Foundation/FileManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ open class FileManager : NSObject {
462462
ps.advanced(by: 1).initialize(to: nil)
463463
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
464464
ps.deinitialize(count: 2)
465-
ps.deallocate()
465+
ps.deallocate(capacity: 2)
466466

467467
if stream != nil {
468468
defer {
@@ -682,7 +682,7 @@ open class FileManager : NSObject {
682682
}
683683
if !path._nsObject.getFileSystemRepresentation(buf, maxLength: len) {
684684
buf.deinitialize(count: len)
685-
buf.deallocate()
685+
buf.deallocate(capacity: len)
686686
fatalError("string could not be converted")
687687
}
688688
return UnsafePointer(buf)
@@ -1038,7 +1038,7 @@ extension FileManager {
10381038
ps.advanced(by: 1).initialize(to: nil)
10391039
_stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
10401040
ps.deinitialize(count: 2)
1041-
ps.deallocate()
1041+
ps.deallocate(capacity: 2)
10421042
} else {
10431043
_rootError = _NSErrorWithErrno(ENOENT, reading: true, url: url)
10441044
}

Foundation/Host.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ open class Host: NSObject {
4242
static internal func currentHostName() -> String {
4343
let hname = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
4444
defer {
45-
hname.deallocate()
45+
hname.deinitialize()
46+
hname.deallocate(capacity: Int(NI_MAXHOST))
4647
}
4748
let r = gethostname(hname, Int(NI_MAXHOST))
4849
if r < 0 || hname[0] == 0 {
@@ -79,7 +80,8 @@ open class Host: NSObject {
7980
let address = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
8081
defer {
8182
freeifaddrs(ifaddr)
82-
address.deallocate()
83+
address.deinitialize()
84+
address.deallocate(capacity: Int(NI_MAXHOST))
8385
}
8486
while let ifaValue = ifa?.pointee {
8587
if let ifa_addr = ifaValue.ifa_addr, ifaValue.ifa_flags & UInt32(IFF_LOOPBACK) == 0 {
@@ -135,7 +137,8 @@ open class Host: NSObject {
135137
var res: UnsafeMutablePointer<addrinfo>? = res0
136138
let host = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
137139
defer {
138-
host.deallocate()
140+
host.deinitialize()
141+
host.deallocate(capacity: Int(NI_MAXHOST))
139142
}
140143
while res != nil {
141144
let info = res!.pointee
@@ -181,3 +184,4 @@ open class Host: NSObject {
181184
return nil
182185
}
183186
}
187+

Foundation/JSONSerialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,9 @@ private struct JSONReader {
820820

821821
let startPointer = buffer.baseAddress!
822822
let intEndPointer = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 1)
823-
defer { intEndPointer.deallocate() }
823+
defer { intEndPointer.deallocate(capacity: 1) }
824824
let doubleEndPointer = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 1)
825-
defer { doubleEndPointer.deallocate() }
825+
defer { doubleEndPointer.deallocate(capacity: 1) }
826826
let intResult = strtol(startPointer, intEndPointer, 10)
827827
let intDistance = startPointer.distance(to: intEndPointer[0]!)
828828
let doubleResult = strtod(startPointer, doubleEndPointer)

Foundation/NSArray.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
148148
buffer.initialize(from: optionalArray, count: cnt)
149149
self.init(objects: buffer, count: cnt)
150150
buffer.deinitialize(count: cnt)
151-
buffer.deallocate()
151+
buffer.deallocate(capacity: cnt)
152152
}
153153

154154
open override func isEqual(_ value: Any?) -> Bool {
@@ -404,7 +404,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
404404
}
405405
}
406406
return Data(bytesNoCopy: buffer, count: size, deallocator: .custom({ (_, _) in
407-
buffer.deallocate()
407+
buffer.deallocate(capacity: size)
408408
}))
409409
}
410410

Foundation/NSCFDictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ internal final class _NSCFDictionary : NSMutableDictionary {
7171
let key = unsafeBitCast(keys.advanced(by: idx).pointee!, to: NSObject.self)
7272
keyArray.append(key)
7373
}
74-
keys.deinitialize(count: 1)
75-
keys.deallocate()
74+
keys.deinitialize()
75+
keys.deallocate(capacity: count)
7676
}
7777
}
7878

Foundation/NSCFSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ internal final class _NSCFSet : NSMutableSet {
5858
let obj = unsafeBitCast(objects.advanced(by: idx).pointee!, to: AnyObject.self)
5959
objArray.append(obj)
6060
}
61-
objects.deinitialize(count: 1)
62-
objects.deallocate()
61+
objects.deinitialize()
62+
objects.deallocate(capacity: count)
6363

6464
return NSGeneratorEnumerator(objArray.makeIterator())
6565

Foundation/NSCoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ open class NSCoder : NSObject {
105105
deinit {
106106
for buffer in _pendingBuffers {
107107
// Cannot deinitialize a pointer to unknown type.
108-
buffer.0.deallocate()
108+
buffer.0.deallocate(bytes: buffer.1, alignedTo: MemoryLayout<Int>.alignment)
109109
}
110110
}
111111

@@ -383,7 +383,7 @@ open class NSCoder : NSObject {
383383
decodeValue(ofObjCType: "I", at: unsafeBitCast(ptr, to: UnsafeMutableRawPointer.self))
384384
}
385385
// we cannot autorelease here so instead the pending buffers will manage the lifespan of the returned data... this is wasteful but good enough...
386-
let result = UnsafeMutableRawPointer.allocate(byteCount: Int(length), alignment: MemoryLayout<Int>.alignment)
386+
let result = UnsafeMutableRawPointer.allocate(bytes: Int(length), alignedTo: MemoryLayout<Int>.alignment)
387387
decodeValue(ofObjCType: "c", at: result)
388388
lengthp.pointee = Int(length)
389389
_pendingBuffers.append((result, Int(length)))

Foundation/NSConcreteValue.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ internal class NSConcreteValue : NSValue {
9191

9292
self._typeInfo = typeInfo!
9393

94-
self._storage = UnsafeMutableRawPointer.allocate(byteCount: self._typeInfo.size, alignment: 1)
95-
self._storage.copyMemory(from: value, byteCount: self._typeInfo.size)
94+
self._storage = UnsafeMutableRawPointer.allocate(bytes: self._typeInfo.size, alignedTo: 1)
95+
self._storage.copyBytes(from: value, count: self._typeInfo.size)
9696
}
9797

9898
deinit {
9999
// Cannot deinitialize raw memory.
100-
self._storage.deallocate()
100+
self._storage.deallocate(bytes: self._size, alignedTo: 1)
101101
}
102102

103103
override func getValue(_ value: UnsafeMutableRawPointer) {
104-
value.copyMemory(from: self._storage, byteCount: self._size)
104+
value.copyBytes(from: self._storage, count: self._size)
105105
}
106106

107107
override var objCType : UnsafePointer<Int8> {

Foundation/NSDictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
154154

155155
keyBuffer.deinitialize(count: keys.count)
156156
valueBuffer.deinitialize(count: objects.count)
157-
keyBuffer.deallocate()
158-
valueBuffer.deallocate()
157+
keyBuffer.deallocate(capacity: keys.count)
158+
valueBuffer.deallocate(capacity: objects.count)
159159
}
160160

161161
public convenience init(dictionary otherDictionary: [AnyHashable : Any]) {

Foundation/NSGeometry.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension CGPoint: NSSpecialValueCoding {
7070
}
7171

7272
func getValue(_ value: UnsafeMutableRawPointer) {
73-
value.initializeMemory(as: CGPoint.self, repeating: self, count: 1)
73+
value.initializeMemory(as: CGPoint.self, to: self)
7474
}
7575

7676
func isEqual(_ aValue: Any) -> Bool {
@@ -162,7 +162,7 @@ extension CGSize: NSSpecialValueCoding {
162162
}
163163

164164
func getValue(_ value: UnsafeMutableRawPointer) {
165-
value.initializeMemory(as: CGSize.self, repeating: self, count: 1)
165+
value.initializeMemory(as: CGSize.self, to: self)
166166
}
167167

168168
func isEqual(_ aValue: Any) -> Bool {
@@ -466,7 +466,7 @@ extension CGRect: NSSpecialValueCoding {
466466
}
467467

468468
func getValue(_ value: UnsafeMutableRawPointer) {
469-
value.initializeMemory(as: CGRect.self, repeating: self, count: 1)
469+
value.initializeMemory(as: CGRect.self, to: self)
470470
}
471471

472472
func isEqual(_ aValue: Any) -> Bool {
@@ -565,7 +565,7 @@ extension NSEdgeInsets: NSSpecialValueCoding {
565565
}
566566

567567
func getValue(_ value: UnsafeMutableRawPointer) {
568-
value.initializeMemory(as: NSEdgeInsets.self, repeating: self, count: 1)
568+
value.initializeMemory(as: NSEdgeInsets.self, to: self)
569569
}
570570

571571
func isEqual(_ aValue: Any) -> Bool {

Foundation/NSKeyedCoderOldStyleArray.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC
4141
deinit {
4242
if self._decoded {
4343
// Cannot deinitialize memory without knowing the element type.
44-
self._addr.deallocate()
44+
self._addr.deallocate(bytes: self._count * self._size, alignedTo: 1)
4545
}
4646
}
4747

@@ -61,7 +61,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC
6161
return nil
6262
}
6363

64-
self._addr = UnsafeMutableRawPointer.allocate(byteCount: self._count * self._size, alignment: 1)
64+
self._addr = UnsafeMutableRawPointer.allocate(bytes: self._count * self._size, alignedTo: 1)
6565

6666
super.init()
6767

@@ -95,7 +95,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC
9595

9696
func fillObjCType(_ type: _NSSimpleObjCType, count: Int, at addr: UnsafeMutableRawPointer) {
9797
if type == self._type && count <= self._count {
98-
addr.copyMemory(from: self._addr, byteCount: count * self._size)
98+
addr.copyBytes(from: self._addr, count: count * self._size)
9999
}
100100
}
101101

Foundation/NSLock.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ open class NSLock: NSObject, NSLocking {
4646

4747
deinit {
4848
pthread_mutex_destroy(mutex)
49-
mutex.deinitialize(count: 1)
50-
mutex.deallocate()
49+
mutex.deinitialize()
50+
mutex.deallocate(capacity: 1)
5151
#if os(OSX) || os(iOS)
5252
deallocateTimedLockData(cond: timeoutCond, mutex: timeoutMutex)
5353
#endif
@@ -196,8 +196,8 @@ open class NSRecursiveLock: NSObject, NSLocking {
196196

197197
deinit {
198198
pthread_mutex_destroy(mutex)
199-
mutex.deinitialize(count: 1)
200-
mutex.deallocate()
199+
mutex.deinitialize()
200+
mutex.deallocate(capacity: 1)
201201
#if os(OSX) || os(iOS)
202202
deallocateTimedLockData(cond: timeoutCond, mutex: timeoutMutex)
203203
#endif
@@ -251,10 +251,10 @@ open class NSCondition: NSObject, NSLocking {
251251
deinit {
252252
pthread_mutex_destroy(mutex)
253253
pthread_cond_destroy(cond)
254-
mutex.deinitialize(count: 1)
255-
cond.deinitialize(count: 1)
256-
mutex.deallocate()
257-
cond.deallocate()
254+
mutex.deinitialize()
255+
cond.deinitialize()
256+
mutex.deallocate(capacity: 1)
257+
cond.deallocate(capacity: 1)
258258
}
259259

260260
open func lock() {

Foundation/NSOrderedSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ extension NSOrderedSet {
302302
}
303303
self.init(objects: buffer, count: array.count)
304304
buffer.deinitialize(count: array.count)
305-
buffer.deallocate()
305+
buffer.deallocate(capacity: array.count)
306306
}
307307

308308
public convenience init(array set: [Any], copyItems flag: Bool) {

Foundation/NSRange.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ extension NSRange: NSSpecialValueCoding {
400400
}
401401

402402
func getValue(_ value: UnsafeMutableRawPointer) {
403-
value.initializeMemory(as: NSRange.self, repeating: self, count: 1)
403+
value.initializeMemory(as: NSRange.self, to: self)
404404
}
405405

406406
func isEqual(_ aValue: Any) -> Bool {
@@ -426,3 +426,4 @@ extension NSValue {
426426
}
427427
}
428428
#endif
429+

Foundation/NSSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi
135135
}
136136
self.init(objects: buffer, count: array.count)
137137
buffer.deinitialize(count: array.count)
138-
buffer.deallocate()
138+
buffer.deallocate(capacity: array.count)
139139
}
140140

141141
public convenience init(set: Set<AnyHashable>) {

Foundation/NSString.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ open class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSC
247247
let characters = UnsafeMutablePointer<unichar>.allocate(capacity: length)
248248
getCharacters(characters, range: NSMakeRange(0, length))
249249
let result = NSMutableString(characters: characters, length: length)
250-
characters.deinitialize(count: 1)
251-
characters.deallocate()
250+
characters.deinitialize()
251+
characters.deallocate(capacity: length)
252252
return result
253253
}
254254

@@ -364,8 +364,8 @@ extension NSString {
364364
let buff = UnsafeMutablePointer<unichar>.allocate(capacity: range.length)
365365
getCharacters(buff, range: range)
366366
let result = String(describing: buff)
367-
buff.deinitialize(count: 1)
368-
buff.deallocate()
367+
buff.deinitialize()
368+
buff.deallocate(capacity: range.length)
369369
return result
370370
}
371371
}

Foundation/NSSwiftRuntime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ extension Array {
342342
let buffer = UnsafeMutablePointer<Element>.allocate(capacity: count)
343343
let res = body(buffer)
344344
buffer.deinitialize(count: count)
345-
buffer.deallocate()
345+
buffer.deallocate(capacity: count)
346346
return res
347347
} else {
348348
return withUnsafeMutableBufferPointer() { (bufferPtr: inout UnsafeMutableBufferPointer<Element>) -> R in

0 commit comments

Comments
 (0)