Skip to content

Commit 6476c4f

Browse files
committed
compatability with SE-0184 implementation
1 parent 17789b5 commit 6476c4f

26 files changed

+68
-74
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(bytes: MemoryLayout<Float>.stride * 6, alignedTo: 1)
372+
let pointer = UnsafeMutableRawPointer.allocate(byteCount: MemoryLayout<Float>.stride * 6, alignment: 1)
373373
defer {
374-
pointer.deallocate(bytes: MemoryLayout<Float>.stride * 6, alignedTo: 1)
374+
pointer.deallocate()
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(count: range.count)
156+
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
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(count: range.count)
187+
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
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(capacity: count)
34-
valueBuffer.deallocate(capacity: count)
33+
keyBuffer.deallocate()
34+
valueBuffer.deallocate()
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(capacity: cnt)
79-
values.deallocate(capacity: cnt)
78+
keys.deallocate()
79+
values.deallocate()
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(capacity: 2)
465+
ps.deallocate()
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(capacity: len)
685+
buf.deallocate()
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(capacity: 2)
1041+
ps.deallocate()
10421042
} else {
10431043
_rootError = _NSErrorWithErrno(ENOENT, reading: true, url: url)
10441044
}

Foundation/Host.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ open class Host: NSObject {
4242
static internal func currentHostName() -> String {
4343
let hname = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
4444
defer {
45-
hname.deinitialize()
46-
hname.deallocate(capacity: Int(NI_MAXHOST))
45+
hname.deallocate()
4746
}
4847
let r = gethostname(hname, Int(NI_MAXHOST))
4948
if r < 0 || hname[0] == 0 {
@@ -80,8 +79,7 @@ open class Host: NSObject {
8079
let address = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
8180
defer {
8281
freeifaddrs(ifaddr)
83-
address.deinitialize()
84-
address.deallocate(capacity: Int(NI_MAXHOST))
82+
address.deallocate()
8583
}
8684
while let ifaValue = ifa?.pointee {
8785
if let ifa_addr = ifaValue.ifa_addr, ifaValue.ifa_flags & UInt32(IFF_LOOPBACK) == 0 {
@@ -137,8 +135,7 @@ open class Host: NSObject {
137135
var res: UnsafeMutablePointer<addrinfo>? = res0
138136
let host = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
139137
defer {
140-
host.deinitialize()
141-
host.deallocate(capacity: Int(NI_MAXHOST))
138+
host.deallocate()
142139
}
143140
while res != nil {
144141
let info = res!.pointee
@@ -184,4 +181,3 @@ open class Host: NSObject {
184181
return nil
185182
}
186183
}
187-

Foundation/JSONSerialization.swift

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

820820
let startPointer = buffer.baseAddress!
821821
let intEndPointer = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 1)
822-
defer { intEndPointer.deallocate(capacity: 1) }
822+
defer { intEndPointer.deallocate() }
823823
let doubleEndPointer = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 1)
824-
defer { doubleEndPointer.deallocate(capacity: 1) }
824+
defer { doubleEndPointer.deallocate() }
825825
let intResult = strtol(startPointer, intEndPointer, 10)
826826
let intDistance = startPointer.distance(to: intEndPointer[0]!)
827827
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(capacity: cnt)
151+
buffer.deallocate()
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(capacity: size)
407+
buffer.deallocate()
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()
75-
keys.deallocate(capacity: count)
74+
keys.deinitialize(count: 1)
75+
keys.deallocate()
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()
62-
objects.deallocate(capacity: count)
61+
objects.deinitialize(count: 1)
62+
objects.deallocate()
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(bytes: buffer.1, alignedTo: MemoryLayout<Int>.alignment)
108+
buffer.0.deallocate()
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(bytes: Int(length), alignedTo: MemoryLayout<Int>.alignment)
386+
let result = UnsafeMutableRawPointer.allocate(byteCount: Int(length), alignment: MemoryLayout<Int>.alignment)
387387
decodeValue(ofObjCType: "c", at: result)
388388
lengthp.pointee = Int(length)
389389
_pendingBuffers.append((result, Int(length)))

0 commit comments

Comments
 (0)