This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS: Migrate accessibility_bridge to ARC #55570
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was odd practice here before. Did we add this line to fix a crash before? If so, this line didn't 100% fix that crash since it's still used in the previous 3 lines.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes! I noticed this line too and was going to leave a comment here referencing the commit here: #31351
This bumps the refcount to ensure that
oldObjectisn't released before it's used again below, if the refcount is decremented in this method itself. It's a relatively common pattern in old non-ARC tree-related Obj-C code.I didn't mentally work through the gymnastics of how
oldObject's refcount could be indirectly knocked down one in this method, but we are manipulating the children of our parent node here, which seems like the exact sort of case where that can happen.This is the sort of case that motivated the creation of ARC -- and IIRC a very old WWDC presentation where ARC was introduced covered exactly this scenario (as well as the more basic cases of incorrect setter implementations that don't check for assignment of the same value already held by the ivar.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try mentally working through it.
oldObjectwithin its parent's children intopositionInChildlist.oldObjectfromobjects, which releasesoldObject. If that was the only thing that had retained it, thenoldObjectis dead and is dealloc'ed.oldObject.parent ...on the next line. Boom.To fix this, we need to ensure that we retain it for the duration we need it. We could have retained it, then manually released it after the call to oldObject.parent, but autorelease is much more future-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah in fact there's a comment that @stuartmorgan left pointing out this exact scenario if you scroll down far enough on the patch.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's 11 years old, but I think this is the talk I was thinking of that covers a simpler version of this scenario, though I swear there was a talk where they went through more complex scenarios like trees.
https://www.youtube.com/watch?v=ANlpDUIF-1o#t=9m19s
Edit: might have been this one around 48 minutes or so:
https://devstreaming-cdn.apple.com/videos/wwdc/2011/323/ipad_c.m3u8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the TL;DR here is that this line is an excellent argument in favour of ARC migration.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it's a great sign of how successful ARC was that there are now a lot of people whose reaction to this line is "that's weird" rather than immediately knowing exactly why it's there and what it's doing. Everyone learning this pattern (usually the hard way) is definitely something we can do without 🙂
Both the line and the discussion! The line because not having this kind of foot gun in the first place is clearly a safety win, but also the discussion because it illustrates that being able to correctly maintain non-ARC code is a shrinking/fading knowledge domain, so any non-ARC code we have will be an increasing liability over time.