Skip to content

Commit a2f4eb6

Browse files
authored
Merge pull request #931 from spevans/pr_warning_fixes
2 parents de6ff76 + b7ddb60 commit a2f4eb6

12 files changed

+59
-45
lines changed

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ static bool (*CAS32)(int32_t, int32_t, volatile int32_t *) = OSAtomicCompareAndS
12841284

12851285
#if DEPLOYMENT_RUNTIME_SWIFT
12861286
extern void swift_retain(void *);
1287+
extern void swift_release(void *);
12871288
#endif
12881289

12891290
// For "tryR==true", a return of NULL means "failed".
@@ -1399,7 +1400,6 @@ Boolean _CFIsDeallocating(CFTypeRef cf) {
13991400
static void _CFRelease(CFTypeRef CF_RELEASES_ARGUMENT cf) {
14001401
#if DEPLOYMENT_RUNTIME_SWIFT
14011402
// We always call through to swift_release, since all CFTypeRefs are at least _NSCFType objects
1402-
extern void swift_release(void *);
14031403
swift_release((void *)cf);
14041404
#else
14051405

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,17 @@ typedef char __cf_uuid_string[37];
259259
typedef __cf_uuid _cf_uuid_t;
260260
typedef __cf_uuid_string _cf_uuid_string_t;
261261

262-
CF_EXPORT void _cf_uuid_clear(_cf_uuid_t uu);
263-
CF_EXPORT int _cf_uuid_compare(const _cf_uuid_t uu1, const _cf_uuid_t uu2);
264-
CF_EXPORT void _cf_uuid_copy(_cf_uuid_t dst, const _cf_uuid_t src);
265-
CF_EXPORT void _cf_uuid_generate(_cf_uuid_t out);
266-
CF_EXPORT void _cf_uuid_generate_random(_cf_uuid_t out);
267-
CF_EXPORT void _cf_uuid_generate_time(_cf_uuid_t out);
268-
CF_EXPORT int _cf_uuid_is_null(const _cf_uuid_t uu);
269-
CF_EXPORT int _cf_uuid_parse(const _cf_uuid_string_t in, _cf_uuid_t uu);
270-
CF_EXPORT void _cf_uuid_unparse(const _cf_uuid_t uu, _cf_uuid_string_t out);
271-
CF_EXPORT void _cf_uuid_unparse_lower(const _cf_uuid_t uu, _cf_uuid_string_t out);
272-
CF_EXPORT void _cf_uuid_unparse_upper(const _cf_uuid_t uu, _cf_uuid_string_t out);
262+
CF_EXPORT void _cf_uuid_clear(_cf_uuid_t _Nonnull uu);
263+
CF_EXPORT int _cf_uuid_compare(const _cf_uuid_t _Nonnull uu1, const _cf_uuid_t _Nonnull uu2);
264+
CF_EXPORT void _cf_uuid_copy(_cf_uuid_t _Nonnull dst, const _cf_uuid_t _Nonnull src);
265+
CF_EXPORT void _cf_uuid_generate(_cf_uuid_t _Nonnull out);
266+
CF_EXPORT void _cf_uuid_generate_random(_cf_uuid_t _Nonnull out);
267+
CF_EXPORT void _cf_uuid_generate_time(_cf_uuid_t _Nonnull out);
268+
CF_EXPORT int _cf_uuid_is_null(const _cf_uuid_t _Nonnull uu);
269+
CF_EXPORT int _cf_uuid_parse(const _cf_uuid_string_t _Nonnull in, _cf_uuid_t _Nonnull uu);
270+
CF_EXPORT void _cf_uuid_unparse(const _cf_uuid_t _Nonnull uu, _cf_uuid_string_t _Nonnull out);
271+
CF_EXPORT void _cf_uuid_unparse_lower(const _cf_uuid_t _Nonnull uu, _cf_uuid_string_t _Nonnull out);
272+
CF_EXPORT void _cf_uuid_unparse_upper(const _cf_uuid_t _Nonnull uu, _cf_uuid_string_t _Nonnull out);
273273

274274

275275
extern CFWriteStreamRef _CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef alloc, int fd);

Foundation/Measurement.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extension Measurement where UnitType : Dimension {
7575
/// Add two measurements of the same Unit.
7676
/// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
7777
/// - returns: A measurement of value `lhs.value + rhs.value` and unit `lhs.unit`.
78-
public func +<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
78+
public func +<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
7979
if lhs.unit.isEqual(rhs.unit) {
8080
return Measurement(value: lhs.value + rhs.value, unit: lhs.unit)
8181
} else {
@@ -100,7 +100,7 @@ public func +<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
100100
/// Subtract two measurements of the same Unit.
101101
/// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
102102
/// - returns: A measurement of value `lhs.value - rhs.value` and unit `lhs.unit`.
103-
public func -<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
103+
public func -<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
104104
if lhs.unit.isEqual(rhs.unit) {
105105
return Measurement(value: lhs.value - rhs.value, unit: lhs.unit)
106106
} else {
@@ -124,31 +124,31 @@ public func -<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
124124

125125
/// Multiply a measurement by a scalar value.
126126
/// - returns: A measurement of value `lhs.value * rhs` with the same unit as `lhs`.
127-
public func *<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Double) -> Measurement<UnitType> {
127+
public func *<UnitType>(lhs: Measurement<UnitType>, rhs: Double) -> Measurement<UnitType> {
128128
return Measurement(value: lhs.value * rhs, unit: lhs.unit)
129129
}
130130

131131
/// Multiply a scalar value by a measurement.
132132
/// - returns: A measurement of value `lhs * rhs.value` with the same unit as `rhs`.
133-
public func *<UnitType : Unit>(lhs: Double, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
133+
public func *<UnitType>(lhs: Double, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
134134
return Measurement(value: lhs * rhs.value, unit: rhs.unit)
135135
}
136136

137137
/// Divide a measurement by a scalar value.
138138
/// - returns: A measurement of value `lhs.value / rhs` with the same unit as `lhs`.
139-
public func /<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Double) -> Measurement<UnitType> {
139+
public func /<UnitType>(lhs: Measurement<UnitType>, rhs: Double) -> Measurement<UnitType> {
140140
return Measurement(value: lhs.value / rhs, unit: lhs.unit)
141141
}
142142

143143
/// Divide a scalar value by a measurement.
144144
/// - returns: A measurement of value `lhs / rhs.value` with the same unit as `rhs`.
145-
public func /<UnitType : Unit>(lhs: Double, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
145+
public func /<UnitType>(lhs: Double, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
146146
return Measurement(value: lhs / rhs.value, unit: rhs.unit)
147147
}
148148

149149
/// Compare two measurements of the same `Unit`.
150150
/// - returns: `true` if `lhs.value == rhs.value && lhs.unit == rhs.unit`.
151-
public func ==<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
151+
public func ==<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
152152
return lhs.value == rhs.value && lhs.unit == rhs.unit
153153
}
154154

@@ -168,7 +168,7 @@ public func ==<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measuremen
168168
/// Compare two measurements of the same `Unit`.
169169
/// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
170170
/// - returns: `lhs.value < rhs.value`
171-
public func <<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
171+
public func <<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
172172
return lhs.value < rhs.value
173173
}
174174

@@ -188,7 +188,7 @@ public func <<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
188188
/// Compare two measurements of the same `Unit`.
189189
/// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
190190
/// - returns: `lhs.value > rhs.value`
191-
public func ><UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
191+
public func ><UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
192192
return lhs.value > rhs.value
193193
}
194194

@@ -208,7 +208,7 @@ public func ><UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
208208
/// Compare two measurements of the same `Unit`.
209209
/// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
210210
/// - returns: `lhs.value <= rhs.value`
211-
public func <=<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
211+
public func <=<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
212212
return lhs.value <= rhs.value
213213
}
214214

@@ -228,7 +228,7 @@ public func <=<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measuremen
228228
/// Compare two measurements of the same `Unit`.
229229
/// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
230230
/// - returns: `lhs.value >= rhs.value`
231-
public func >=<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
231+
public func >=<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Bool {
232232
return lhs.value >= rhs.value
233233
}
234234

Foundation/NSKeyedArchiver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ open class NSKeyedArchiver : NSCoder {
376376
if objv == nil {
377377
return true // always have a null reference
378378
} else {
379-
return self._objRefMap[_SwiftValue.store(objv)] != nil
379+
return self._objRefMap[_SwiftValue.store(objv!)] != nil
380380
}
381381
}
382382

@@ -612,7 +612,7 @@ open class NSKeyedArchiver : NSCoder {
612612

613613
if _isContainer(object) {
614614
guard let codable = object as? NSCoding else {
615-
fatalError("Object \(object) does not conform to NSCoding")
615+
fatalError("Object \(String(describing: object)) does not conform to NSCoding")
616616
}
617617

618618
let innerEncodingContext = EncodingContext()

Foundation/NSKeyedUnarchiver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ open class NSKeyedUnarchiver : NSCoder {
387387
}
388388

389389
// check replacement cache
390-
object = self._replacementMap[_SwiftValue.store(decodedObject)]
390+
object = self._replacementMap[_SwiftValue.store(decodedObject!)]
391391
if object != nil {
392392
return object
393393
}
@@ -454,7 +454,7 @@ open class NSKeyedUnarchiver : NSCoder {
454454

455455
guard let classReference = innerDecodingContext.dict["$class"] as? _NSKeyedArchiverUID else {
456456
throw _decodingError(CocoaError.coderReadCorrupt,
457-
withDescription: "Invalid class reference \(innerDecodingContext.dict["$class"]). The data may be corrupt.")
457+
withDescription: "Invalid class reference \(String(describing: innerDecodingContext.dict["$class"])). The data may be corrupt.")
458458
}
459459

460460
var classToConstruct : AnyClass? = try _validateAndMapClassReference(classReference,

Foundation/NSMeasurementFormatter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ open class MeasurementFormatter : Formatter, NSSecureCoding {
7979
}
8080

8181
extension MeasurementFormatter {
82-
public func string<UnitType : Unit>(from measurement: Measurement<UnitType>) -> String { NSUnimplemented() }
82+
public func string<UnitType>(from measurement: Measurement<UnitType>) -> String { NSUnimplemented() }
8383
}

Foundation/NSString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ open class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSC
286286
internal var _fastContents: UnsafePointer<UniChar>? {
287287
if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
288288
if !_storage._core.isASCII {
289-
return unsafeBitCast(_storage._core.startUTF16, to: UnsafePointer<UniChar>.self)
289+
return UnsafePointer<UniChar>(_storage._core.startUTF16)
290290
}
291291
}
292292
return nil

Foundation/ReferenceConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// Decorates types which are backed by a Foundation reference type.
1212
///
1313
/// All `ReferenceConvertible` types are hashable, equatable, and provide description functions.
14-
public protocol ReferenceConvertible : CustomStringConvertible, CustomDebugStringConvertible, Hashable, Equatable {
14+
public protocol ReferenceConvertible : CustomStringConvertible, CustomDebugStringConvertible, Hashable {
1515
associatedtype ReferenceType : NSObject, NSCopying
1616
}
1717

Foundation/UUID.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
2424
/* Create a new UUID with RFC 4122 version 4 random bytes */
2525
public init() {
2626
withUnsafeMutablePointer(to: &uuid) {
27-
_cf_uuid_generate_random(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
27+
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
28+
_cf_uuid_generate_random($0)
29+
}
2830
}
2931
}
3032

3133
fileprivate init(reference: NSUUID) {
3234
var bytes: uuid_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
3335
withUnsafeMutablePointer(to: &bytes) {
34-
reference.getBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
36+
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
37+
reference.getBytes($0)
38+
}
3539
}
3640
uuid = bytes
3741
}
@@ -41,7 +45,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
4145
/// Returns nil for invalid strings.
4246
public init?(uuidString string: String) {
4347
let res = withUnsafeMutablePointer(to: &uuid) {
44-
return _cf_uuid_parse(string, unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
48+
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
49+
return _cf_uuid_parse(string, $0)
50+
}
4551
}
4652
if res != 0 {
4753
return nil
@@ -57,18 +63,24 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
5763
public var uuidString: String {
5864
var bytes: uuid_string_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
5965
var localValue = uuid
60-
return withUnsafeMutablePointer(to: &localValue) { val in
61-
withUnsafeMutablePointer(to: &bytes) { str in
62-
_cf_uuid_unparse(unsafeBitCast(val, to: UnsafePointer<UInt8>.self), unsafeBitCast(str, to: UnsafeMutablePointer<Int8>.self))
63-
return String(cString: unsafeBitCast(str, to: UnsafePointer<CChar>.self), encoding: .utf8)!
66+
return withUnsafeMutablePointer(to: &localValue) { valPtr in
67+
valPtr.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) { val in
68+
withUnsafeMutablePointer(to: &bytes) { strPtr in
69+
strPtr.withMemoryRebound(to: CChar.self, capacity: MemoryLayout<uuid_string_t>.size) { str in
70+
_cf_uuid_unparse(val, str)
71+
return String(cString: str, encoding: .utf8)!
72+
}
73+
}
6474
}
6575
}
6676
}
6777

6878
public var hashValue: Int {
6979
var localValue = uuid
7080
return withUnsafeMutablePointer(to: &localValue) {
71-
return Int(bitPattern: CFHashBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self), CFIndex(MemoryLayout<uuid_t>.size)))
81+
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
82+
return Int(bitPattern: CFHashBytes($0, CFIndex(MemoryLayout<uuid_t>.size)))
83+
}
7284
}
7385
}
7486

@@ -85,7 +97,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
8597
fileprivate var reference: NSUUID {
8698
var bytes = uuid
8799
return withUnsafePointer(to: &bytes) {
88-
return NSUUID(uuidBytes: unsafeBitCast($0, to: UnsafePointer<UInt8>.self))
100+
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
101+
return NSUUID(uuidBytes: $0)
102+
}
89103
}
90104
}
91105

TestFoundation/TestNSURL.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,23 @@ class TestNSURL : XCTestCase {
158158
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(testedValue)'")
159159
}
160160
} else {
161-
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(got[key])'")
161+
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(String(describing: got[key]))'")
162162
}
163163
} else if let expectedValue = obj as? [String] {
164164
if let testedValue = got[key] as? [String] {
165165
if expectedValue != testedValue {
166166
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(testedValue)'")
167167
}
168168
} else {
169-
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(got[key])'")
169+
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(String(describing: got[key]))'")
170170
}
171171
} else if let expectedValue = obj as? Int {
172172
if let testedValue = got[key] as? Int {
173173
if expectedValue != testedValue {
174174
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(testedValue)'")
175175
}
176176
} else {
177-
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(got[key])'")
177+
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(String(describing: got[key]))'")
178178
}
179179
}
180180

TestFoundation/TestNSURLSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ extension DataTask : URLSessionDataDelegate {
428428

429429
extension DataTask : URLSessionTaskDelegate {
430430
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
431-
guard let e = error as? URLError else { return }
431+
guard (error as? URLError) != nil else { return }
432432
dataTaskExpectation.fulfill()
433433
if let cancellation = cancelExpectation {
434434
cancellation.fulfill()

TestFoundation/TestNSXMLDocument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class TestNSXMLDocument : XCTestCase {
6767

6868
func test_basicCreation() {
6969
let doc = XMLDocument(rootElement: nil)
70-
XCTAssert(doc.version == "1.0", "expected 1.0, got \(doc.version)")
70+
XCTAssert(doc.version == "1.0", "expected 1.0, got \(String(describing: doc.version))")
7171
doc.version = "1.1"
72-
XCTAssert(doc.version == "1.1", "expected 1.1, got \(doc.version)")
72+
XCTAssert(doc.version == "1.1", "expected 1.1, got \(String(describing: doc.version))")
7373
let node = XMLElement(name: "Hello", uri: "http://www.example.com")
7474

7575
doc.setRootElement(node)

0 commit comments

Comments
 (0)