Skip to content

[SR-1843] Libdispatch: DispatchData api inconsistency  #742

Open
@DevAndArtist

Description

@DevAndArtist
Previous ID SR-1843
Radar None
Original Reporter @DevAndArtist
Type Bug
Environment

Swift 3 from first Xcode 8 beta.

Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug, SDKOverlay
Assignee mww (JIRA)
Priority Medium

md5: 0a7dbaaa991f1ff9845f0d281525f77f

Issue Description:

Please check this diffs between `DispatchData` and `Data`, not all api parts are identical, where some of them should be. As an example different range types are used or labels and generic type `Result` vs. `ResultType` don't match.

Here is a formatted gist: https://gist.github.com/DevAndArtist/4f1cef7a0d58cc786e6ed1837a107a0c

Here is the raw diff:

- public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, Hashable, RandomAccessCollection, MutableCollection {
+ public struct DispatchData : RandomAccessCollection {

-   public typealias ReferenceType = NSData
-   public typealias ReadingOptions = NSData.ReadingOptions
-   public typealias WritingOptions = NSData.WritingOptions
-   public typealias SearchOptions = NSData.SearchOptions
-   public typealias Base64EncodingOptions = NSData.Base64EncodingOptions
-   public typealias Base64DecodingOptions = NSData.Base64DecodingOptions

+   public typealias Iterator = DispatchDataIterator

    public typealias Index = Int

-   public typealias Indices = DefaultRandomAccessIndices<Data>
+   public typealias Indices = DefaultRandomAccessIndices<DispatchData>

+   public static let empty: DispatchData
    
    public enum Deallocator {
-       case virtualMemory
-       case none
       
        case free
        case unmap

-       case custom((UnsafeMutablePointer<UInt8>, Int) -> Swift.Void)
+       case custom(DispatchQueue?, @convention(block) () -> Swift.Void)
    }
    
-   public init(bytes: UnsafePointer<UInt8>, count: Int)
-   public init(bytes: [UInt8])
-   public init(bytes: ArraySlice<UInt8>)
-   public init?(capacity: Int)
-   public init()
-   public init(contentsOf url: URL, options: ReadingOptions = default) throws
-   public init?(base64Encoded base64String: String, options: Base64EncodingOptions = default)
-   public init?(base64Encoded base64Data: Data, options: Base64DecodingOptions = default)

-   public init<SourceType>(buffer: UnsafeBufferPointer<SourceType>)
+   public init(bytes buffer: UnsafeBufferPointer<UInt8>)

-   public init(bytesNoCopy bytes: UnsafeMutablePointer<UInt8>, count: Int, deallocator: Data.Deallocator)
+   public init(bytesNoCopy bytes: UnsafeBufferPointer<UInt8>, deallocator: DispatchData.Deallocator = default)

-   public var count: Int
+   public var count: Int { get }

-   public func withUnsafeBytes<ResultType, ContentType>(_ body: @noescape (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
+   public func withUnsafeBytes<Result, ContentType>(body: @noescape (UnsafePointer<ContentType>) throws -> Result) rethrows -> Result

-   public mutating func withUnsafeMutableBytes<ResultType, ContentType>(_ body: @noescape (UnsafeMutablePointer<ContentType>) throws -> ResultType) rethrows -> ResultType

-   public func enumerateBytes(_ block: @noescape (buffer: UnsafeBufferPointer<UInt8>, byteIndex: Index, stop: inout Bool) -> Swift.Void)
+   public func enumerateBytes(block: @noescape (buffer: UnsafeBufferPointer<UInt8>, byteIndex: Int, stop: inout Bool) -> Swift.Void)

    public mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int)

-   public mutating func append(_ other: Data)
+   public mutating func append(_ other: DispatchData)

    public mutating func append<SourceType>(_ buffer: UnsafeBufferPointer<SourceType>)
    
    public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, count: Int)

-   public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: Range<Index>)
+   public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>)

-   public func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: Range<Index>? = default) -> Int
+   public func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: CountableRange<Index>? = default) -> Int

-   public subscript(index: Index) -> UInt8
+   public subscript(index: Index) -> UInt8 { get }

-   public subscript(bounds: Range<Int>) -> MutableRandomAccessSlice<Data>
+   public subscript(bounds: Range<Int>) -> RandomAccessSlice<DispatchData> { get }

-   public func subdata(in range: Range<Index>) -> Data
+   public func subdata(in range: CountableRange<Index>) -> DispatchData

+   public func region(location: Int) -> (data: DispatchData, offset: Int)

-   public func write(to url: URL, options: WritingOptions = default) throws
-   public func range(of dataToFind: Data, options: SearchOptions = default, in range: Range<Index>? = default) -> Range<Index>?
-   public mutating func resetBytes(in range: Range<Index>)
-   public mutating func replaceBytes(in range: Range<Index>, with data: Data)
-   public func base64EncodedString(_ options: Base64EncodingOptions = default) -> String
-   public func base64EncodedData(_ options: Base64EncodingOptions = default) -> Data
-   public var hashValue: Int { get }
-   public var description: String { get }
-   public var debugDescription: String { get }

    public var startIndex: Index { get }
    public var endIndex: Index { get }
    public func index(before i: Index) -> Index
    public func index(after i: Index) -> Index
    public func makeIterator() -> Iterator
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions