Skip to content

[5.10] [stdlib] Avoid materializing strong references in potential dangling unmanaged opaque functions #70964

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

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

Azoy
Copy link
Contributor

@Azoy Azoy commented Jan 17, 2024

  • Explanation: Previously, these functions bit casted pointers to a temporary Instance local (and vice versa) and these causes the compiler to emit retain/releases in certain configurations (notably debug). If the pointer we were converting was a dangling reference to an already released class ref for instance, then this would attempt to retain a bogus pointer which caused crashes. Operate on Unmanaged<Instance> going to and from pointers instead to elide these retain/releases that the compiler wants to add.
  • Scope: Affects users of Unmanaged.toOpaque and Unmanaged.fromOpaque who should mostly be folks like the standard library.
  • Risk: Low. This does not change any existing code relying on the previous semantics, this only fixes previously broken uses of these functions.
  • Testing: Added a new test to exercise that this prevents a crash.
  • Main branch PR: [stdlib] Avoid materializing strong references in potential dangling unmanaged opaque functions #70945
  • Reviewed by: @lorentey @glessard @stephentyrone

[stdlib] Avoid materializing strong references in potential dangling unmanaged opaque functions
@Azoy Azoy requested a review from stephentyrone January 17, 2024 17:44
@Azoy Azoy requested a review from a team as a code owner January 17, 2024 17:44
@Azoy
Copy link
Contributor Author

Azoy commented Jan 17, 2024

@swift-ci please test

@stephentyrone stephentyrone merged commit 97ddeba into swiftlang:release/5.10 Jan 18, 2024
@Azoy Azoy deleted the fix-unmanaged-510 branch January 18, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants