Make SDL's Objective-C build with GCC as well as clang. GCC's Objective-C has no ARC and no @autoreleasepool, and the pre-10.15 SDKs lack the larger AudioChannelLayout tags along with the @available keyword to guard them. Gate the CoreAudio 6.1/7.1 layouts on the SDK version, and spell autorelease pools as SDL_OBJC_POOL (new src/SDL_objc_compat.h): under clang it expands to @autoreleasepool itself - with or without ARC, byte-for-byte upstream behavior - and under GCC to an NSAutoreleasePool whose cleanup attribute drains it on any exit from the enclosing scope, early returns included. --- src/audio/coreaudio/SDL_coreaudio.m +++ src/audio/coreaudio/SDL_coreaudio.m @@ -765,6 +765,8 @@ // L R C LFE Ls Rs layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_12; break; +#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || \ + (defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101500) case 7: if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { // L R C LFE Cs Ls Rs @@ -801,6 +803,7 @@ } } break; +#endif default: return SDL_SetError("Unsupported audio channels"); } --- /dev/null +++ src/SDL_objc_compat.h @@ -0,0 +1,52 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2026 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* Compatibility layer that lets SDL's Objective-C sources build both with + clang (with or without ARC; the upstream default) and with GCC, whose + Objective-C has no ARC and no @autoreleasepool. Everything here compiles + away to the stock spelling under clang. */ + +#ifndef SDL_objc_compat_h_ +#define SDL_objc_compat_h_ + +#include + +/* @autoreleasepool replacement. GCC cannot parse @autoreleasepool, so + spell pools as SDL_OBJC_POOL { ... }. The GCC version is a plain + declaration whose cleanup attribute drains the pool when the enclosing + scope exits (early return included) - slightly wider than the braces, + but every use is the first statement of a function body, where the two + are equivalent. For the same reason it can only be used once per scope, + and only at the top of a block. */ +#if defined(__clang__) +#define SDL_OBJC_POOL @autoreleasepool +#else +static inline void SDL_ObjCDrainPool_(NSAutoreleasePool **pool) +{ + [*pool drain]; +} +#define SDL_OBJC_POOL \ + NSAutoreleasePool *sdl_objc_pool_ \ + __attribute__((__cleanup__(SDL_ObjCDrainPool_), __unused__)) \ + = [[NSAutoreleasePool alloc] init]; +#endif + +#endif // SDL_objc_compat_h_ --- src/filesystem/cocoa/SDL_sysfilesystem.m +++ src/filesystem/cocoa/SDL_sysfilesystem.m @@ -31,9 +31,11 @@ #include #include +#include "SDL_objc_compat.h" + char *SDL_SYS_GetBasePath(void) { - @autoreleasepool { + SDL_OBJC_POOL { NSBundle *bundle = [NSBundle mainBundle]; const char *baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String]; const char *base = NULL; @@ -65,7 +67,7 @@ char *SDL_SYS_GetExeName(void) { - @autoreleasepool { + SDL_OBJC_POOL { NSBundle *bundle = [NSBundle mainBundle]; const char *name = [[[bundle infoDictionary] objectForKey:@"CFBundleIdentifier"] UTF8String]; if (!name) { @@ -87,7 +89,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) { - @autoreleasepool { + SDL_OBJC_POOL { char *result = NULL; NSArray *array; @@ -143,7 +145,7 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) { - @autoreleasepool { + SDL_OBJC_POOL { #ifdef SDL_PLATFORM_TVOS SDL_SetError("tvOS does not have persistent storage"); return NULL; --- src/locale/macos/SDL_syslocale.m +++ src/locale/macos/SDL_syslocale.m @@ -24,9 +24,11 @@ #import +#include "SDL_objc_compat.h" + bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { - @autoreleasepool { + SDL_OBJC_POOL { NSArray *languages = NSLocale.preferredLanguages; size_t numlangs = 0; size_t i;