Skip to content

Commit 2e38280

Browse files
committed
[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)'.
1 parent 039331c commit 2e38280

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

stdlib/public/core/CTypes.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ extension OpaquePointer : CustomDebugStringConvertible {
162162
}
163163
}
164164

165+
extension Int {
166+
@warn_unused_result
167+
public init(bitPattern pointer: OpaquePointer?) {
168+
self.init(bitPattern: UnsafePointer<Void>(pointer))
169+
}
170+
}
171+
172+
extension UInt {
173+
@warn_unused_result
174+
public init(bitPattern pointer: OpaquePointer?) {
175+
self.init(bitPattern: UnsafePointer<Void>(pointer))
176+
}
177+
}
178+
165179
@warn_unused_result
166180
public func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool {
167181
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))

test/1_stdlib/UnsafePointer.swift.gyb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ ${SelfName}TestSuite.test("Hashable") {
151151
}
152152
}
153153

154-
% if SelfName != 'OpaquePointer':
155154
${SelfName}TestSuite.test("toInteger") {
156155
do {
157156
let word: Int = 0x12345678
@@ -172,7 +171,6 @@ ${SelfName}TestSuite.test("toInteger") {
172171
expectEqual(UInt(0), UInt(bitPattern: ptr))
173172
}
174173
}
175-
% end
176174

177175
% end
178176

0 commit comments

Comments
 (0)