[swift-dev] feedback on alternatives for importing libdispatch types into Swift on Liunx
David P Grove
groved at us.ibm.com
Wed Mar 9 17:14:46 CST 2016
I've made some progress on getting libdispatch types like dispatch_queue_t
to implement the Swift object model and be imported as Swift classes. As
Joe suggested last week, I am attempting to implement the Swift object
model in libdispatch (and get the importer to realize that).
To simplify things, I created a tiny simulation of libdispatch  and used
it to explore options. I think I've ended up in a reasonable point, but
before actually making the changes for real in libdispatch and submitting
pull requests I want to get a sanity check on the approach.
Summary of the changes:
1. In the ClangImporter, I added more Dispatch types to
MappedTypes.def and a new value, MappedCTypeKind::SwiftClass.
2. In the simulated libdispatch, I define DISPATCH_RETURNS_RETAINED
to be __attribute__((cf_returns_retained)) instead of
3. In the simulated libdispatch, I wired
dispatch_retain/dispatch_release to swift_retain/release. I used
swift_allocObject to create instances of dispatch_queue_t, etc.
4. In Dispatch.swift I define stub classes DispatchObject,
DispatchQueue, etc. in a class hierarchy. I use the compiler-generated
metadata for these classes when calling swift_allocObject for the isa
The changes to ClangImporter can be browsed at .
thanks for any feedback,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-dev