Makefile: build coreaudio3.m with -fobjc-arc

audio/drivers/coreaudio3.m is written assuming ARC:

    - Uses __bridge / __bridge_retained / __bridge_transfer casts in
      the coreaudio3_init / coreaudio3_write / coreaudio3_free hooks
      to move an NSObject through the void* driver-interface without
      the caller needing to know its real type.
    - Zero manual [x retain] / [x release] / [x autorelease] calls
      anywhere in the file.
    - Assigns Obj-C locals to ivars ('_au = au') and relies on ARC's
      strong-ivar semantics to retain them; dealloc has no matching
      releases.
    - Leaks every +1 local (renderFormat at line 253 / 268, the
      dispatch_semaphore at line 218) under MRC because nothing
      releases them.

The file was enabled by '--enable-coreaudio3' (off by default, per
qb/config.params.sh line 127), but when enabled the top-level qb
Makefile build compiled it without -fobjc-arc - since it was not
in the per-file override list at the top of this Makefile alongside
metal.o and mfi_joypad.o.  Under MRC compilation the file silently
leaks every Obj-C object it creates, which in audio-driver code
means a steady accumulation with every driver reinit (device
hotplug, latency change, etc.).  The __bridge* casts still
compile under MRC (they're ARC's ownership-casts but are also
valid non-ARC syntax), so the build succeeded and nothing
fired - the leaks were invisible until you ran Instruments.

No Xcode project references this file (grepped all of pkg/apple/*/
project.pbxproj - empty result), so the Xcode-side per-file
CLANG_ENABLE_OBJC_ARC=YES path doesn't exist for it yet.  If that
integration ever lands, the Xcode target would also need to flip
it on.

Added coreaudio3.o to the ARC override list alongside metal.o and
mfi_joypad.o.  Also updated the now-stale 'These three Objective-C
files' comment (it had said three but only listed two) and broadened
the ARC-constructs example from '__weak, etc.' to '__weak, __bridge*,
no manual retain/release' to cover this file's shape too.

Thread-safety: unchanged - this is a compile-flag change, no
runtime behaviour is touched.  With ARC on, the existing ivar
assignments and bridge casts produce the intended retain counts;
the per-init-call leaks are reclaimed when the CoreAudio3
instance is released.

Reachability: anyone who enables --enable-coreaudio3.  Default
builds are unaffected.
This commit is contained in:
U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-04-23 22:45:47 +02:00
1 parent 648558d7f2
commit 34987713d0
1 file changed
+8 -6
+8 -6
View File
@@ -266,14 +266,16 @@ $(OBJDIR)/%.o: %.m
@$(if $(Q), $(shell echo echo OBJC $<),)
$(Q)$(CXX) $(OBJCFLAGS) $(DEFINES) -MMD -c -o $@ $<
# ARC (Automatic Reference Counting) overrides. These three Objective-C
# files use ARC-only constructs (__weak, etc.) and must be built with
# -fobjc-arc. The rest of the RetroArch Objective-C code is MRC-written
# (explicit retain/release, NSAutoreleasePool, etc.) and would fail to
# compile under ARC — so we cannot set -fobjc-arc globally. Xcode does
# the equivalent via per-file CLANG_ENABLE_OBJC_ARC=YES build settings.
# ARC (Automatic Reference Counting) overrides. These Objective-C
# files use ARC-only constructs (__weak, __bridge*, no manual
# retain/release) and must be built with -fobjc-arc. The rest of the
# RetroArch Objective-C code is MRC-written (explicit retain/release,
# NSAutoreleasePool, etc.) and would fail to compile under ARC — so
# we cannot set -fobjc-arc globally. Xcode does the equivalent via
# per-file CLANG_ENABLE_OBJC_ARC=YES build settings.
$(OBJDIR)/gfx/drivers/metal.o: OBJCFLAGS += -fobjc-arc
$(OBJDIR)/input/drivers_joypad/mfi_joypad.o: OBJCFLAGS += -fobjc-arc
$(OBJDIR)/audio/drivers/coreaudio3.o: OBJCFLAGS += -fobjc-arc
$(OBJDIR)/%.o: %.S config.h config.mk $(HEADERS)
@mkdir -p $(dir $@)