Skip to content

Commit 1457de8

Browse files
authored
Merge pull request #352 from compnerd/typecast
SwiftOverlay: add explicit casts
2 parents c4d6402 + 689b172 commit 1457de8

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

src/swift/Block.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ public class DispatchWorkItem {
4040
internal var _block: _DispatchBlock
4141

4242
public init(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @escaping @convention(block) () -> ()) {
43-
_block = dispatch_block_create_with_qos_class(dispatch_block_flags_t(flags.rawValue),
43+
_block = dispatch_block_create_with_qos_class(dispatch_block_flags_t(UInt32(flags.rawValue)),
4444
qos.qosClass.rawValue.rawValue, Int32(qos.relativePriority), block)
4545
}
4646

4747
// Used by DispatchQueue.synchronously<T> to provide a path through
4848
// dispatch_block_t, as we know the lifetime of the block in question.
4949
internal init(flags: DispatchWorkItemFlags = [], noescapeBlock: () -> ()) {
50-
_block = _swift_dispatch_block_create_noescape(dispatch_block_flags_t(flags.rawValue), noescapeBlock)
50+
_block = _swift_dispatch_block_create_noescape(dispatch_block_flags_t(UInt32(flags.rawValue)), noescapeBlock)
5151
}
5252

5353
public func perform() {

src/swift/Dispatch.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public extension DispatchGroup {
166166
public extension DispatchSemaphore {
167167
@discardableResult
168168
public func signal() -> Int {
169-
return dispatch_semaphore_signal(self.__wrapped)
169+
return Int(dispatch_semaphore_signal(self.__wrapped))
170170
}
171171

172172
public func wait() {

src/swift/IO.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public extension DispatchIO {
3535
}
3636

3737
public class func read(fromFileDescriptor: Int32, maxLength: Int, runningHandlerOn queue: DispatchQueue, handler: @escaping (_ data: DispatchData, _ error: Int32) -> Void) {
38-
dispatch_read(fromFileDescriptor, maxLength, queue.__wrapped) { (data: dispatch_data_t, error: Int32) in
38+
dispatch_read(dispatch_fd_t(fromFileDescriptor), maxLength, queue.__wrapped) { (data: dispatch_data_t, error: Int32) in
3939
handler(DispatchData(borrowedData: data), error)
4040
}
4141
}
4242

4343
public class func write(toFileDescriptor: Int32, data: DispatchData, runningHandlerOn queue: DispatchQueue, handler: @escaping (_ data: DispatchData?, _ error: Int32) -> Void) {
44-
dispatch_write(toFileDescriptor, data.__wrapped.__wrapped, queue.__wrapped) { (data: dispatch_data_t?, error: Int32) in
44+
dispatch_write(dispatch_fd_t(toFileDescriptor), data.__wrapped.__wrapped, queue.__wrapped) { (data: dispatch_data_t?, error: Int32) in
4545
handler(data.map { DispatchData(borrowedData: $0) }, error)
4646
}
4747
}
@@ -101,10 +101,10 @@ public extension DispatchIO {
101101
}
102102

103103
public func setInterval(interval: DispatchTimeInterval, flags: IntervalFlags = []) {
104-
dispatch_io_set_interval(self.__wrapped, UInt64(interval.rawValue), flags.rawValue)
104+
dispatch_io_set_interval(self.__wrapped, UInt64(interval.rawValue), dispatch_io_interval_flags_t(flags.rawValue))
105105
}
106106

107107
public func close(flags: CloseFlags = []) {
108-
dispatch_io_close(self.__wrapped, flags.rawValue)
108+
dispatch_io_close(self.__wrapped, dispatch_io_close_flags_t(flags.rawValue))
109109
}
110110
}

src/swift/Queue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public extension DispatchQueue {
115115
@available(macOS, deprecated: 10.10, message: "")
116116
@available(*, deprecated: 8.0, message: "")
117117
public class func global(priority: GlobalQueuePriority) -> DispatchQueue {
118-
return DispatchQueue(queue: CDispatch.dispatch_get_global_queue(priority._translatedValue, 0))
118+
return DispatchQueue(queue: CDispatch.dispatch_get_global_queue(Int(priority._translatedValue), 0))
119119
}
120120

121121
@available(macOS 10.10, iOS 8.0, *)

src/swift/Source.swift

+8-10
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public extension DispatchSource {
189189
}
190190

191191
public class func makeTimerSource(flags: TimerFlags = [], queue: DispatchQueue? = nil) -> DispatchSourceTimer {
192-
let source = dispatch_source_create(_swift_dispatch_source_type_TIMER(), 0, flags.rawValue, queue?.__wrapped)
192+
let source = dispatch_source_create(_swift_dispatch_source_type_TIMER(), 0, UInt(flags.rawValue), queue?.__wrapped)
193193
return DispatchSource(source: source) as DispatchSourceTimer
194194
}
195195

@@ -268,13 +268,11 @@ public extension DispatchSourceProcess {
268268
}
269269

270270
public var data: DispatchSource.ProcessEvent {
271-
let data = dispatch_source_get_data(self as! DispatchSource)
272-
return DispatchSource.ProcessEvent(rawValue: data)
271+
return DispatchSource.ProcessEvent(rawValue: (self as! DispatchSource).data)
273272
}
274273

275274
public var mask: DispatchSource.ProcessEvent {
276-
let mask = dispatch_source_get_mask(self as! DispatchSource)
277-
return DispatchSource.ProcessEvent(rawValue: mask)
275+
return DispatchSource.ProcessEvent(rawValue: (self as! DispatchSource).mask)
278276
}
279277
}
280278
#endif
@@ -627,12 +625,12 @@ public extension DispatchSourceFileSystemObject {
627625

628626
public var data: DispatchSource.FileSystemEvent {
629627
let data = dispatch_source_get_data((self as! DispatchSource).__wrapped)
630-
return DispatchSource.FileSystemEvent(rawValue: data)
628+
return DispatchSource.FileSystemEvent(rawValue: UInt(data))
631629
}
632630

633631
public var mask: DispatchSource.FileSystemEvent {
634632
let data = dispatch_source_get_mask((self as! DispatchSource).__wrapped)
635-
return DispatchSource.FileSystemEvent(rawValue: data)
633+
return DispatchSource.FileSystemEvent(rawValue: UInt(data))
636634
}
637635
}
638636
#endif
@@ -644,7 +642,7 @@ public extension DispatchSourceUserDataAdd {
644642
/// - parameter data: the value to add to the current pending data. A value of zero
645643
/// has no effect and will not result in the submission of the event handler block.
646644
public func add(data: UInt) {
647-
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
645+
dispatch_source_merge_data((self as! DispatchSource).__wrapped, UInt(data))
648646
}
649647
}
650648

@@ -655,7 +653,7 @@ public extension DispatchSourceUserDataOr {
655653
/// - parameter data: The value to OR into the current pending data. A value of zero
656654
/// has no effect and will not result in the submission of the event handler block.
657655
public func or(data: UInt) {
658-
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
656+
dispatch_source_merge_data((self as! DispatchSource).__wrapped, UInt(data))
659657
}
660658
}
661659

@@ -667,6 +665,6 @@ public extension DispatchSourceUserDataReplace {
667665
/// A value of zero will be stored but will not result in the submission of the event
668666
/// handler block.
669667
public func replace(data: UInt) {
670-
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
668+
dispatch_source_merge_data((self as! DispatchSource).__wrapped, UInt(data))
671669
}
672670
}

src/swift/Wrapper.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class DispatchSemaphore : DispatchObject {
7676
}
7777

7878
public init(value: Int) {
79-
__wrapped = dispatch_semaphore_create(value)
79+
__wrapped = dispatch_semaphore_create(Int(value))
8080
}
8181

8282
deinit {
@@ -93,17 +93,17 @@ public class DispatchIO : DispatchObject {
9393

9494
internal init(__type: UInt, fd: Int32, queue: DispatchQueue,
9595
handler: @escaping (_ error: Int32) -> Void) {
96-
__wrapped = dispatch_io_create(__type, fd, queue.__wrapped, handler)
96+
__wrapped = dispatch_io_create(dispatch_io_type_t(__type), dispatch_fd_t(fd), queue.__wrapped, handler)
9797
}
9898

9999
internal init(__type: UInt, path: UnsafePointer<Int8>, oflag: Int32,
100100
mode: mode_t, queue: DispatchQueue, handler: @escaping (_ error: Int32) -> Void) {
101-
__wrapped = dispatch_io_create_with_path(__type, path, oflag, mode, queue.__wrapped, handler)
101+
__wrapped = dispatch_io_create_with_path(dispatch_io_type_t(__type), path, oflag, mode, queue.__wrapped, handler)
102102
}
103103

104104
internal init(__type: UInt, io: DispatchIO,
105105
queue: DispatchQueue, handler: @escaping (_ error: Int32) -> Void) {
106-
__wrapped = dispatch_io_create_with_io(__type, io.__wrapped, queue.__wrapped, handler)
106+
__wrapped = dispatch_io_create_with_io(dispatch_io_type_t(__type), io.__wrapped, queue.__wrapped, handler)
107107
}
108108

109109
deinit {
@@ -115,7 +115,7 @@ public class DispatchIO : DispatchObject {
115115
}
116116

117117
public var fileDescriptor: Int32 {
118-
return dispatch_io_get_descriptor(__wrapped)
118+
return Int32(dispatch_io_get_descriptor(__wrapped))
119119
}
120120

121121
public func setLimit(highWater: Int) {

0 commit comments

Comments
 (0)