mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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
|
@warn_unused_result
|
||||||
public func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool {
|
public func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool {
|
||||||
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
|
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ ${SelfName}TestSuite.test("Hashable") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
% if SelfName != 'OpaquePointer':
|
|
||||||
${SelfName}TestSuite.test("toInteger") {
|
${SelfName}TestSuite.test("toInteger") {
|
||||||
do {
|
do {
|
||||||
let word: Int = 0x12345678
|
let word: Int = 0x12345678
|
||||||
@@ -172,7 +171,6 @@ ${SelfName}TestSuite.test("toInteger") {
|
|||||||
expectEqual(UInt(0), UInt(bitPattern: ptr))
|
expectEqual(UInt(0), UInt(bitPattern: ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% end
|
|
||||||
|
|
||||||
% end
|
% end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user