Skip to content

Commit 158b69c

Browse files
committed
swift: remove Windows special case in Block.swift
`DISPATCH_ENUM` will use a typed enum which creates a typedef to an elaborated type. This fails to be imported into Swift as a numeric type. Explicitly convert the `numericCast`'ed value from the Swift `OptionSet` to the `dispatch_block_flags_t` as a portable alternate spelling. This allows us to continue to import the enum as a typed value. Thanks to @beccadax for the pointer that this pattern may not work on Darwin (which it does not!) and the suggestion for the explicit type conversion!
1 parent 12a60ac commit 158b69c

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/swift/Block.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,15 @@ public class DispatchWorkItem {
4040
internal var _block: _DispatchBlock
4141

4242
public init(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @escaping @convention(block) () -> ()) {
43-
#if os(Windows)
44-
#if arch(arm64) || arch(x86_64)
45-
let flags = dispatch_block_flags_t(UInt32(flags.rawValue))
46-
#else
47-
let flags = dispatch_block_flags_t(UInt(flags.rawValue))
48-
#endif
49-
#else
50-
let flags: dispatch_block_flags_t = numericCast(flags.rawValue)
51-
#endif
43+
let flags: dispatch_block_flags_t = dispatch_block_flags_t(numericCast(flags.rawValue))
5244
_block = dispatch_block_create_with_qos_class(flags,
5345
qos.qosClass.rawValue.rawValue, Int32(qos.relativePriority), block)
5446
}
5547

5648
// Used by DispatchQueue.synchronously<T> to provide a path through
5749
// dispatch_block_t, as we know the lifetime of the block in question.
5850
internal init(flags: DispatchWorkItemFlags = [], noescapeBlock: () -> ()) {
59-
#if os(Windows)
60-
#if arch(arm64) || arch(x86_64)
61-
let flags = dispatch_block_flags_t(UInt32(flags.rawValue))
62-
#else
63-
let flags = dispatch_block_flags_t(UInt(flags.rawValue))
64-
#endif
65-
#else
66-
let flags: dispatch_block_flags_t = numericCast(flags.rawValue)
67-
#endif
51+
let flags: dispatch_block_flags_t = dispatch_block_flags_t(numericCast(flags.rawValue))
6852
_block = _swift_dispatch_block_create_noescape(flags, noescapeBlock)
6953
}
7054

0 commit comments

Comments
 (0)