Skip to content

Fix some small divergences from Darwin overlay #170

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
Sep 12, 2016
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
3 changes: 1 addition & 2 deletions src/swift/Block.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
@available(OSX 10.10, iOS 8.0, *)
public class DispatchWorkItem {
internal var _block: _DispatchBlock
internal var _group: DispatchGroup?

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

// Used by DispatchQueue.synchronously<T> to provide a @noescape path through
// Used by DispatchQueue.synchronously<T> to provide a path through
// dispatch_block_t, as we know the lifetime of the block in question.
internal init(flags: DispatchWorkItemFlags = [], noescapeBlock: () -> ()) {
_block = _swift_dispatch_block_create_noescape(dispatch_block_flags_t(flags.rawValue), noescapeBlock)
Expand Down
12 changes: 4 additions & 8 deletions src/swift/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public struct DispatchData : RandomAccessCollection {
/// Initialize a `Data` with copied memory content.
///
/// - parameter bytes: A pointer to the memory. It will be copied.
/// - parameter count: The number of bytes to copy.
public init(bytes buffer: UnsafeBufferPointer<UInt8>) {
let d = dispatch_data_create(buffer.baseAddress!, buffer.count, nil, _dispatch_data_destructor_default())
self.init(data: d)
Expand Down Expand Up @@ -88,7 +87,7 @@ public struct DispatchData : RandomAccessCollection {
public func enumerateBytes(
block: (_ buffer: UnsafeBufferPointer<UInt8>, _ byteIndex: Int, _ stop: inout Bool) -> Void)
{
_swift_dispatch_data_apply(__wrapped.__wrapped) { (data: dispatch_data_t, offset: Int, ptr: UnsafeRawPointer, size: Int) in
_swift_dispatch_data_apply(__wrapped.__wrapped) { (_, offset: Int, ptr: UnsafeRawPointer, size: Int) in
let bytePtr = ptr.bindMemory(to: UInt8.self, capacity: size)
let bp = UnsafeBufferPointer(start: bytePtr, count: size)
var stop = false
Expand Down Expand Up @@ -124,7 +123,7 @@ public struct DispatchData : RandomAccessCollection {
}
}

private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: CountableRange<Index>) {
var copiedCount = 0
_ = CDispatch.dispatch_data_apply(__wrapped.__wrapped) { (data: dispatch_data_t, offset: Int, ptr: UnsafeRawPointer, size: Int) in
let limit = Swift.min((range.endIndex - range.startIndex) - copiedCount, size)
Expand Down Expand Up @@ -179,10 +178,7 @@ public struct DispatchData : RandomAccessCollection {

guard !copyRange.isEmpty else { return 0 }

let bufferCapacity = buffer.count * MemoryLayout<DestinationType>.stride
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: bufferCapacity) {
_copyBytesHelper(to: $0, from: copyRange)
}
_copyBytesHelper(to: buffer.baseAddress!, from: copyRange)
return copyRange.count
}

Expand Down Expand Up @@ -244,7 +240,7 @@ public struct DispatchData : RandomAccessCollection {

public struct DispatchDataIterator : IteratorProtocol, Sequence {

/// Create an iterator over the given DisaptchData
/// Create an iterator over the given DispatchData
public init(_data: DispatchData) {
var ptr: UnsafeRawPointer?
self._count = 0
Expand Down
2 changes: 1 addition & 1 deletion src/swift/Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class DispatchQueue : DispatchObject {
_swift_dispatch_release(wrapped())
}

public func sync(execute workItem: @noescape ()->()) {
public func sync(execute workItem: ()->()) {
dispatch_sync(self.__wrapped, workItem)
}
}
Expand Down