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-1956] withUnsafePointer shouldn't take its argument as inout #44565

Closed
gribozavr opened this issue Jul 1, 2016 · 9 comments
Closed

[SR-1956] withUnsafePointer shouldn't take its argument as inout #44565

gribozavr opened this issue Jul 1, 2016 · 9 comments
Assignees
Labels
affects ABI Flag: Affects ABI bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@gribozavr
Copy link
Collaborator

Previous ID SR-1956
Radar rdar://problem/25019862
Original Reporter @gribozavr
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, AffectsABI, swift-evolution-proposal-needed
Assignee @jckarter
Priority Medium

md5: 8e53bb39aa7c76996fc1ff7050056a6c

relates to:

  • SR-4542 Pointer to immutable object makes method mutable
  • SR-4649 Don't require & to pass value to UnsafeRawPointer

Issue Description:

Since withUnsafePointer produces a non-mutable pointer, it should not take the argument inout.

NOTE: requires a swift-evolution proposal. (apple/swift-evolution#437

@belkadan
Copy link
Contributor

belkadan commented Jul 1, 2016

I don't think this is correct; we really want `withUnsafePointer` on a global to produce the same address every time.

@gribozavr
Copy link
Collaborator Author

What provides this guarantee?

@belkadan
Copy link
Contributor

belkadan commented Jul 1, 2016

The language and compiler. I can't find a citation, but we've stated this publicly on multiple occasions, and recommended it as a pattern for KVO context IDs.

@gribozavr
Copy link
Collaborator Author

OK, what should we do with non-globals then?

@belkadan
Copy link
Contributor

belkadan commented Jul 1, 2016

It's not usually a pain to make those vars for this purpose. A little annoying, but not overly so.

@gribozavr
Copy link
Collaborator Author

It is not huge issue, but users are complaining about it. You also can't do this for APIs you don't own, so you have to introduce temporaries for no reason.

@bob-wilson
Copy link

As I commented in apple/swift-evolution#437 for those cases where you don't care about getting the same address, I can see the convenience of having an API like withUnsafePointer that does not require an inout argument, but it would be better to introduce a new API with a different name for that purpose.

@bob-wilson
Copy link

We discussed including this change in SE-0127 (https://github.com/apple/swift-evolution/blob/master/proposals/0127-cleaning-up-stdlib-ptr-buffer.md) and decided not to change the behavior of withUnsafePointer in Swift 3. However, we could still consider adding a separate variant in a future that works with immutable values.

@atrick
Copy link
Member

atrick commented Jul 8, 2019

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects ABI Flag: Affects ABI bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

4 participants