[ffigen] Remove objc_retain from bindings#1888
Merged
Merged
Conversation
PR Health
API leaks
|
| Package | Leaked API symbols |
|---|---|
| objective_c | ObjCBlockBase c._ObjCBlockImpl _ObjCBlockDesc _ObjCBlockRef _ObjCObject _Dart_FinalizableHandle _ObjCProtocol _ObjCSelector _ObjCMethodDesc _ObjCObjectRef _NSZone |
This check can be disabled by tagging the PR with skip-leaking-check.
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
| Files |
|---|
| no missing headers |
All source files should start with a license header.
Unrelated files missing license headers
| Files |
|---|
| pkgs/jni/lib/src/third_party/generated_bindings.dart |
| pkgs/objective_c/lib/src/ns_input_stream.dart |
HosseinYousefi
approved these changes
Jan 14, 2025
1 task
liamappelbe
added a commit
that referenced
this pull request
Feb 6, 2025
This reverts commit 7c7cced.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_retainbehaves 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
footo avoid*while incrementing its ref count, then converts it back to anidwithout changing its ref count.Note that we're still using
objc_retainBlockthroughout the bindings, because it works slightly differently, and can't simply be swapped for a bridge cast (ifobjc_retainBlockis 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.