Skip to content

Commit caf5f68

Browse files
authored
[Foundation] Correct symbolic availability for CFURL component characer set accessors (#9626)
1 parent 34ad596 commit caf5f68

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed

stdlib/public/SDK/Foundation/CharacterSet.swift

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@_exported import Foundation // Clang module
1414
import CoreFoundation
1515
import _SwiftCoreFoundationOverlayShims
16+
import _SwiftFoundationOverlayShims
1617

1718
private func _utfRangeToCFRange(_ inRange : Range<Unicode.Scalar>) -> CFRange {
1819
return CFRange(
@@ -513,35 +514,59 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
513514
}
514515

515516
// MARK: Static functions, from NSURL
516-
517+
517518
/// Returns the character set for characters allowed in a user URL subcomponent.
518519
public static var urlUserAllowed : CharacterSet {
519-
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLUserAllowedCharacterSet() as NSCharacterSet)
520+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
521+
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLUserAllowedCharacterSet() as NSCharacterSet)
522+
} else {
523+
return CharacterSet(_uncopiedImmutableReference: _NSURLComponentsGetURLUserAllowedCharacterSet() as! NSCharacterSet)
524+
}
520525
}
521526

522527
/// Returns the character set for characters allowed in a password URL subcomponent.
523528
public static var urlPasswordAllowed : CharacterSet {
524-
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLPasswordAllowedCharacterSet() as NSCharacterSet)
529+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
530+
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLPasswordAllowedCharacterSet() as NSCharacterSet)
531+
} else {
532+
return CharacterSet(_uncopiedImmutableReference: _NSURLComponentsGetURLPasswordAllowedCharacterSet() as! NSCharacterSet)
533+
}
525534
}
526535

527536
/// Returns the character set for characters allowed in a host URL subcomponent.
528537
public static var urlHostAllowed : CharacterSet {
529-
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLHostAllowedCharacterSet() as NSCharacterSet)
538+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
539+
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLHostAllowedCharacterSet() as NSCharacterSet)
540+
} else {
541+
return CharacterSet(_uncopiedImmutableReference: _NSURLComponentsGetURLHostAllowedCharacterSet() as! NSCharacterSet)
542+
}
530543
}
531544

532545
/// Returns the character set for characters allowed in a path URL component.
533546
public static var urlPathAllowed : CharacterSet {
534-
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLPathAllowedCharacterSet() as NSCharacterSet)
547+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
548+
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLPathAllowedCharacterSet() as NSCharacterSet)
549+
} else {
550+
return CharacterSet(_uncopiedImmutableReference: _NSURLComponentsGetURLPathAllowedCharacterSet() as! NSCharacterSet)
551+
}
535552
}
536553

537554
/// Returns the character set for characters allowed in a query URL component.
538555
public static var urlQueryAllowed : CharacterSet {
539-
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLQueryAllowedCharacterSet() as NSCharacterSet)
556+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
557+
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLQueryAllowedCharacterSet() as NSCharacterSet)
558+
} else {
559+
return CharacterSet(_uncopiedImmutableReference: _NSURLComponentsGetURLQueryAllowedCharacterSet() as! NSCharacterSet)
560+
}
540561
}
541562

542563
/// Returns the character set for characters allowed in a fragment URL component.
543564
public static var urlFragmentAllowed : CharacterSet {
544-
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLFragmentAllowedCharacterSet() as NSCharacterSet)
565+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
566+
return CharacterSet(_uncopiedImmutableReference: _CFURLComponentsGetURLFragmentAllowedCharacterSet() as NSCharacterSet)
567+
} else {
568+
return CharacterSet(_uncopiedImmutableReference: _NSURLComponentsGetURLFragmentAllowedCharacterSet() as! NSCharacterSet)
569+
}
545570
}
546571

547572
// MARK: Immutable functions

stdlib/public/SwiftShims/CFCharacterSetShims.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ CF_IMPLICIT_BRIDGING_ENABLED
1414
CF_EXTERN_C_BEGIN
1515
_Pragma("clang assume_nonnull begin")
1616

17-
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLUserAllowedCharacterSet();
18-
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLPasswordAllowedCharacterSet();
19-
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLHostAllowedCharacterSet();
20-
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLPathAllowedCharacterSet();
21-
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLQueryAllowedCharacterSet();
22-
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLFragmentAllowedCharacterSet();
17+
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLUserAllowedCharacterSet() API_AVAILABLE(macos(10.12), ios(10.0), watchos(3.0), tvos(10.0));
18+
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLPasswordAllowedCharacterSet() API_AVAILABLE(macos(10.12), ios(10.0), watchos(3.0), tvos(10.0));
19+
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLHostAllowedCharacterSet() API_AVAILABLE(macos(10.12), ios(10.0), watchos(3.0), tvos(10.0));
20+
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLPathAllowedCharacterSet() API_AVAILABLE(macos(10.12), ios(10.0), watchos(3.0), tvos(10.0));
21+
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLQueryAllowedCharacterSet() API_AVAILABLE(macos(10.12), ios(10.0), watchos(3.0), tvos(10.0));
22+
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLFragmentAllowedCharacterSet() API_AVAILABLE(macos(10.12), ios(10.0), watchos(3.0), tvos(10.0));
2323

2424
_Pragma("clang assume_nonnull end")
2525
CF_EXTERN_C_END

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(sources
2929
FoundationOverlayShims.h
3030
FoundationShimSupport.h
3131
NSCalendarShims.h
32+
NSCharacterSetShims.h
3233
NSCoderShims.h
3334
NSDataShims.h
3435
NSDictionaryShims.h

stdlib/public/SwiftShims/FoundationOverlayShims.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#import "FoundationShimSupport.h"
1919
#import "NSCalendarShims.h"
20+
#import "NSCharacterSetShims.h"
2021
#import "NSCoderShims.h"
2122
#import "NSDataShims.h"
2223
#import "NSDictionaryShims.h"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===--- NSCharacterSetShims.h - Foundation declarations for CharacterSet overlay -----===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#import "FoundationShimSupport.h"
14+
15+
NS_BEGIN_DECLS
16+
17+
NS_INLINE NS_RETURNS_RETAINED NS_NON_BRIDGED(NSCharacterSet *) _NSURLComponentsGetURLUserAllowedCharacterSet(void) {
18+
return NSCharacterSet.URLUserAllowedCharacterSet;
19+
}
20+
21+
NS_INLINE NS_RETURNS_RETAINED NS_NON_BRIDGED(NSCharacterSet *) _NSURLComponentsGetURLPasswordAllowedCharacterSet(void) {
22+
return NSCharacterSet.URLPasswordAllowedCharacterSet;
23+
}
24+
25+
NS_INLINE NS_RETURNS_RETAINED NS_NON_BRIDGED(NSCharacterSet *) _NSURLComponentsGetURLHostAllowedCharacterSet(void) {
26+
return NSCharacterSet.URLHostAllowedCharacterSet;
27+
}
28+
29+
NS_INLINE NS_RETURNS_RETAINED NS_NON_BRIDGED(NSCharacterSet *) _NSURLComponentsGetURLPathAllowedCharacterSet(void) {
30+
return NSCharacterSet.URLPathAllowedCharacterSet;
31+
}
32+
33+
NS_INLINE NS_RETURNS_RETAINED NS_NON_BRIDGED(NSCharacterSet *) _NSURLComponentsGetURLQueryAllowedCharacterSet(void) {
34+
return NSCharacterSet.URLQueryAllowedCharacterSet;
35+
}
36+
37+
NS_INLINE NS_RETURNS_RETAINED NS_NON_BRIDGED(NSCharacterSet *) _NSURLComponentsGetURLFragmentAllowedCharacterSet(void) {
38+
return NSCharacterSet.URLFragmentAllowedCharacterSet;
39+
}
40+
41+
NS_END_DECLS

0 commit comments

Comments
 (0)