Skip to content

Commit fe6a4bc

Browse files
committed
Merge branch 'swift-3.0-branch' into das-darwin-006-merge-swift-3.0-branch
2 parents f932a06 + e2d5eb5 commit fe6a4bc

File tree

7 files changed

+43
-38
lines changed

7 files changed

+43
-38
lines changed

src/swift/Block.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public class DispatchWorkItem {
4141

4242
// Temporary for swift-corelibs-foundation
4343
@available(*, deprecated, renamed: "DispatchWorkItem(qos:flags:block:)")
44-
public convenience init(group: DispatchGroup, qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @convention(block) () -> ()) {
44+
public convenience init(group: DispatchGroup, qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @escaping @convention(block) () -> ()) {
4545
self.init(qos: qos, flags: flags, block: block)
4646

4747
}
4848

49-
public init(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @convention(block) () -> ()) {
49+
public init(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], block: @escaping @convention(block) () -> ()) {
5050
_block = dispatch_block_create_with_qos_class(dispatch_block_flags_t(flags.rawValue),
5151
qos.qosClass.rawValue.rawValue, Int32(qos.relativePriority), block)
5252
}
@@ -77,7 +77,7 @@ public class DispatchWorkItem {
7777
qos: DispatchQoS = .unspecified,
7878
flags: DispatchWorkItemFlags = [],
7979
queue: DispatchQueue,
80-
execute: @convention(block) () -> Void)
80+
execute: @escaping @convention(block) () -> ())
8181
{
8282
if qos != .unspecified || !flags.isEmpty {
8383
let item = DispatchWorkItem(qos: qos, flags: flags, block: execute)

src/swift/Data.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct DispatchData : RandomAccessCollection {
3535
// which is only made available on platforms with Objective-C.
3636
case custom(DispatchQueue?, () -> Void)
3737

38-
private var _deallocator: (DispatchQueue?, @convention(block) () -> Void) {
38+
fileprivate var _deallocator: (DispatchQueue?, @convention(block) () -> Void) {
3939
switch self {
4040
case .free: return (nil, _dispatch_data_destructor_free())
4141
case .unmap: return (nil, _dispatch_data_destructor_munmap())
@@ -80,19 +80,19 @@ public struct DispatchData : RandomAccessCollection {
8080
var size = 0
8181
let data = CDispatch.dispatch_data_create_map(__wrapped.__wrapped, &ptr, &size)
8282
let contentPtr = ptr!.bindMemory(
83-
to: ContentType.self, capacity: size / strideof(ContentType.self))
83+
to: ContentType.self, capacity: size / MemoryLayout<ContentType>.stride)
8484
defer { _fixLifetime(data) }
8585
return try body(contentPtr)
8686
}
8787

8888
public func enumerateBytes(
89-
block: @noescape (buffer: UnsafeBufferPointer<UInt8>, byteIndex: Int, stop: inout Bool) -> Void)
89+
block: @noescape (_ buffer: UnsafeBufferPointer<UInt8>, _ byteIndex: Int, _ stop: inout Bool) -> Void)
9090
{
9191
_swift_dispatch_data_apply(__wrapped.__wrapped) { (data: dispatch_data_t, offset: Int, ptr: UnsafeRawPointer, size: Int) in
9292
let bytePtr = ptr.bindMemory(to: UInt8.self, capacity: size)
9393
let bp = UnsafeBufferPointer(start: bytePtr, count: size)
9494
var stop = false
95-
block(buffer: bp, byteIndex: offset, stop: &stop)
95+
block(bp, offset, &stop)
9696
return !stop
9797
}
9898
}
@@ -118,7 +118,10 @@ public struct DispatchData : RandomAccessCollection {
118118
///
119119
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
120120
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
121-
self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * sizeof(SourceType.self))
121+
let count = buffer.count * MemoryLayout<SourceType>.stride;
122+
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: count) {
123+
self.append($0, count: count)
124+
}
122125
}
123126

124127
private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
@@ -151,7 +154,7 @@ public struct DispatchData : RandomAccessCollection {
151154

152155
/// Copy the contents of the data into a buffer.
153156
///
154-
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `sizeof(DestinationType) * buffer.count` then the first N bytes will be copied into the buffer.
157+
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `MemoryLayout<DestinationType>.stride * buffer.count` then the first N bytes will be copied into the buffer.
155158
/// - precondition: The range must be within the bounds of the data. Otherwise `fatalError` is called.
156159
/// - parameter buffer: A buffer to copy the data into.
157160
/// - parameter range: A range in the data to copy into the buffer. If the range is empty, this function will return 0 without copying anything. If the range is nil, as much data as will fit into `buffer` is copied.
@@ -169,15 +172,17 @@ public struct DispatchData : RandomAccessCollection {
169172
precondition(r.endIndex >= 0)
170173
precondition(r.endIndex <= cnt, "The range is outside the bounds of the data")
171174

172-
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * sizeof(DestinationType.self), r.count))
175+
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, r.count))
173176
} else {
174-
copyRange = 0..<Swift.min(buffer.count * sizeof(DestinationType.self), cnt)
177+
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, cnt)
175178
}
176179

177180
guard !copyRange.isEmpty else { return 0 }
178181

179-
let pointer : UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer.baseAddress!)
180-
_copyBytesHelper(to: pointer, from: copyRange)
182+
let bufferCapacity = buffer.count * MemoryLayout<DestinationType>.stride
183+
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: bufferCapacity) {
184+
_copyBytesHelper(to: $0, from: copyRange)
185+
}
181186
return copyRange.count
182187
}
183188

src/swift/Dispatch.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public enum DispatchTimeoutResult {
134134
/// dispatch_group
135135

136136
public extension DispatchGroup {
137-
public func notify(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], queue: DispatchQueue, execute work: @convention(block) () -> ()) {
137+
public func notify(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], queue: DispatchQueue, execute work: @escaping @convention(block) () -> ()) {
138138
if #available(OSX 10.10, iOS 8.0, *), qos != .unspecified || !flags.isEmpty {
139139
let item = DispatchWorkItem(qos: qos, flags: flags, block: work)
140140
dispatch_group_notify(self.__wrapped, queue.__wrapped, item._block)

src/swift/IO.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ public extension DispatchIO {
3434
public static let strictInterval = IntervalFlags(rawValue: 1)
3535
}
3636

37-
public class func read(fromFileDescriptor: Int32, maxLength: Int, runningHandlerOn queue: DispatchQueue, handler: (data: DispatchData, error: Int32) -> Void) {
37+
public class func read(fromFileDescriptor: Int32, maxLength: Int, runningHandlerOn queue: DispatchQueue, handler: @escaping (_ data: DispatchData, _ error: Int32) -> Void) {
3838
dispatch_read(fromFileDescriptor, maxLength, queue.__wrapped) { (data: dispatch_data_t, error: Int32) in
39-
handler(data: DispatchData(data: data), error: error)
39+
handler(DispatchData(data: data), error)
4040
}
4141
}
4242

43-
public class func write(toFileDescriptor: Int32, data: DispatchData, runningHandlerOn queue: DispatchQueue, handler: (data: DispatchData?, error: Int32) -> Void) {
43+
public class func write(toFileDescriptor: Int32, data: DispatchData, runningHandlerOn queue: DispatchQueue, handler: @escaping (_ data: DispatchData?, _ error: Int32) -> Void) {
4444
dispatch_write(toFileDescriptor, data.__wrapped.__wrapped, queue.__wrapped) { (data: dispatch_data_t?, error: Int32) in
45-
handler(data: data.flatMap { DispatchData(data: $0) }, error: error)
45+
handler(data.flatMap { DispatchData(data: $0) }, error)
4646
}
4747
}
4848

4949
public convenience init(
5050
type: StreamType,
5151
fileDescriptor: Int32,
5252
queue: DispatchQueue,
53-
cleanupHandler: (error: Int32) -> Void)
53+
cleanupHandler: @escaping (_ error: Int32) -> Void)
5454
{
5555
self.init(__type: type.rawValue, fd: fileDescriptor, queue: queue, handler: cleanupHandler)
5656
}
@@ -61,7 +61,7 @@ public extension DispatchIO {
6161
oflag: Int32,
6262
mode: mode_t,
6363
queue: DispatchQueue,
64-
cleanupHandler: (error: Int32) -> Void)
64+
cleanupHandler: @escaping (_ error: Int32) -> Void)
6565
{
6666
self.init(__type: type.rawValue, path: path, oflag: oflag, mode: mode, queue: queue, handler: cleanupHandler)
6767
}
@@ -70,20 +70,20 @@ public extension DispatchIO {
7070
type: StreamType,
7171
io: DispatchIO,
7272
queue: DispatchQueue,
73-
cleanupHandler: (error: Int32) -> Void)
73+
cleanupHandler: @escaping (_ error: Int32) -> Void)
7474
{
7575
self.init(__type: type.rawValue, io: io, queue: queue, handler: cleanupHandler)
7676
}
7777

78-
public func read(offset: off_t, length: Int, queue: DispatchQueue, ioHandler: (done: Bool, data: DispatchData?, error: Int32) -> Void) {
78+
public func read(offset: off_t, length: Int, queue: DispatchQueue, ioHandler: @escaping (_ done: Bool, _ data: DispatchData?, _ error: Int32) -> Void) {
7979
dispatch_io_read(self.__wrapped, offset, length, queue.__wrapped) { (done: Bool, data: dispatch_data_t?, error: Int32) in
80-
ioHandler(done: done, data: data.flatMap { DispatchData(data: $0) }, error: error)
80+
ioHandler(done, data.flatMap { DispatchData(data: $0) }, error)
8181
}
8282
}
8383

84-
public func write(offset: off_t, data: DispatchData, queue: DispatchQueue, ioHandler: (done: Bool, data: DispatchData?, error: Int32) -> Void) {
84+
public func write(offset: off_t, data: DispatchData, queue: DispatchQueue, ioHandler: @escaping (_ done: Bool, _ data: DispatchData?, _ error: Int32) -> Void) {
8585
dispatch_io_write(self.__wrapped, offset, data.__wrapped.__wrapped, queue.__wrapped) { (done: Bool, data: dispatch_data_t?, error: Int32) in
86-
ioHandler(done: done, data: data.flatMap { DispatchData(data: $0) }, error: error)
86+
ioHandler(done, data.flatMap { DispatchData(data: $0) }, error)
8787
}
8888
}
8989

src/swift/Queue.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct DispatchQueueAttributes : OptionSet {
3232
public static let serial = DispatchQueueAttributes(rawValue: 1<<0)
3333
public static let concurrent = DispatchQueueAttributes(rawValue: 1<<1)
3434

35-
private var _translatedValue: DispatchQueue.Attributes {
35+
fileprivate var _translatedValue: DispatchQueue.Attributes {
3636
if self.contains(.concurrent) { return .concurrent }
3737
return []
3838
}
@@ -48,7 +48,7 @@ public extension DispatchQueue {
4848
@available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
4949
public static let initiallyInactive = Attributes(rawValue: 1<<2)
5050

51-
private func _attr() -> dispatch_queue_attr_t? {
51+
fileprivate func _attr() -> dispatch_queue_attr_t? {
5252
var attr: dispatch_queue_attr_t? = nil
5353

5454
if self.contains(.concurrent) {
@@ -95,7 +95,7 @@ public extension DispatchQueue {
9595
public enum GlobalQueueDeprecatedPriority {
9696
case qosBackground
9797

98-
private var _translatedValue: DispatchQoS.QoSClass {
98+
fileprivate var _translatedValue: DispatchQoS.QoSClass {
9999
switch self {
100100
case .qosBackground: return .background
101101
}
@@ -221,15 +221,15 @@ public extension DispatchQueue {
221221
group: DispatchGroup? = nil,
222222
qos: DispatchQoS = .unspecified,
223223
flags: DispatchWorkItemFlags = [],
224-
execute work: @convention(block) () -> Void)
224+
execute work: @escaping @convention(block) () -> Void)
225225
{
226226
if group == nil && qos == .unspecified && flags.isEmpty {
227227
// Fast-path route for the most common API usage
228228
CDispatch.dispatch_async(self.__wrapped, work)
229229
return
230230
}
231231

232-
var block: @convention(block) () -> Void = work
232+
var block: @escaping @convention(block) () -> Void = work
233233
if #available(OSX 10.10, iOS 8.0, *), (qos != .unspecified || !flags.isEmpty) {
234234
let workItem = DispatchWorkItem(qos: qos, flags: flags, block: work)
235235
block = workItem._block
@@ -309,7 +309,7 @@ public extension DispatchQueue {
309309
deadline: DispatchTime,
310310
qos: DispatchQoS = .unspecified,
311311
flags: DispatchWorkItemFlags = [],
312-
execute work: @convention(block) () -> Void)
312+
execute work: @escaping @convention(block) () -> Void)
313313
{
314314
if #available(OSX 10.10, iOS 8.0, *), qos != .unspecified || !flags.isEmpty {
315315
let item = DispatchWorkItem(qos: qos, flags: flags, block: work)
@@ -323,7 +323,7 @@ public extension DispatchQueue {
323323
wallDeadline: DispatchWallTime,
324324
qos: DispatchQoS = .unspecified,
325325
flags: DispatchWorkItemFlags = [],
326-
execute work: @convention(block) () -> Void)
326+
execute work: @escaping @convention(block) () -> Void)
327327
{
328328
if #available(OSX 10.10, iOS 8.0, *), qos != .unspecified || !flags.isEmpty {
329329
let item = DispatchWorkItem(qos: qos, flags: flags, block: work)

src/swift/Time.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct DispatchTime : Comparable {
2626

2727
public static let distantFuture = DispatchTime(rawValue: ~0)
2828

29-
private init(rawValue: dispatch_time_t) {
29+
fileprivate init(rawValue: dispatch_time_t) {
3030
self.rawValue = rawValue
3131
}
3232

@@ -64,7 +64,7 @@ public struct DispatchWallTime : Comparable {
6464

6565
public static let distantFuture = DispatchWallTime(rawValue: ~0)
6666

67-
private init(rawValue: dispatch_time_t) {
67+
fileprivate init(rawValue: dispatch_time_t) {
6868
self.rawValue = rawValue
6969
}
7070

src/swift/Wrapper.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ public class DispatchIO : DispatchObject {
9191
}
9292

9393
internal init(__type: UInt, fd: Int32, queue: DispatchQueue,
94-
handler: (error: Int32) -> Void) {
94+
handler: @escaping (_ error: Int32) -> Void) {
9595
__wrapped = dispatch_io_create(__type, fd, queue.__wrapped, handler)
9696
}
9797

9898
internal init(__type: UInt, path: UnsafePointer<Int8>, oflag: Int32,
99-
mode: mode_t, queue: DispatchQueue, handler: (error: Int32) -> Void) {
99+
mode: mode_t, queue: DispatchQueue, handler: @escaping (_ error: Int32) -> Void) {
100100
__wrapped = dispatch_io_create_with_path(__type, path, oflag, mode, queue.__wrapped, handler)
101101
}
102102

103103
internal init(__type: UInt, io: DispatchIO,
104-
queue: DispatchQueue, handler: (error: Int32) -> Void) {
104+
queue: DispatchQueue, handler: @escaping (_ error: Int32) -> Void) {
105105
__wrapped = dispatch_io_create_with_io(__type, io.__wrapped, queue.__wrapped, handler)
106106
}
107107

@@ -113,7 +113,7 @@ public class DispatchIO : DispatchObject {
113113
_swift_dispatch_release(wrapped())
114114
}
115115

116-
public func barrier(execute: () -> ()) {
116+
public func barrier(execute: @escaping () -> ()) {
117117
dispatch_io_barrier(self.__wrapped, execute)
118118
}
119119

0 commit comments

Comments
 (0)