[stdlib] Add Int.init(bitPattern: OpaquePointer?)

(and the same for UInt)

Dmitri and I consider this an oversight in SE-0016, particularly since
OpaquePointer has the inverse operation 'init?(bitPattern: Int)'.
This commit is contained in:
Jordan Rose
2016-04-18 14:55:22 -07:00
parent 039331c461
commit 2e38280047
2 changed files with 14 additions and 2 deletions

View File

@@ -162,6 +162,20 @@ extension OpaquePointer : CustomDebugStringConvertible {
}
}
extension Int {
@warn_unused_result
public init(bitPattern pointer: OpaquePointer?) {
self.init(bitPattern: UnsafePointer<Void>(pointer))
}
}
extension UInt {
@warn_unused_result
public init(bitPattern pointer: OpaquePointer?) {
self.init(bitPattern: UnsafePointer<Void>(pointer))
}
}
@warn_unused_result
public func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool {
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))

View File

@@ -151,7 +151,6 @@ ${SelfName}TestSuite.test("Hashable") {
}
}
% if SelfName != 'OpaquePointer':
${SelfName}TestSuite.test("toInteger") {
do {
let word: Int = 0x12345678
@@ -172,7 +171,6 @@ ${SelfName}TestSuite.test("toInteger") {
expectEqual(UInt(0), UInt(bitPattern: ptr))
}
}
% end
% end