swiftlang / swiftlang/swift-corelibs-libdispatch

[SR-1843] Libdispatch: DispatchData api inconsistency

Open
#742 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug libdispatch SDKOverlay
Dominant language
C
Stars
2.6k
Forks
496
Avg merge
2d 6h
Merged PRs (30d)
3

Description

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Swift DispatchData and Data API declarations in the libdispatch project and compare them with the signatures listed in the issue and linked diff. Review how the Swift 3 overlay exposes these types; done means the intended matching API signatures and range, label, and generic naming differences are resolved and verified by the project’s available checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.