Commit aed4543
committed
OSX/MACOS/COCOATOUCH: Fix build break from RARCH_AUTORELEASE misuse
0062608 (Make [CocoaView get] honour the +0 "get" convention)
introduced two mistakes in the use of the RARCH_* retain/release
macros in ui/drivers/cocoa/cocoa_common.m. Both are visible under
any ARC build (i.e. every shipping Xcode project); the first is a
hard error, the second is a -Wunused-value warning.
RARCH_RETAIN / RARCH_RELEASE / RARCH_AUTORELEASE are defined in
libretro-common/include/defines/cocoa_defines.h as follows:
#if __has_feature(objc_arc)
#define RARCH_RETAIN(x) (x)
#define RARCH_RELEASE(x) ((void)0)
#define RARCH_AUTORELEASE(x) ((void)0)
...
#else
#define RARCH_RETAIN(x) [(x) retain]
#define RARCH_RELEASE(x) [(x) release]
#define RARCH_AUTORELEASE(x) [(x) autorelease]
#endif
RARCH_RETAIN is expression-form: it evaluates to x (under ARC) or
[x retain] (under MRR), and is meant to appear on the RHS of an
assignment, e.g. _renderView = RARCH_RETAIN([CocoaView get]).
RARCH_RELEASE and RARCH_AUTORELEASE are statement-only: their ARC
expansion is ((void)0), which is not an lvalue or pointer rvalue
and cannot participate in an expression. They must appear on
their own line. ui_cocoa.m already follows this convention
consistently (see e.g. RARCH_AUTORELEASE(metal_layer); after the
CAMetalLayer alloc in -setViewType:).
Site 1 - hard compile error:
view = RARCH_AUTORELEASE([CocoaView new]);
expands under ARC to `view = ((void)0);` which fails with
"assigning to 'CocoaView *__strong' from incompatible type 'void'".
Split into the two-line statement form so the assignment and the
autorelease are independent:
view = [CocoaView new];
RARCH_AUTORELEASE(view);
Semantics are unchanged under both ARC and MRR: view receives +1
from +new, autorelease balances it after nsview_set_ptr has taken
its own retain for g_instance.
Site 2 - -Wunused-value warning:
RARCH_RETAIN(p);
expands under ARC to `(p);` which triggers -Wunused-value on any
build that hardens with -Werror (or just clutters the log
otherwise). Under MRR it expands to `[p retain];` which is a
method call with a discarded return value and does not warn. Cast
the RARCH_RETAIN call to (void) so both expansions discard the
result explicitly:
(void)RARCH_RETAIN(p);
Retain semantics are unchanged under both ARC and MRR.
Audited the rest of the tree; cocoa_common.m was the only offender.
Every other RARCH_AUTORELEASE / RARCH_RELEASE call site already
uses the statement form, and every RARCH_RETAIN call site either
uses expression form (y = RARCH_RETAIN(x)) or was this one
standalone use.1 parent 08a6562 commit aed4543
1 file changed
Lines changed: 19 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
221 | 228 | | |
222 | 229 | | |
223 | 230 | | |
| |||
958 | 965 | | |
959 | 966 | | |
960 | 967 | | |
961 | | - | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
962 | 974 | | |
963 | 975 | | |
964 | | - | |
| 976 | + | |
965 | 977 | | |
966 | 978 | | |
967 | 979 | | |
| |||
0 commit comments