Skip to content

Extend the lifetime of the buffer while copying from a _CocoaArrayWrapper #41779

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
Mar 11, 2022

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Mar 11, 2022

Thanks to @atrick for finding the issue

Fixes rdar://90108215.

@DougGregor
Copy link
Member Author

@swift-ci swift please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It's reasonable to keep the source array alive until the method is done accessing the copied elements. I'm guessing the array might be copied to itself. Actually, any call to NSArray.getObjects needs to be guarded by something that forces the array to be alive as long as the copied array contents are accessed.

Adding the withExtendedLifetime here is definitely harmless.

@atrick
Copy link
Contributor

atrick commented Mar 11, 2022

@lorentey Heads up for any calls to NSArray/NSDictionary getObjects. It copies into a C array without retaining the elements so we need to manually keep the original container alive.

@DougGregor DougGregor merged commit 07bb2b1 into swiftlang:main Mar 11, 2022
@DougGregor DougGregor deleted the extend-cocoaarray-buffer branch March 11, 2022 04:07
@lorentey
Copy link
Member

🙀 Wow, thanks for catching this!

I would've probably looked at this for hours, assuming self was kept alive, and completely missing that this is a __consuming method.

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.

3 participants