Navigation Menu

Skip to content
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-9719] Foundation Data API: add copyBytes methods taking UnsafeMutableRawPointer #3554

Closed
atrick opened this issue Jan 21, 2019 · 5 comments

Comments

@atrick
Copy link
Member

atrick commented Jan 21, 2019

Previous ID SR-9719
Radar rdar://47431135
Original Reporter @atrick
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels New Feature
Assignee @phausler
Priority Medium

md5: d4ce88a8326d7388b45b4f881c1d2cd4

relates to:

  • SR-9720 Foundation Data API: add Data.copyBytes methods taking UnsafeRawBufferPointer.

Issue Description:

In the Foundation Data API...

Add these:

public func copyBytes(to pointer: UnsafeMutableRawPointer, count: Int)
public func copyBytes(to pointer: UnsafeMutableRawPointer, from range: Range<Index>) 

Deprecate these:

public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, count: Int)
public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: Range<Index>) 

This way, users will not be forced to incorrectly "bind" memory when they need to copy into a raw pointer and don't know the underlying type.

The raw pointer form is a more general overload, so I expect removing the `UInt8` overloads to be source compatible. They only need to remain as "deprecated" for ABI stability. I'm not sure how to best do this. I think it would even work to remove the public keyword and mark them @usableFromInline so they don't appear in documentation.

I expect this to be completely source compatible but have not verified that with a prototype.

@belkadan
Copy link

Deprecation (deliberately) doesn't affect overload resolution, so if this doesn't go into Swift 5 you'll need to leave both overloads forever, for people backwards-deploying. (Or we need an always-emit-into-client annotation, so that we can backwards-deploy the new thing.)

If someone's made a protocol that matches the existing signature, we don't want to break them either.

@atrick
Copy link
Member Author

atrick commented Jan 23, 2019

@belkadan, excellent points. If this doesn't go into Swift 5, I imagine putting @available(introduced) on the new API and @available(deprecated) on the old one without obsoleting it.

I have no strong feelings about it going into Swift 5.

@belkadan
Copy link

Sorry, my point was that I don't think we can even deprecate the old one. If the pointer you're copying into happens to be an UMP<UInt8>, it'll always pick the old overload even if the new one exists.

@atrick
Copy link
Member Author

atrick commented Jan 23, 2019

Oh, yes of course. Rather than deprecation, we may want an attribute that hides declarations from the documentation. I think we have a number of redundant UnsafePointer-related overloads hanging around. I have mixed feelings about hiding anything from the docs, but I've gotten feedback that the docs need to be simplified to be more approachable.

@atrick
Copy link
Member Author

atrick commented May 26, 2019

Looks like this was done in Swift 5!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants