diff --git a/Foundation/AffineTransform.swift b/Foundation/AffineTransform.swift index 845c5df620..703278930e 100644 --- a/Foundation/AffineTransform.swift +++ b/Foundation/AffineTransform.swift @@ -369,9 +369,9 @@ open class NSAffineTransform : NSObject, NSCopying, NSSecureCoding { preconditionFailure("Unkeyed coding is unsupported.") } - let pointer = UnsafeMutableRawPointer.allocate(bytes: MemoryLayout.stride * 6, alignedTo: 1) + let pointer = UnsafeMutableRawPointer.allocate(byteCount: MemoryLayout.stride * 6, alignment: 1) defer { - pointer.deallocate(bytes: MemoryLayout.stride * 6, alignedTo: 1) + pointer.deallocate() } aDecoder.decodeValue(ofObjCType: "[6f]", at: pointer) diff --git a/Foundation/Data.swift b/Foundation/Data.swift index 41eebb287c..82f7479434 100644 --- a/Foundation/Data.swift +++ b/Foundation/Data.swift @@ -153,7 +153,7 @@ public final class _DataStorage { } return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len))) } else { - var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count) + var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout.alignment) defer { buffer.deallocate() } let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count) var enumerated = 0 @@ -184,7 +184,7 @@ public final class _DataStorage { } return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len))) } else { - var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count) + var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout.alignment) defer { buffer.deallocate() } let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count) var enumerated = 0 diff --git a/Foundation/Dictionary.swift b/Foundation/Dictionary.swift index 0237012908..8d8981b505 100644 --- a/Foundation/Dictionary.swift +++ b/Foundation/Dictionary.swift @@ -30,8 +30,8 @@ extension Dictionary : _ObjectTypeBridgeable { keyBuffer.deinitialize(count: count) valueBuffer.deinitialize(count: count) - keyBuffer.deallocate(capacity: count) - valueBuffer.deallocate(capacity: count) + keyBuffer.deallocate() + valueBuffer.deallocate() return dict @@ -75,8 +75,8 @@ extension Dictionary : _ObjectTypeBridgeable { } keys.deinitialize(count: cnt) values.deinitialize(count: cnt) - keys.deallocate(capacity: cnt) - values.deallocate(capacity: cnt) + keys.deallocate() + values.deallocate() } if !failedConversion { result = dict diff --git a/Foundation/FileManager.swift b/Foundation/FileManager.swift index 0148a38c7a..3028d472c5 100644 --- a/Foundation/FileManager.swift +++ b/Foundation/FileManager.swift @@ -462,7 +462,7 @@ open class FileManager : NSObject { ps.advanced(by: 1).initialize(to: nil) let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil) ps.deinitialize(count: 2) - ps.deallocate(capacity: 2) + ps.deallocate() if stream != nil { defer { @@ -682,7 +682,7 @@ open class FileManager : NSObject { } if !path._nsObject.getFileSystemRepresentation(buf, maxLength: len) { buf.deinitialize(count: len) - buf.deallocate(capacity: len) + buf.deallocate() fatalError("string could not be converted") } return UnsafePointer(buf) @@ -1038,7 +1038,7 @@ extension FileManager { ps.advanced(by: 1).initialize(to: nil) _stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil) ps.deinitialize(count: 2) - ps.deallocate(capacity: 2) + ps.deallocate() } else { _rootError = _NSErrorWithErrno(ENOENT, reading: true, url: url) } diff --git a/Foundation/Host.swift b/Foundation/Host.swift index 2a41f68071..ba0aefd08f 100644 --- a/Foundation/Host.swift +++ b/Foundation/Host.swift @@ -42,8 +42,7 @@ open class Host: NSObject { static internal func currentHostName() -> String { let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { - hname.deinitialize() - hname.deallocate(capacity: Int(NI_MAXHOST)) + hname.deallocate() } let r = gethostname(hname, Int(NI_MAXHOST)) if r < 0 || hname[0] == 0 { @@ -80,8 +79,7 @@ open class Host: NSObject { let address = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { freeifaddrs(ifaddr) - address.deinitialize() - address.deallocate(capacity: Int(NI_MAXHOST)) + address.deallocate() } while let ifaValue = ifa?.pointee { if let ifa_addr = ifaValue.ifa_addr, ifaValue.ifa_flags & UInt32(IFF_LOOPBACK) == 0 { @@ -138,8 +136,7 @@ open class Host: NSObject { var res: UnsafeMutablePointer? = res0 let host = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { - host.deinitialize() - host.deallocate(capacity: Int(NI_MAXHOST)) + host.deallocate() } while res != nil { let info = res!.pointee @@ -186,4 +183,3 @@ open class Host: NSObject { return nil } } - diff --git a/Foundation/JSONSerialization.swift b/Foundation/JSONSerialization.swift index 3575fcaf0e..7cd40d1128 100644 --- a/Foundation/JSONSerialization.swift +++ b/Foundation/JSONSerialization.swift @@ -820,9 +820,9 @@ private struct JSONReader { let startPointer = buffer.baseAddress! let intEndPointer = UnsafeMutablePointer?>.allocate(capacity: 1) - defer { intEndPointer.deallocate(capacity: 1) } + defer { intEndPointer.deallocate() } let doubleEndPointer = UnsafeMutablePointer?>.allocate(capacity: 1) - defer { doubleEndPointer.deallocate(capacity: 1) } + defer { doubleEndPointer.deallocate() } let intResult = strtol(startPointer, intEndPointer, 10) let intDistance = startPointer.distance(to: intEndPointer[0]!) let doubleResult = strtod(startPointer, doubleEndPointer) diff --git a/Foundation/NSArray.swift b/Foundation/NSArray.swift index 33b4b015b7..707b4fe8cc 100644 --- a/Foundation/NSArray.swift +++ b/Foundation/NSArray.swift @@ -148,7 +148,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo buffer.initialize(from: optionalArray, count: cnt) self.init(objects: buffer, count: cnt) buffer.deinitialize(count: cnt) - buffer.deallocate(capacity: cnt) + buffer.deallocate() } open override func isEqual(_ value: Any?) -> Bool { @@ -404,7 +404,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo } } return Data(bytesNoCopy: buffer, count: size, deallocator: .custom({ (_, _) in - buffer.deallocate(capacity: size) + buffer.deallocate() })) } diff --git a/Foundation/NSCFDictionary.swift b/Foundation/NSCFDictionary.swift index 18164130de..07eb183204 100644 --- a/Foundation/NSCFDictionary.swift +++ b/Foundation/NSCFDictionary.swift @@ -71,8 +71,8 @@ internal final class _NSCFDictionary : NSMutableDictionary { let key = unsafeBitCast(keys.advanced(by: idx).pointee!, to: NSObject.self) keyArray.append(key) } - keys.deinitialize() - keys.deallocate(capacity: count) + keys.deinitialize(count: 1) + keys.deallocate() } } diff --git a/Foundation/NSCFSet.swift b/Foundation/NSCFSet.swift index 9c21377ee7..8db8ebde00 100644 --- a/Foundation/NSCFSet.swift +++ b/Foundation/NSCFSet.swift @@ -58,8 +58,8 @@ internal final class _NSCFSet : NSMutableSet { let obj = unsafeBitCast(objects.advanced(by: idx).pointee!, to: AnyObject.self) objArray.append(obj) } - objects.deinitialize() - objects.deallocate(capacity: count) + objects.deinitialize(count: 1) + objects.deallocate() return NSGeneratorEnumerator(objArray.makeIterator()) diff --git a/Foundation/NSCoder.swift b/Foundation/NSCoder.swift index 90fe7e5c69..688b0969bb 100644 --- a/Foundation/NSCoder.swift +++ b/Foundation/NSCoder.swift @@ -105,7 +105,7 @@ open class NSCoder : NSObject { deinit { for buffer in _pendingBuffers { // Cannot deinitialize a pointer to unknown type. - buffer.0.deallocate(bytes: buffer.1, alignedTo: MemoryLayout.alignment) + buffer.0.deallocate() } } @@ -383,7 +383,7 @@ open class NSCoder : NSObject { decodeValue(ofObjCType: "I", at: unsafeBitCast(ptr, to: UnsafeMutableRawPointer.self)) } // we cannot autorelease here so instead the pending buffers will manage the lifespan of the returned data... this is wasteful but good enough... - let result = UnsafeMutableRawPointer.allocate(bytes: Int(length), alignedTo: MemoryLayout.alignment) + let result = UnsafeMutableRawPointer.allocate(byteCount: Int(length), alignment: MemoryLayout.alignment) decodeValue(ofObjCType: "c", at: result) lengthp.pointee = Int(length) _pendingBuffers.append((result, Int(length))) diff --git a/Foundation/NSConcreteValue.swift b/Foundation/NSConcreteValue.swift index eccb14e334..aa54316aaa 100644 --- a/Foundation/NSConcreteValue.swift +++ b/Foundation/NSConcreteValue.swift @@ -91,17 +91,17 @@ internal class NSConcreteValue : NSValue { self._typeInfo = typeInfo! - self._storage = UnsafeMutableRawPointer.allocate(bytes: self._typeInfo.size, alignedTo: 1) - self._storage.copyBytes(from: value, count: self._typeInfo.size) + self._storage = UnsafeMutableRawPointer.allocate(byteCount: self._typeInfo.size, alignment: 1) + self._storage.copyMemory(from: value, byteCount: self._typeInfo.size) } deinit { // Cannot deinitialize raw memory. - self._storage.deallocate(bytes: self._size, alignedTo: 1) + self._storage.deallocate() } override func getValue(_ value: UnsafeMutableRawPointer) { - value.copyBytes(from: self._storage, count: self._size) + value.copyMemory(from: self._storage, byteCount: self._size) } override var objCType : UnsafePointer { diff --git a/Foundation/NSDictionary.swift b/Foundation/NSDictionary.swift index 18392f49d8..4dd44e675c 100644 --- a/Foundation/NSDictionary.swift +++ b/Foundation/NSDictionary.swift @@ -154,8 +154,8 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, keyBuffer.deinitialize(count: keys.count) valueBuffer.deinitialize(count: objects.count) - keyBuffer.deallocate(capacity: keys.count) - valueBuffer.deallocate(capacity: objects.count) + keyBuffer.deallocate() + valueBuffer.deallocate() } public convenience init(dictionary otherDictionary: [AnyHashable : Any]) { diff --git a/Foundation/NSGeometry.swift b/Foundation/NSGeometry.swift index 3420df6c8e..8519b62614 100644 --- a/Foundation/NSGeometry.swift +++ b/Foundation/NSGeometry.swift @@ -70,7 +70,7 @@ extension CGPoint: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: CGPoint.self, to: self) + value.initializeMemory(as: CGPoint.self, repeating: self, count: 1) } func isEqual(_ aValue: Any) -> Bool { @@ -162,7 +162,7 @@ extension CGSize: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: CGSize.self, to: self) + value.initializeMemory(as: CGSize.self, repeating: self, count: 1) } func isEqual(_ aValue: Any) -> Bool { @@ -466,7 +466,7 @@ extension CGRect: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: CGRect.self, to: self) + value.initializeMemory(as: CGRect.self, repeating: self, count: 1) } func isEqual(_ aValue: Any) -> Bool { @@ -565,7 +565,7 @@ extension NSEdgeInsets: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: NSEdgeInsets.self, to: self) + value.initializeMemory(as: NSEdgeInsets.self, repeating: self, count: 1) } func isEqual(_ aValue: Any) -> Bool { diff --git a/Foundation/NSKeyedCoderOldStyleArray.swift b/Foundation/NSKeyedCoderOldStyleArray.swift index 1d83e23e17..98450b8510 100644 --- a/Foundation/NSKeyedCoderOldStyleArray.swift +++ b/Foundation/NSKeyedCoderOldStyleArray.swift @@ -41,7 +41,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC deinit { if self._decoded { // Cannot deinitialize memory without knowing the element type. - self._addr.deallocate(bytes: self._count * self._size, alignedTo: 1) + self._addr.deallocate() } } @@ -61,7 +61,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC return nil } - self._addr = UnsafeMutableRawPointer.allocate(bytes: self._count * self._size, alignedTo: 1) + self._addr = UnsafeMutableRawPointer.allocate(byteCount: self._count * self._size, alignment: 1) super.init() @@ -95,7 +95,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC func fillObjCType(_ type: _NSSimpleObjCType, count: Int, at addr: UnsafeMutableRawPointer) { if type == self._type && count <= self._count { - addr.copyBytes(from: self._addr, count: count * self._size) + addr.copyMemory(from: self._addr, byteCount: count * self._size) } } diff --git a/Foundation/NSLock.swift b/Foundation/NSLock.swift index 886b5ba796..0ecb4d9e2e 100644 --- a/Foundation/NSLock.swift +++ b/Foundation/NSLock.swift @@ -46,8 +46,8 @@ open class NSLock: NSObject, NSLocking { deinit { pthread_mutex_destroy(mutex) - mutex.deinitialize() - mutex.deallocate(capacity: 1) + mutex.deinitialize(count: 1) + mutex.deallocate() #if os(OSX) || os(iOS) deallocateTimedLockData(cond: timeoutCond, mutex: timeoutMutex) #endif @@ -196,8 +196,8 @@ open class NSRecursiveLock: NSObject, NSLocking { deinit { pthread_mutex_destroy(mutex) - mutex.deinitialize() - mutex.deallocate(capacity: 1) + mutex.deinitialize(count: 1) + mutex.deallocate() #if os(OSX) || os(iOS) deallocateTimedLockData(cond: timeoutCond, mutex: timeoutMutex) #endif @@ -251,10 +251,10 @@ open class NSCondition: NSObject, NSLocking { deinit { pthread_mutex_destroy(mutex) pthread_cond_destroy(cond) - mutex.deinitialize() - cond.deinitialize() - mutex.deallocate(capacity: 1) - cond.deallocate(capacity: 1) + mutex.deinitialize(count: 1) + cond.deinitialize(count: 1) + mutex.deallocate() + cond.deallocate() } open func lock() { diff --git a/Foundation/NSOrderedSet.swift b/Foundation/NSOrderedSet.swift index 9d76f93a24..419dcfd6d1 100644 --- a/Foundation/NSOrderedSet.swift +++ b/Foundation/NSOrderedSet.swift @@ -302,7 +302,7 @@ extension NSOrderedSet { } self.init(objects: buffer, count: array.count) buffer.deinitialize(count: array.count) - buffer.deallocate(capacity: array.count) + buffer.deallocate() } public convenience init(array set: [Any], copyItems flag: Bool) { diff --git a/Foundation/NSRange.swift b/Foundation/NSRange.swift index 91a8aba8a6..5e998d9635 100644 --- a/Foundation/NSRange.swift +++ b/Foundation/NSRange.swift @@ -400,7 +400,7 @@ extension NSRange: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: NSRange.self, to: self) + value.initializeMemory(as: NSRange.self, repeating: self, count: 1) } func isEqual(_ aValue: Any) -> Bool { @@ -426,4 +426,3 @@ extension NSValue { } } #endif - diff --git a/Foundation/NSSet.swift b/Foundation/NSSet.swift index 939c3580ad..81aeaccf19 100644 --- a/Foundation/NSSet.swift +++ b/Foundation/NSSet.swift @@ -135,7 +135,7 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi } self.init(objects: buffer, count: array.count) buffer.deinitialize(count: array.count) - buffer.deallocate(capacity: array.count) + buffer.deallocate() } public convenience init(set: Set) { diff --git a/Foundation/NSString.swift b/Foundation/NSString.swift index 9352c7d1a1..ccf057667f 100644 --- a/Foundation/NSString.swift +++ b/Foundation/NSString.swift @@ -247,8 +247,8 @@ open class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSC let characters = UnsafeMutablePointer.allocate(capacity: length) getCharacters(characters, range: NSMakeRange(0, length)) let result = NSMutableString(characters: characters, length: length) - characters.deinitialize() - characters.deallocate(capacity: length) + characters.deinitialize(count: 1) + characters.deallocate() return result } @@ -364,8 +364,8 @@ extension NSString { let buff = UnsafeMutablePointer.allocate(capacity: range.length) getCharacters(buff, range: range) let result = String(describing: buff) - buff.deinitialize() - buff.deallocate(capacity: range.length) + buff.deinitialize(count: 1) + buff.deallocate() return result } } diff --git a/Foundation/NSSwiftRuntime.swift b/Foundation/NSSwiftRuntime.swift index 33112a8913..02da8d6805 100644 --- a/Foundation/NSSwiftRuntime.swift +++ b/Foundation/NSSwiftRuntime.swift @@ -342,7 +342,7 @@ extension Array { let buffer = UnsafeMutablePointer.allocate(capacity: count) let res = body(buffer) buffer.deinitialize(count: count) - buffer.deallocate(capacity: count) + buffer.deallocate() return res } else { return withUnsafeMutableBufferPointer() { (bufferPtr: inout UnsafeMutableBufferPointer) -> R in diff --git a/Foundation/NSUUID.swift b/Foundation/NSUUID.swift index 63e330b817..6b8fe8680a 100644 --- a/Foundation/NSUUID.swift +++ b/Foundation/NSUUID.swift @@ -20,8 +20,8 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding { internal var buffer = UnsafeMutablePointer.allocate(capacity: 16) deinit { - buffer.deinitialize() - buffer.deallocate(capacity: 16) + buffer.deinitialize(count: 1) + buffer.deallocate() } public override init() { @@ -31,8 +31,8 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding { public convenience init?(uuidString string: String) { let buffer = UnsafeMutablePointer.allocate(capacity: 16) defer { - buffer.deinitialize() - buffer.deallocate(capacity: 16) + buffer.deinitialize(count: 1) + buffer.deallocate() } if _cf_uuid_parse(string, buffer) != 0 { return nil @@ -51,8 +51,8 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding { open var uuidString: String { let strPtr = UnsafeMutablePointer.allocate(capacity: 37) defer { - strPtr.deinitialize() - strPtr.deallocate(capacity: 37) + strPtr.deinitialize(count: 1) + strPtr.deallocate() } _cf_uuid_unparse_upper(buffer, strPtr) return String(cString: strPtr) @@ -83,8 +83,8 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding { guard data.count == 16 else { return nil } let buffer = UnsafeMutablePointer.allocate(capacity: 16) defer { - buffer.deinitialize() - buffer.deallocate(capacity: 16) + buffer.deinitialize(count: 1) + buffer.deallocate() } data.copyBytes(to: buffer, count: 16) self.init(uuidBytes: buffer) diff --git a/Foundation/Process.swift b/Foundation/Process.swift index 7ff80dc4fd..380200bc5d 100644 --- a/Foundation/Process.swift +++ b/Foundation/Process.swift @@ -233,7 +233,7 @@ open class Process: NSObject { free(UnsafeMutableRawPointer(arg.pointee)) } - argv.deallocate(capacity: args.count + 1) + argv.deallocate() } let envp: UnsafeMutablePointer?> @@ -252,7 +252,7 @@ open class Process: NSObject { for pair in envp ..< envp + env.count { free(UnsafeMutableRawPointer(pair.pointee)) } - envp.deallocate(capacity: env.count + 1) + envp.deallocate() } } diff --git a/Foundation/Set.swift b/Foundation/Set.swift index 763b47c85d..1db2f1048f 100644 --- a/Foundation/Set.swift +++ b/Foundation/Set.swift @@ -21,7 +21,7 @@ extension Set : _ObjectTypeBridgeable { let set = NSSet(objects: buffer, count: count) buffer.deinitialize(count: count) - buffer.deallocate(capacity: count) + buffer.deallocate() return set } @@ -67,7 +67,7 @@ extension Set : _ObjectTypeBridgeable { } } objs.deinitialize(count: cnt) - objs.deallocate(capacity: cnt) + objs.deallocate() } if !failedConversion { result = set diff --git a/Foundation/String.swift b/Foundation/String.swift index f9a4ca8f71..07b0bb95f0 100644 --- a/Foundation/String.swift +++ b/Foundation/String.swift @@ -39,7 +39,7 @@ extension String : _ObjectTypeBridgeable { let str = String._fromCodeUnitSequence(UTF16.self, input: UnsafeBufferPointer(start: buffer, count: length)) buffer.deinitialize(count: length) - buffer.deallocate(capacity: length) + buffer.deallocate() result = str } } else if type(of: source) == _NSCFConstantString.self { @@ -67,4 +67,3 @@ extension String : _ObjectTypeBridgeable { } } } - diff --git a/Foundation/Thread.swift b/Foundation/Thread.swift index 14899694b3..c1709b7a06 100644 --- a/Foundation/Thread.swift +++ b/Foundation/Thread.swift @@ -259,7 +259,7 @@ open class Thread : NSObject { // Same as swift/stdlib/public/runtime/Errors.cpp backtrace let maxSupportedStackDepth = 128; let addrs = UnsafeMutablePointer.allocate(capacity: maxSupportedStackDepth) - defer { addrs.deallocate(capacity: maxSupportedStackDepth) } + defer { addrs.deallocate() } #if os(Android) let count = 0 #else diff --git a/TestFoundation/TestNSKeyedArchiver.swift b/TestFoundation/TestNSKeyedArchiver.swift index 4ccc05eea7..92de26099f 100644 --- a/TestFoundation/TestNSKeyedArchiver.swift +++ b/TestFoundation/TestNSKeyedArchiver.swift @@ -288,7 +288,7 @@ class TestNSKeyedArchiver : XCTestCase { // On Darwin decoded strings would belong to the autorelease pool, but as we don't have // one in SwiftFoundation let's explicitly deallocate it here. - expectedCharPtr!.deallocate(capacity: charArray.count) + expectedCharPtr!.deallocate() return s1 == s2 })