- _swift_dispatch_data_apply(__wrapped) { (data: dispatch_data_t, offset: Int, ptr: UnsafePointer<Void>, size: Int) in
- let bp = UnsafeBufferPointer(start: UnsafePointer<UInt8>(ptr), count: size)
- var stop = false
- block(buffer: bp, byteIndex: offset, stop: &stop)
- return !stop
+ // we know that capturing block in the closure being created/passed to dispatch_data_apply
+ // does not cause block to escape because dispatch_data_apply does not allow its
+ // block argument to escape. Therefore, the usage of withoutActuallyEscaping to
+ // bypass the Swift type system is safe.
+ withoutActuallyEscaping(block) { escapableBlock in
+ _ = CDispatch.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
+ escapableBlock(bp, offset, &stop)
+ return !stop
+ }