From 62fcab15ac2b04bfc992ef5a856d754f56f6626d Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 18 Nov 2017 10:22:17 -0500 Subject: [PATCH] Revert "Merge pull request #1247 from kelvin13/se-0184a" This reverts commit 1b12e8368fb5930f5e7cc0b6136e9a87a479f77d, reversing changes made to c13b850c9351e3d98cef8f39d4d0e506e3ef315f. --- Foundation/AffineTransform.swift | 4 ++-- Foundation/Data.swift | 4 ++-- Foundation/Dictionary.swift | 8 ++++---- Foundation/FileManager.swift | 6 +++--- Foundation/Host.swift | 10 +++++++--- Foundation/JSONSerialization.swift | 4 ++-- Foundation/NSArray.swift | 4 ++-- Foundation/NSCFDictionary.swift | 4 ++-- Foundation/NSCFSet.swift | 4 ++-- Foundation/NSCoder.swift | 4 ++-- Foundation/NSConcreteValue.swift | 8 ++++---- Foundation/NSDictionary.swift | 4 ++-- Foundation/NSGeometry.swift | 8 ++++---- Foundation/NSKeyedCoderOldStyleArray.swift | 6 +++--- Foundation/NSLock.swift | 16 ++++++++-------- Foundation/NSOrderedSet.swift | 2 +- Foundation/NSRange.swift | 3 ++- Foundation/NSSet.swift | 2 +- Foundation/NSString.swift | 8 ++++---- Foundation/NSSwiftRuntime.swift | 2 +- Foundation/NSUUID.swift | 16 ++++++++-------- Foundation/Process.swift | 4 ++-- Foundation/Set.swift | 4 ++-- Foundation/String.swift | 3 ++- Foundation/Thread.swift | 2 +- TestFoundation/TestNSKeyedArchiver.swift | 2 +- 26 files changed, 74 insertions(+), 68 deletions(-) diff --git a/Foundation/AffineTransform.swift b/Foundation/AffineTransform.swift index 703278930e..845c5df620 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(byteCount: MemoryLayout.stride * 6, alignment: 1) + let pointer = UnsafeMutableRawPointer.allocate(bytes: MemoryLayout.stride * 6, alignedTo: 1) defer { - pointer.deallocate() + pointer.deallocate(bytes: MemoryLayout.stride * 6, alignedTo: 1) } aDecoder.decodeValue(ofObjCType: "[6f]", at: pointer) diff --git a/Foundation/Data.swift b/Foundation/Data.swift index 82f7479434..41eebb287c 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(byteCount: range.count, alignment: MemoryLayout.alignment) + var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count) 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(byteCount: range.count, alignment: MemoryLayout.alignment) + var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count) 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 8d8981b505..0237012908 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() - valueBuffer.deallocate() + keyBuffer.deallocate(capacity: count) + valueBuffer.deallocate(capacity: count) return dict @@ -75,8 +75,8 @@ extension Dictionary : _ObjectTypeBridgeable { } keys.deinitialize(count: cnt) values.deinitialize(count: cnt) - keys.deallocate() - values.deallocate() + keys.deallocate(capacity: cnt) + values.deallocate(capacity: cnt) } if !failedConversion { result = dict diff --git a/Foundation/FileManager.swift b/Foundation/FileManager.swift index 3028d472c5..0148a38c7a 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() + ps.deallocate(capacity: 2) 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() + buf.deallocate(capacity: len) 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() + ps.deallocate(capacity: 2) } else { _rootError = _NSErrorWithErrno(ENOENT, reading: true, url: url) } diff --git a/Foundation/Host.swift b/Foundation/Host.swift index a59d4480f5..64b979d34a 100644 --- a/Foundation/Host.swift +++ b/Foundation/Host.swift @@ -42,7 +42,8 @@ open class Host: NSObject { static internal func currentHostName() -> String { let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { - hname.deallocate() + hname.deinitialize() + hname.deallocate(capacity: Int(NI_MAXHOST)) } let r = gethostname(hname, Int(NI_MAXHOST)) if r < 0 || hname[0] == 0 { @@ -79,7 +80,8 @@ open class Host: NSObject { let address = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { freeifaddrs(ifaddr) - address.deallocate() + address.deinitialize() + address.deallocate(capacity: Int(NI_MAXHOST)) } while let ifaValue = ifa?.pointee { if let ifa_addr = ifaValue.ifa_addr, ifaValue.ifa_flags & UInt32(IFF_LOOPBACK) == 0 { @@ -135,7 +137,8 @@ open class Host: NSObject { var res: UnsafeMutablePointer? = res0 let host = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { - host.deallocate() + host.deinitialize() + host.deallocate(capacity: Int(NI_MAXHOST)) } while res != nil { let info = res!.pointee @@ -181,3 +184,4 @@ open class Host: NSObject { return nil } } + diff --git a/Foundation/JSONSerialization.swift b/Foundation/JSONSerialization.swift index 7cd40d1128..3575fcaf0e 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() } + defer { intEndPointer.deallocate(capacity: 1) } let doubleEndPointer = UnsafeMutablePointer?>.allocate(capacity: 1) - defer { doubleEndPointer.deallocate() } + defer { doubleEndPointer.deallocate(capacity: 1) } 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 707b4fe8cc..33b4b015b7 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() + buffer.deallocate(capacity: cnt) } 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() + buffer.deallocate(capacity: size) })) } diff --git a/Foundation/NSCFDictionary.swift b/Foundation/NSCFDictionary.swift index 07eb183204..18164130de 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(count: 1) - keys.deallocate() + keys.deinitialize() + keys.deallocate(capacity: count) } } diff --git a/Foundation/NSCFSet.swift b/Foundation/NSCFSet.swift index 8db8ebde00..9c21377ee7 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(count: 1) - objects.deallocate() + objects.deinitialize() + objects.deallocate(capacity: count) return NSGeneratorEnumerator(objArray.makeIterator()) diff --git a/Foundation/NSCoder.swift b/Foundation/NSCoder.swift index 688b0969bb..90fe7e5c69 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() + buffer.0.deallocate(bytes: buffer.1, alignedTo: MemoryLayout.alignment) } } @@ -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(byteCount: Int(length), alignment: MemoryLayout.alignment) + let result = UnsafeMutableRawPointer.allocate(bytes: Int(length), alignedTo: 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 aa54316aaa..eccb14e334 100644 --- a/Foundation/NSConcreteValue.swift +++ b/Foundation/NSConcreteValue.swift @@ -91,17 +91,17 @@ internal class NSConcreteValue : NSValue { self._typeInfo = typeInfo! - self._storage = UnsafeMutableRawPointer.allocate(byteCount: self._typeInfo.size, alignment: 1) - self._storage.copyMemory(from: value, byteCount: self._typeInfo.size) + self._storage = UnsafeMutableRawPointer.allocate(bytes: self._typeInfo.size, alignedTo: 1) + self._storage.copyBytes(from: value, count: self._typeInfo.size) } deinit { // Cannot deinitialize raw memory. - self._storage.deallocate() + self._storage.deallocate(bytes: self._size, alignedTo: 1) } override func getValue(_ value: UnsafeMutableRawPointer) { - value.copyMemory(from: self._storage, byteCount: self._size) + value.copyBytes(from: self._storage, count: self._size) } override var objCType : UnsafePointer { diff --git a/Foundation/NSDictionary.swift b/Foundation/NSDictionary.swift index 4dd44e675c..18392f49d8 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() - valueBuffer.deallocate() + keyBuffer.deallocate(capacity: keys.count) + valueBuffer.deallocate(capacity: objects.count) } public convenience init(dictionary otherDictionary: [AnyHashable : Any]) { diff --git a/Foundation/NSGeometry.swift b/Foundation/NSGeometry.swift index 8519b62614..3420df6c8e 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, repeating: self, count: 1) + value.initializeMemory(as: CGPoint.self, to: self) } func isEqual(_ aValue: Any) -> Bool { @@ -162,7 +162,7 @@ extension CGSize: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: CGSize.self, repeating: self, count: 1) + value.initializeMemory(as: CGSize.self, to: self) } func isEqual(_ aValue: Any) -> Bool { @@ -466,7 +466,7 @@ extension CGRect: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: CGRect.self, repeating: self, count: 1) + value.initializeMemory(as: CGRect.self, to: self) } func isEqual(_ aValue: Any) -> Bool { @@ -565,7 +565,7 @@ extension NSEdgeInsets: NSSpecialValueCoding { } func getValue(_ value: UnsafeMutableRawPointer) { - value.initializeMemory(as: NSEdgeInsets.self, repeating: self, count: 1) + value.initializeMemory(as: NSEdgeInsets.self, to: self) } func isEqual(_ aValue: Any) -> Bool { diff --git a/Foundation/NSKeyedCoderOldStyleArray.swift b/Foundation/NSKeyedCoderOldStyleArray.swift index 98450b8510..1d83e23e17 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() + self._addr.deallocate(bytes: self._count * self._size, alignedTo: 1) } } @@ -61,7 +61,7 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC return nil } - self._addr = UnsafeMutableRawPointer.allocate(byteCount: self._count * self._size, alignment: 1) + self._addr = UnsafeMutableRawPointer.allocate(bytes: self._count * self._size, alignedTo: 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.copyMemory(from: self._addr, byteCount: count * self._size) + addr.copyBytes(from: self._addr, count: count * self._size) } } diff --git a/Foundation/NSLock.swift b/Foundation/NSLock.swift index 0ecb4d9e2e..886b5ba796 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(count: 1) - mutex.deallocate() + mutex.deinitialize() + mutex.deallocate(capacity: 1) #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(count: 1) - mutex.deallocate() + mutex.deinitialize() + mutex.deallocate(capacity: 1) #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(count: 1) - cond.deinitialize(count: 1) - mutex.deallocate() - cond.deallocate() + mutex.deinitialize() + cond.deinitialize() + mutex.deallocate(capacity: 1) + cond.deallocate(capacity: 1) } open func lock() { diff --git a/Foundation/NSOrderedSet.swift b/Foundation/NSOrderedSet.swift index 419dcfd6d1..9d76f93a24 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() + buffer.deallocate(capacity: array.count) } public convenience init(array set: [Any], copyItems flag: Bool) { diff --git a/Foundation/NSRange.swift b/Foundation/NSRange.swift index 5e998d9635..91a8aba8a6 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, repeating: self, count: 1) + value.initializeMemory(as: NSRange.self, to: self) } func isEqual(_ aValue: Any) -> Bool { @@ -426,3 +426,4 @@ extension NSValue { } } #endif + diff --git a/Foundation/NSSet.swift b/Foundation/NSSet.swift index 81aeaccf19..939c3580ad 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() + buffer.deallocate(capacity: array.count) } public convenience init(set: Set) { diff --git a/Foundation/NSString.swift b/Foundation/NSString.swift index ccf057667f..9352c7d1a1 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(count: 1) - characters.deallocate() + characters.deinitialize() + characters.deallocate(capacity: length) 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(count: 1) - buff.deallocate() + buff.deinitialize() + buff.deallocate(capacity: range.length) return result } } diff --git a/Foundation/NSSwiftRuntime.swift b/Foundation/NSSwiftRuntime.swift index 02da8d6805..33112a8913 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() + buffer.deallocate(capacity: count) return res } else { return withUnsafeMutableBufferPointer() { (bufferPtr: inout UnsafeMutableBufferPointer) -> R in diff --git a/Foundation/NSUUID.swift b/Foundation/NSUUID.swift index 6b8fe8680a..63e330b817 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(count: 1) - buffer.deallocate() + buffer.deinitialize() + buffer.deallocate(capacity: 16) } 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(count: 1) - buffer.deallocate() + buffer.deinitialize() + buffer.deallocate(capacity: 16) } 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(count: 1) - strPtr.deallocate() + strPtr.deinitialize() + strPtr.deallocate(capacity: 37) } _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(count: 1) - buffer.deallocate() + buffer.deinitialize() + buffer.deallocate(capacity: 16) } data.copyBytes(to: buffer, count: 16) self.init(uuidBytes: buffer) diff --git a/Foundation/Process.swift b/Foundation/Process.swift index 380200bc5d..7ff80dc4fd 100644 --- a/Foundation/Process.swift +++ b/Foundation/Process.swift @@ -233,7 +233,7 @@ open class Process: NSObject { free(UnsafeMutableRawPointer(arg.pointee)) } - argv.deallocate() + argv.deallocate(capacity: args.count + 1) } let envp: UnsafeMutablePointer?> @@ -252,7 +252,7 @@ open class Process: NSObject { for pair in envp ..< envp + env.count { free(UnsafeMutableRawPointer(pair.pointee)) } - envp.deallocate() + envp.deallocate(capacity: env.count + 1) } } diff --git a/Foundation/Set.swift b/Foundation/Set.swift index 1db2f1048f..763b47c85d 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() + buffer.deallocate(capacity: count) return set } @@ -67,7 +67,7 @@ extension Set : _ObjectTypeBridgeable { } } objs.deinitialize(count: cnt) - objs.deallocate() + objs.deallocate(capacity: cnt) } if !failedConversion { result = set diff --git a/Foundation/String.swift b/Foundation/String.swift index 07b0bb95f0..f9a4ca8f71 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() + buffer.deallocate(capacity: length) result = str } } else if type(of: source) == _NSCFConstantString.self { @@ -67,3 +67,4 @@ extension String : _ObjectTypeBridgeable { } } } + diff --git a/Foundation/Thread.swift b/Foundation/Thread.swift index c1709b7a06..14899694b3 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() } + defer { addrs.deallocate(capacity: maxSupportedStackDepth) } #if os(Android) let count = 0 #else diff --git a/TestFoundation/TestNSKeyedArchiver.swift b/TestFoundation/TestNSKeyedArchiver.swift index 92de26099f..4ccc05eea7 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() + expectedCharPtr!.deallocate(capacity: charArray.count) return s1 == s2 })