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
[SR-1843] Libdispatch: DispatchData api inconsistency #742
Comments
cc @phausler. It'd probably also be good to get Matt Wright in here, but it looks like he hasn't registered an account yet. |
@belkadan talked to both via twitter already. (I missed `UnsafeBufferPointer` vs. `UnsafeMutablePointer` at first glance but I updated the post). There are still a few other small things to polish. |
Comment by Daniel A. Steffen (JIRA) it would be helpful if you could provide the specific adjustements that you would like to see rather than a generic diff, there are parts of the NSData API that don't make sense for DispatchData (and cannot be cheaply implemented in the Overlay which is a requirement for being backwards deployable to older versions of Darwin). |
Comment by Matt Wright (JIRA) Yeah, some of these we just can't match. Some I can match to Data (the initialiser was me attempting to match against an earlier API version, I think). Many of the mutable accessors cannot be implemented with DispatchData (and hence why its a separate type). |
By api consistency, I'd wish types and labels to match with `Data` (it depends on how the Swift 3 api will look like when its not beta anymore). I'm fine with keeping both types. Here are some wishes (its up to you to decide what to change): 1. Decide whether it's best to use `UnsafeBufferPointer` against `UnsafeMutablePointer` + `count` in both apis, so initializer and functions would match. Additionally we could have both version in both libdispatch and foundation. 2. Can `.custom` get visibility to immutable pointer of the data so one would be able to call for instance `free(pointer)`:
3. [Optional] Consider to add more initializer
4. [Optional] Can this initializer become generic, so we could store different types inside `DispatchData`?
5. Match initializer or provide both versions to both libdispatch and foundation.
6. Match type names and labels.
7. [Optional] Here for instance we don't use `UnsafeBufferPointer`
8. [Optional] Is there any technical reason for using different range types?
9. Check `Index` vs. `Int` 10. [Optional but highly wished] Make `DispatchData` convertible to `Data` and vice versa (extension?). 11. [Optional] Consider to add these protocols:
|
From the Swift side, I'm in favor of Unsafe[Mutable]BufferPointer over Unsafe[Mutable]Pointer. |
I was just about the file a bug about DispatchData not supporting RangeReplaceableCollection. Since the two are toll-free bridged, theoretically you could get a DispatchData, hand it off to an Obj-C thunk which casts a dispatch_data_t to an NSData*, which you then bridge back to a Foundation Data. AFAIK, no copying happens in any of that, which means they are just two abstractions for the same underlying object. Surely they should both be able to support exactly the same interfaces? |
Environment
Swift 3 from first Xcode 8 beta.
Additional Detail from JIRA
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:
The text was updated successfully, but these errors were encountered: