Skip to content

Replace uses of @_silgen_name with uses of a shims header. #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/swift/Block.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import CDispatch
import _SwiftDispatchOverlayShims

public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
public let rawValue: UInt
Expand Down Expand Up @@ -98,6 +99,3 @@ public class DispatchWorkItem {
/// on the referential identity of a block. Particularly, dispatch_block_create.
internal typealias _DispatchBlock = @convention(block) () -> Void
internal typealias dispatch_block_t = @convention(block) () -> Void

@_silgen_name("_swift_dispatch_block_create_noescape")
internal func _swift_dispatch_block_create_noescape(_ flags: dispatch_block_flags_t, _ block: () -> ()) -> _DispatchBlock
25 changes: 7 additions & 18 deletions src/swift/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import CDispatch
import _SwiftDispatchOverlayShims

public struct DispatchData : RandomAccessCollection {
public typealias Iterator = DispatchDataIterator
Expand All @@ -37,8 +38,8 @@ public struct DispatchData : RandomAccessCollection {

fileprivate var _deallocator: (DispatchQueue?, @convention(block) () -> Void) {
switch self {
case .free: return (nil, _dispatch_data_destructor_free())
case .unmap: return (nil, _dispatch_data_destructor_munmap())
case .free: return (nil, _swift_dispatch_data_destructor_free())
case .unmap: return (nil, _swift_dispatch_data_destructor_munmap())
case .custom(let q, let b): return (q, b)
}
}
Expand All @@ -53,7 +54,7 @@ public struct DispatchData : RandomAccessCollection {
public init(bytes buffer: UnsafeBufferPointer<UInt8>) {
let d = buffer.baseAddress == nil ? _swift_dispatch_data_empty()
: dispatch_data_create(buffer.baseAddress!, buffer.count, nil,
_dispatch_data_destructor_default())
_swift_dispatch_data_destructor_default())
self.init(data: d)
}

Expand All @@ -64,7 +65,7 @@ public struct DispatchData : RandomAccessCollection {
public init(bytes buffer: UnsafeRawBufferPointer) {
let d = buffer.baseAddress == nil ? _swift_dispatch_data_empty()
: dispatch_data_create(buffer.baseAddress!, buffer.count, nil,
_dispatch_data_destructor_default())
_swift_dispatch_data_destructor_default())
self.init(data: d)
}

Expand Down Expand Up @@ -140,7 +141,7 @@ public struct DispatchData : RandomAccessCollection {
/// - parameter count: The number of bytes to copy.
@available(swift, deprecated: 4, message: "Use append(_: UnsafeRawBufferPointer) instead")
public mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int) {
let data = dispatch_data_create(bytes, count, nil, _dispatch_data_destructor_default())
let data = dispatch_data_create(bytes, count, nil, _swift_dispatch_data_destructor_default())
self.append(DispatchData(data: data))
}

Expand All @@ -151,7 +152,7 @@ public struct DispatchData : RandomAccessCollection {
public mutating func append(_ bytes: UnsafeRawBufferPointer) {
// Nil base address does nothing.
guard bytes.baseAddress != nil else { return }
let data = dispatch_data_create(bytes.baseAddress!, bytes.count, nil, _dispatch_data_destructor_default())
let data = dispatch_data_create(bytes.baseAddress!, bytes.count, nil, _swift_dispatch_data_destructor_default())
self.append(DispatchData(data: data))
}

Expand Down Expand Up @@ -346,15 +347,3 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
internal var _count: Int
internal var _position: DispatchData.Index
}

@_silgen_name("_swift_dispatch_data_empty")
internal func _swift_dispatch_data_empty() -> dispatch_data_t

@_silgen_name("_swift_dispatch_data_destructor_free")
internal func _dispatch_data_destructor_free() -> _DispatchBlock

@_silgen_name("_swift_dispatch_data_destructor_munmap")
internal func _dispatch_data_destructor_munmap() -> _DispatchBlock

@_silgen_name("_swift_dispatch_data_destructor_default")
internal func _dispatch_data_destructor_default() -> _DispatchBlock
168 changes: 1 addition & 167 deletions src/swift/DispatchStubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,176 +53,10 @@ static void _dispatch_overlay_constructor() {

#endif /* USE_OBJC */


// Replicate the SWIFT_CC(swift) calling convention macro from
// swift/include/swift/Runtime/Config.h because it is
// quite awkward to include Config.h and its recursive includes
// in dispatch. This define must be manually kept in synch
#define SWIFT_CC(CC) SWIFT_CC_##CC
#if SWIFT_USE_SWIFTCALL
#define SWIFT_CC_swift __attribute__((swiftcall))
#else
#define SWIFT_CC_swift
#endif

extern "C" dispatch_queue_attr_t _swift_dispatch_queue_concurrent(void);
extern "C" void _swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t));
extern "C" dispatch_queue_t _swift_dispatch_get_main_queue(void);
extern "C" dispatch_data_t _swift_dispatch_data_empty(void);
extern "C" dispatch_block_t _swift_dispatch_data_destructor_default(void);
extern "C" dispatch_block_t _swift_dispatch_data_destructor_free(void);
extern "C" dispatch_block_t _swift_dispatch_data_destructor_munmap(void);
extern "C" dispatch_block_t _swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags, dispatch_qos_class_t qos, int relative_priority, dispatch_block_t block);
extern "C" dispatch_block_t _swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block);
extern "C" void _swift_dispatch_block_cancel(dispatch_block_t block);
extern "C" long _swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout);
extern "C" void _swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block);
extern "C" long _swift_dispatch_block_testcancel(dispatch_block_t block);
extern "C" void _swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
extern "C" void _swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block);
extern "C" void _swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);
extern "C" void _swift_dispatch_release(dispatch_object_t obj);
extern "C" void _swift_dispatch_retain(dispatch_object_t obj);
#if !USE_OBJC
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj);
#endif


SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_queue_attr_t
_swift_dispatch_queue_concurrent(void) {
return DISPATCH_QUEUE_CONCURRENT;
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t)) {
dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_queue_t
_swift_dispatch_get_main_queue(void) {
return dispatch_get_main_queue();
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_data_t
_swift_dispatch_data_empty(void) {
return dispatch_data_empty;
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_block_t
_swift_dispatch_data_destructor_default(void) {
return DISPATCH_DATA_DESTRUCTOR_DEFAULT;
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_block_t
_swift_dispatch_data_destructor_free(void) {
return _dispatch_data_destructor_free;
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_block_t
_swift_dispatch_data_destructor_munmap(void) {
return _dispatch_data_destructor_munmap;
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_block_t
_swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags, dispatch_qos_class_t qos, int relative_priority, dispatch_block_t block) {
return dispatch_block_create_with_qos_class(flags, qos, relative_priority, block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" dispatch_block_t
_swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block) {
return dispatch_block_create(flags, block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_block_cancel(dispatch_block_t block) {
dispatch_block_cancel(block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" long
_swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout) {
return dispatch_block_wait(block, timeout);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block) {
dispatch_block_notify(block, queue, notification_block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" long
_swift_dispatch_block_testcancel(dispatch_block_t block) {
return dispatch_block_testcancel(block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
dispatch_async(queue, block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block) {
dispatch_group_async(group, queue, block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block) {
dispatch_sync(queue, block);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_release(dispatch_object_t obj) {
dispatch_release(obj);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_retain(dispatch_object_t obj) {
dispatch_retain(obj);
}

#define SOURCE(t) \
extern "C" dispatch_source_type_t _swift_dispatch_source_type_##t(void); \
SWIFT_CC(swift) \
DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t \
_swift_dispatch_source_type_##t(void) { \
return DISPATCH_SOURCE_TYPE_##t; \
}

SOURCE(DATA_ADD)
SOURCE(DATA_OR)
SOURCE(DATA_REPLACE)
#if HAVE_MACH
SOURCE(MACH_SEND)
SOURCE(MACH_RECV)
SOURCE(MEMORYPRESSURE)
#endif
#ifndef __linux__
SOURCE(PROC)
#endif
SOURCE(READ)
SOURCE(SIGNAL)
SOURCE(TIMER)
#ifndef __linux__
SOURCE(VNODE)
#endif
SOURCE(WRITE)

#if !USE_OBJC

// For CF functions with 'Get' semantics, the compiler currently assumes that
Expand All @@ -235,7 +69,7 @@ SOURCE(WRITE)
// platforms.
extern "C" void swift_retain(void *);

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {
if (obj) {
swift_retain(obj);
Expand Down
13 changes: 1 addition & 12 deletions src/swift/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// dispatch/queue.h

import CDispatch
import _SwiftDispatchOverlayShims

public final class DispatchSpecificKey<T> {
public init() {}
Expand Down Expand Up @@ -334,9 +335,6 @@ public extension DispatchQueue {
}

#if os(Android)
@_silgen_name("_dispatch_install_thread_detach_callback")
private static func _dispatch_install_thread_detach_callback(_ cb: @escaping @convention(c) () -> Void)

public static func setThreadDetachCallback(_ cb: @escaping @convention(c) () -> Void) {
_dispatch_install_thread_detach_callback(cb)
}
Expand All @@ -348,12 +346,3 @@ private func _destructDispatchSpecificValue(ptr: UnsafeMutableRawPointer?) {
Unmanaged<AnyObject>.fromOpaque(p).release()
}
}

@_silgen_name("_swift_dispatch_queue_concurrent")
internal func _swift_dispatch_queue_concurrent() -> dispatch_queue_attr_t

@_silgen_name("_swift_dispatch_get_main_queue")
internal func _swift_dispatch_get_main_queue() -> dispatch_queue_t

@_silgen_name("_swift_dispatch_apply_current")
internal func _swift_dispatch_apply_current(_ iterations: Int, _ block: @convention(block) (Int) -> Void)
Loading