From fdbf76e9f5437add8082e26392fbd4f032307f3d Mon Sep 17 00:00:00 2001 From: Mishal Shah Date: Thu, 25 Jan 2018 16:03:11 -0800 Subject: [PATCH] Update master to build with Xcode 9.3 beta 1 --- README.md | 2 +- stdlib/public/SDK/ARKit/ARKit.swift | 57 +++++++++++++++++-- stdlib/public/SDK/Foundation/NSCoder.swift | 19 +++++++ .../public/SwiftShims/NSKeyedArchiverShims.h | 15 ++++- test/stdlib/DispatchRenames.swift | 6 +- test/stdlib/Foundation_NewGenericAPIs.swift | 12 ++++ test/stdlib/NSKeyedArchival.swift | 51 ++++++++++++++++- 7 files changed, 153 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 685586ba5f6..54819c2f451 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ supported host development operating systems. #### macOS -To build for macOS, you need [Xcode 9.2](https://developer.apple.com/xcode/downloads/). +To build for macOS, you need [Xcode 9.3 beta](https://developer.apple.com/xcode/downloads/). The required version of Xcode changes frequently, and is often a beta release. Check this document or the host information on for the current required version. diff --git a/stdlib/public/SDK/ARKit/ARKit.swift b/stdlib/public/SDK/ARKit/ARKit.swift index a2baa6a286d..6e776547f7c 100644 --- a/stdlib/public/SDK/ARKit/ARKit.swift +++ b/stdlib/public/SDK/ARKit/ARKit.swift @@ -27,6 +27,10 @@ extension ARCamera { /** Tracking is limited due to a lack of features visible to the camera. */ case insufficientFeatures + + /** Tracking is limited due to a relocalization in progress. */ + @available(iOS, introduced: 11.3) + case relocalizing } /** Tracking is not available. */ @@ -49,10 +53,20 @@ extension ARCamera { case .limited: let reason: TrackingState.Reason - switch __trackingStateReason { - case .initializing: reason = .initializing - case .excessiveMotion: reason = .excessiveMotion - default: reason = .insufficientFeatures + if #available(iOS 11.3, *) { + switch __trackingStateReason { + case .initializing: reason = .initializing + case .relocalizing: reason = .relocalizing + case .excessiveMotion: reason = .excessiveMotion + default: reason = .insufficientFeatures + } + } + else { + switch __trackingStateReason { + case .initializing: reason = .initializing + case .excessiveMotion: reason = .excessiveMotion + default: reason = .insufficientFeatures + } } return .limited(reason) @@ -105,3 +119,38 @@ extension ARFaceGeometry { return Array(buffer) } } + +@available(iOS, introduced: 11.3) +extension ARPlaneGeometry { + /** + The mesh vertices of the geometry. + */ + @nonobjc public var vertices: [vector_float3] { + let buffer = UnsafeBufferPointer(start: __vertices, count: Int(__vertexCount)) + return Array(buffer) + } + + /** + The texture coordinates of the geometry. + */ + @nonobjc public var textureCoordinates: [vector_float2] { + let buffer = UnsafeBufferPointer(start: __textureCoordinates, count: Int(__textureCoordinateCount)) + return Array(buffer) + } + + /** + The triangle indices of the geometry. + */ + @nonobjc public var triangleIndices: [Int16] { + let buffer = UnsafeBufferPointer(start: __triangleIndices, count: Int(triangleCount * 3)) + return Array(buffer) + } + + /** + The vertices of the geometry's outermost boundary. + */ + @nonobjc public var boundaryVertices: [vector_float3] { + let buffer = UnsafeBufferPointer(start: __boundaryVertices, count: Int(__boundaryVertexCount)) + return Array(buffer) + } +} diff --git a/stdlib/public/SDK/Foundation/NSCoder.swift b/stdlib/public/SDK/Foundation/NSCoder.swift index b64291e34d4..dbc76745fe5 100644 --- a/stdlib/public/SDK/Foundation/NSCoder.swift +++ b/stdlib/public/SDK/Foundation/NSCoder.swift @@ -167,6 +167,25 @@ extension NSKeyedUnarchiver { try resolveError(error) return result } + + @nonobjc + @available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) + public static func unarchivedObject(ofClass cls: DecodedObjectType.Type, from data: Data) throws -> DecodedObjectType? { + var error: NSError? + let result = __NSKeyedUnarchiverSecureUnarchiveObjectOfClass(cls as! AnyClass, data, &error) + try resolveError(error) + return result as? DecodedObjectType + } + + @nonobjc + @available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) + public static func unarchivedObject(ofClasses classes: [AnyClass], from data: Data) throws -> Any? { + var error: NSError? + let classesAsNSObjects = NSSet(array: classes.map { $0 as AnyObject }) + let result = __NSKeyedUnarchiverSecureUnarchiveObjectOfClasses(classesAsNSObjects, data, &error) + try resolveError(error) + return result + } @nonobjc private static let __plistClasses: [AnyClass] = [ diff --git a/stdlib/public/SwiftShims/NSKeyedArchiverShims.h b/stdlib/public/SwiftShims/NSKeyedArchiverShims.h index f9c94025a83..f1467906835 100644 --- a/stdlib/public/SwiftShims/NSKeyedArchiverShims.h +++ b/stdlib/public/SwiftShims/NSKeyedArchiverShims.h @@ -14,7 +14,6 @@ NS_BEGIN_DECLS - NS_INLINE NS_RETURNS_RETAINED _Nullable id __NSKeyedUnarchiverUnarchiveObject(id Self_, NS_NON_BRIDGED(NSData *)data, NSError **_Nullable error) { if (error) { return [Self_ unarchiveTopLevelObjectWithData:(NSData *)data error:error]; @@ -23,4 +22,18 @@ NS_INLINE NS_RETURNS_RETAINED _Nullable id __NSKeyedUnarchiverUnarchiveObject(id } } +// Re-exposed here until all SDKs contain the relevant methods publicly. +@interface NSKeyedUnarchiver (SecureMethods) ++ (nullable id)unarchivedObjectOfClass:(Class)cls fromData:(NSData *)data error:(NSError **)error API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0)); ++ (nullable id)unarchivedObjectOfClasses:(NSSet *)classes fromData:(NSData *)data error:(NSError **)error API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0)); +@end + +NS_INLINE NS_RETURNS_RETAINED id _Nullable __NSKeyedUnarchiverSecureUnarchiveObjectOfClass(Class cls, NSData *data, NSError * _Nullable * _Nullable error) { + return [NSKeyedUnarchiver unarchivedObjectOfClass:cls fromData:data error:error]; +} + +NS_INLINE NS_RETURNS_RETAINED id _Nullable __NSKeyedUnarchiverSecureUnarchiveObjectOfClasses(NS_NON_BRIDGED(NSSet *) classes, NSData *data, NSError * _Nullable * _Nullable error) { + return [NSKeyedUnarchiver unarchivedObjectOfClasses:classes fromData:data error:error]; +} + NS_END_DECLS diff --git a/test/stdlib/DispatchRenames.swift b/test/stdlib/DispatchRenames.swift index 0ea564a83b6..6ed9250df6f 100644 --- a/test/stdlib/DispatchRenames.swift +++ b/test/stdlib/DispatchRenames.swift @@ -11,5 +11,9 @@ _ = dispatch_get_global_queue(0, 0) // expected-error {{'dispatch_get_global_que _ = dispatch_source_create(OpaquePointer(bitPattern: ~0)!, 0, 0, nil) // expected-error {{'dispatch_source_create' is unavailable: Use DispatchSource class methods}} -_ = dispatch_get_main_queue() // expected-error {{'dispatch_get_main_queue()' has been replaced by property 'DispatchQueue.main'}} +// Next test is disabled pending what to do about libdispatch change to the signature of dispatch_get_main_queue(): rdar://problem/36528231. +// To re-enable, remove the #if/#endif and remove "FIXME-" from 'expected-FIXME-error' +#if false +_ = dispatch_get_main_queue() // expected-FIXME-error {{'dispatch_get_main_queue()' has been replaced by property 'DispatchQueue.main'}} +#endif _ = DispatchQueue.main diff --git a/test/stdlib/Foundation_NewGenericAPIs.swift b/test/stdlib/Foundation_NewGenericAPIs.swift index 4e96bfeee8a..dc17c38cb94 100644 --- a/test/stdlib/Foundation_NewGenericAPIs.swift +++ b/test/stdlib/Foundation_NewGenericAPIs.swift @@ -63,3 +63,15 @@ func test_NSKeyedUnarchiver_decodeObjectForKey( expectType(Optional.self, &r) } + +@available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) +func test_NSKeyedUnarchiver_unarchivedObjectOfClass(from data: Data) throws { + var r = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSString.self, from: data) + expectType(NSString?.self, &r) +} + +@available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) +func test_NSKeyedUnarchiver_unarchivedObjectOfClasses(from data: Data) throws { + var r = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSString.self, NSData.self, NSArray.self], from: data) + expectType(Any?.self, &r) +} diff --git a/test/stdlib/NSKeyedArchival.swift b/test/stdlib/NSKeyedArchival.swift index 3175f1b6785..dd85c77cd92 100644 --- a/test/stdlib/NSKeyedArchival.swift +++ b/test/stdlib/NSKeyedArchival.swift @@ -163,21 +163,68 @@ func test_toplevelAPIVariants() { } } +@available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) +func test_unarchiveObjectOfClass() { + let topLevel = NSArray() + let data = NSKeyedArchiver.archivedData(withRootObject: topLevel) + + // Should be able to decode an NSArray back out. + expectNoError { + guard let result = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSArray.self, from: data) else { + expectUnreachable("Unable to decode top-level array.") + return + } + + expectEqual(result, topLevel) + } + + // Shouldn't be able to decode an NSString out of an NSArray. + expectError { + let _ = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSString.self, from: data) + } +} + +@available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) +func test_unarchiveObjectOfClasses() { + let topLevel = NSArray() + let data = NSKeyedArchiver.archivedData(withRootObject: topLevel) + + // Should be able to unarchive an array back out. + expectNoError { + guard let result = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self], from: data) as? NSArray else { + expectUnreachable("Unable to decode top-level array.") + return + } + + expectEqual(result, topLevel) + } + + // Shouldn't be able to decode an NSString out of an NSArray. + expectError { + let _ = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSString.self], from: data) + } +} + // MARK: - Run Tests #if !FOUNDATION_XCTEST if #available(OSX 10.11, iOS 9.0, *) { let NSKeyedArchiverTest = TestSuite("TestNSKeyedArchiver") - let tests = [ + var tests = [ "NSKeyedArchival.simpleCodableSupportInNSKeyedArchival": test_simpleCodableSupport, "NSKeyedArchival.encodableErrorHandling": test_encodableErrorHandling, "NSKeyedArchival.readingNonCodableFromDecodeDecodable": test_readingNonCodableFromDecodeDecodable, "NSKeyedArchival.toplevelAPIVariants": test_toplevelAPIVariants ] + + if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) { + tests["NSKeyedArchival.unarchiveObjectOfClass"] = test_unarchiveObjectOfClass + tests["NSKeyedArchival.unarchiveObjectOfClasses"] = test_unarchiveObjectOfClasses + } for (name, test) in tests { NSKeyedArchiverTest.test(name) { test() } } runAllTests() } -#endif \ No newline at end of file +#endif