Skip to content

Minor warning fixes #931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ static bool (*CAS32)(int32_t, int32_t, volatile int32_t *) = OSAtomicCompareAndS

#if DEPLOYMENT_RUNTIME_SWIFT
extern void swift_retain(void *);
extern void swift_release(void *);
#endif

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

Expand Down
22 changes: 11 additions & 11 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,17 @@ typedef char __cf_uuid_string[37];
typedef __cf_uuid _cf_uuid_t;
typedef __cf_uuid_string _cf_uuid_string_t;

CF_EXPORT void _cf_uuid_clear(_cf_uuid_t uu);
CF_EXPORT int _cf_uuid_compare(const _cf_uuid_t uu1, const _cf_uuid_t uu2);
CF_EXPORT void _cf_uuid_copy(_cf_uuid_t dst, const _cf_uuid_t src);
CF_EXPORT void _cf_uuid_generate(_cf_uuid_t out);
CF_EXPORT void _cf_uuid_generate_random(_cf_uuid_t out);
CF_EXPORT void _cf_uuid_generate_time(_cf_uuid_t out);
CF_EXPORT int _cf_uuid_is_null(const _cf_uuid_t uu);
CF_EXPORT int _cf_uuid_parse(const _cf_uuid_string_t in, _cf_uuid_t uu);
CF_EXPORT void _cf_uuid_unparse(const _cf_uuid_t uu, _cf_uuid_string_t out);
CF_EXPORT void _cf_uuid_unparse_lower(const _cf_uuid_t uu, _cf_uuid_string_t out);
CF_EXPORT void _cf_uuid_unparse_upper(const _cf_uuid_t uu, _cf_uuid_string_t out);
CF_EXPORT void _cf_uuid_clear(_cf_uuid_t _Nonnull uu);
CF_EXPORT int _cf_uuid_compare(const _cf_uuid_t _Nonnull uu1, const _cf_uuid_t _Nonnull uu2);
CF_EXPORT void _cf_uuid_copy(_cf_uuid_t _Nonnull dst, const _cf_uuid_t _Nonnull src);
CF_EXPORT void _cf_uuid_generate(_cf_uuid_t _Nonnull out);
CF_EXPORT void _cf_uuid_generate_random(_cf_uuid_t _Nonnull out);
CF_EXPORT void _cf_uuid_generate_time(_cf_uuid_t _Nonnull out);
CF_EXPORT int _cf_uuid_is_null(const _cf_uuid_t _Nonnull uu);
CF_EXPORT int _cf_uuid_parse(const _cf_uuid_string_t _Nonnull in, _cf_uuid_t _Nonnull uu);
CF_EXPORT void _cf_uuid_unparse(const _cf_uuid_t _Nonnull uu, _cf_uuid_string_t _Nonnull out);
CF_EXPORT void _cf_uuid_unparse_lower(const _cf_uuid_t _Nonnull uu, _cf_uuid_string_t _Nonnull out);
CF_EXPORT void _cf_uuid_unparse_upper(const _cf_uuid_t _Nonnull uu, _cf_uuid_string_t _Nonnull out);


extern CFWriteStreamRef _CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef alloc, int fd);
Expand Down
22 changes: 11 additions & 11 deletions Foundation/Measurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension Measurement where UnitType : Dimension {
/// Add two measurements of the same Unit.
/// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
/// - returns: A measurement of value `lhs.value + rhs.value` and unit `lhs.unit`.
public func +<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
public func +<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we make these changes in the Swift overlay too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was done as part of swiftlang/swift#8281

if lhs.unit.isEqual(rhs.unit) {
return Measurement(value: lhs.value + rhs.value, unit: lhs.unit)
} else {
Expand All @@ -100,7 +100,7 @@ public func +<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
/// Subtract two measurements of the same Unit.
/// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
/// - returns: A measurement of value `lhs.value - rhs.value` and unit `lhs.unit`.
public func -<UnitType : Unit>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
public func -<UnitType>(lhs: Measurement<UnitType>, rhs: Measurement<UnitType>) -> Measurement<UnitType> {
if lhs.unit.isEqual(rhs.unit) {
return Measurement(value: lhs.value - rhs.value, unit: lhs.unit)
} else {
Expand All @@ -124,31 +124,31 @@ public func -<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement

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

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

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

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

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSKeyedArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ open class NSKeyedArchiver : NSCoder {
if objv == nil {
return true // always have a null reference
} else {
return self._objRefMap[_SwiftValue.store(objv)] != nil
return self._objRefMap[_SwiftValue.store(objv!)] != nil
}
}

Expand Down Expand Up @@ -612,7 +612,7 @@ open class NSKeyedArchiver : NSCoder {

if _isContainer(object) {
guard let codable = object as? NSCoding else {
fatalError("Object \(object) does not conform to NSCoding")
fatalError("Object \(String(describing: object)) does not conform to NSCoding")
}

let innerEncodingContext = EncodingContext()
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSKeyedUnarchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ open class NSKeyedUnarchiver : NSCoder {
}

// check replacement cache
object = self._replacementMap[_SwiftValue.store(decodedObject)]
object = self._replacementMap[_SwiftValue.store(decodedObject!)]
if object != nil {
return object
}
Expand Down Expand Up @@ -454,7 +454,7 @@ open class NSKeyedUnarchiver : NSCoder {

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

var classToConstruct : AnyClass? = try _validateAndMapClassReference(classReference,
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSMeasurementFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ open class MeasurementFormatter : Formatter, NSSecureCoding {
}

extension MeasurementFormatter {
public func string<UnitType : Unit>(from measurement: Measurement<UnitType>) -> String { NSUnimplemented() }
public func string<UnitType>(from measurement: Measurement<UnitType>) -> String { NSUnimplemented() }
}
2 changes: 1 addition & 1 deletion Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ open class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSC
internal var _fastContents: UnsafePointer<UniChar>? {
if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
if !_storage._core.isASCII {
return unsafeBitCast(_storage._core.startUTF16, to: UnsafePointer<UniChar>.self)
return UnsafePointer<UniChar>(_storage._core.startUTF16)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion Foundation/ReferenceConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// Decorates types which are backed by a Foundation reference type.
///
/// All `ReferenceConvertible` types are hashable, equatable, and provide description functions.
public protocol ReferenceConvertible : CustomStringConvertible, CustomDebugStringConvertible, Hashable, Equatable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems obnoxious that this generates a warning, but ok.

public protocol ReferenceConvertible : CustomStringConvertible, CustomDebugStringConvertible, Hashable {
associatedtype ReferenceType : NSObject, NSCopying
}

32 changes: 23 additions & 9 deletions Foundation/UUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
/* Create a new UUID with RFC 4122 version 4 random bytes */
public init() {
withUnsafeMutablePointer(to: &uuid) {
_cf_uuid_generate_random(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
_cf_uuid_generate_random($0)
}
}
}

fileprivate init(reference: NSUUID) {
var bytes: uuid_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
withUnsafeMutablePointer(to: &bytes) {
reference.getBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
reference.getBytes($0)
}
}
uuid = bytes
}
Expand All @@ -41,7 +45,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
/// Returns nil for invalid strings.
public init?(uuidString string: String) {
let res = withUnsafeMutablePointer(to: &uuid) {
return _cf_uuid_parse(string, unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
return _cf_uuid_parse(string, $0)
}
}
if res != 0 {
return nil
Expand All @@ -57,18 +63,24 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
public var uuidString: String {
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)
var localValue = uuid
return withUnsafeMutablePointer(to: &localValue) { val in
withUnsafeMutablePointer(to: &bytes) { str in
_cf_uuid_unparse(unsafeBitCast(val, to: UnsafePointer<UInt8>.self), unsafeBitCast(str, to: UnsafeMutablePointer<Int8>.self))
return String(cString: unsafeBitCast(str, to: UnsafePointer<CChar>.self), encoding: .utf8)!
return withUnsafeMutablePointer(to: &localValue) { valPtr in
valPtr.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) { val in
withUnsafeMutablePointer(to: &bytes) { strPtr in
strPtr.withMemoryRebound(to: CChar.self, capacity: MemoryLayout<uuid_string_t>.size) { str in
_cf_uuid_unparse(val, str)
return String(cString: str, encoding: .utf8)!
}
}
}
}
}

public var hashValue: Int {
var localValue = uuid
return withUnsafeMutablePointer(to: &localValue) {
return Int(bitPattern: CFHashBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self), CFIndex(MemoryLayout<uuid_t>.size)))
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
return Int(bitPattern: CFHashBytes($0, CFIndex(MemoryLayout<uuid_t>.size)))
}
}
}

Expand All @@ -85,7 +97,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
fileprivate var reference: NSUUID {
var bytes = uuid
return withUnsafePointer(to: &bytes) {
return NSUUID(uuidBytes: unsafeBitCast($0, to: UnsafePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<uuid_t>.size) {
return NSUUID(uuidBytes: $0)
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions TestFoundation/TestNSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ class TestNSURL : XCTestCase {
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(testedValue)'")
}
} else {
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(got[key])'")
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(String(describing: got[key]))'")
}
} else if let expectedValue = obj as? [String] {
if let testedValue = got[key] as? [String] {
if expectedValue != testedValue {
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(testedValue)'")
}
} else {
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(got[key])'")
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(String(describing: got[key]))'")
}
} else if let expectedValue = obj as? Int {
if let testedValue = got[key] as? Int {
if expectedValue != testedValue {
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(testedValue)'")
}
} else {
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(got[key])'")
differences.append(" \(key) Expected = '\(expectedValue)', Got = '\(String(describing: got[key]))'")
}
}

Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ extension DataTask : URLSessionDataDelegate {

extension DataTask : URLSessionTaskDelegate {
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
guard let e = error as? URLError else { return }
guard (error as? URLError) != nil else { return }
dataTaskExpectation.fulfill()
if let cancellation = cancelExpectation {
cancellation.fulfill()
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestNSXMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class TestNSXMLDocument : XCTestCase {

func test_basicCreation() {
let doc = XMLDocument(rootElement: nil)
XCTAssert(doc.version == "1.0", "expected 1.0, got \(doc.version)")
XCTAssert(doc.version == "1.0", "expected 1.0, got \(String(describing: doc.version))")
doc.version = "1.1"
XCTAssert(doc.version == "1.1", "expected 1.1, got \(doc.version)")
XCTAssert(doc.version == "1.1", "expected 1.1, got \(String(describing: doc.version))")
let node = XMLElement(name: "Hello", uri: "http://www.example.com")

doc.setRootElement(node)
Expand Down