[ffigen] Remove objc_retain from bindings #1888
Merged
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.
objc_retain
behaves oddly on physical iOS devices, in certain build configurations (release mode plus other flags), when ARC is enabled. Anything from argument reordering (stack corruption) to outright crashes. My hypothesis is that calling this function explicitly under ARC might be undefined behavior that release builds can exploit for optimizations.A more roundabout way of incrementing the ref count, that is more explicitly supported by the compiler, is to use bridge casts. These convert between ARC pointers and ordinary pointers, optionally altering the ref count.
This expression converts
foo
to avoid*
while incrementing its ref count, then converts it back to anid
without changing its ref count.Note that we're still using
objc_retainBlock
throughout the bindings, because it works slightly differently, and can't simply be swapped for a bridge cast (ifobjc_retainBlock
is passed a stack allocated block, it converts it to a heap allocated block).Unrelated change: Deleted objective_c_bindings_generated.dart.m, which is an old unused file.