Skip to content

Commit 733171d

Browse files
committed
Rework of Dispatch overlay for Linux
The lack of Objective-C and associated bridging when importing the libdispatch header files into Swift caused a number of problems including (a) missing ref count operations in Swift compiled code (b) SR-739, dispatch types not being upcastable to dispatch_object_t (c) SR-730, dispatch types not being upcastable to AnyObject (d) SR-737, dispatch types being imported as COpaquePointer This commit fixes all of these issues by injecting a complete Swift overlay layer that wraps the native libdispatch objects and native APIs. The C header files are now imported into a distinct CDispatch module that is not made available to Swift client code (which continues to import Dispatch). Code is added to Dispatch.swift to mirror the native CDispatch APIs up to the Swift Dispatch API and to wrap/unwrap values as needed across that boundary. This wrapping layer does add some minor space and time overheads, but after extensively exploring implementing the Swift object model within the C code of libdispatch (to avoid introducing this overhead), I concluded that the necessary changes to libdispatch would be fairly invasive, and therefore were not justified at this point in the development of the Swift/Linux port of libdispatch.
1 parent 054d938 commit 733171d

File tree

3 files changed

+571
-61
lines changed

3 files changed

+571
-61
lines changed

dispatch/module.map

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
module Dispatch [system] {
1+
module Dispatch {
2+
requires blocks
3+
export *
4+
link "dispatch"
5+
link "BlocksRuntime"
6+
}
7+
8+
module CDispatch [system] {
29
umbrella header "dispatch.h"
310
requires blocks
411
export *

0 commit comments

Comments
 (0)