libass: build: Macro fails to identify Mac OS X version

libass version

5298859c298d3c570d8d7e3b883a0d63490659b8

Is it a regression?

No response

How did you invoke configure?

CC=gcc-mp-7 ./configure

System Information

OS: Mac OS X 10.5.8 PowerPC CPU: PowerPC G5 MacPorts: 2.10.2

Toolchain

gcc-mp-7 (MacPorts gcc7 7.5.0_4) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@(#)PROGRAM:ld  PROJECT:ld64-127.2
configured to support archs: i386 x86_64 ppc ppc64 armv6 armv7
LTO support using: LLVM version 3.3

Log of the error

  CC       libass/ass_coretext.lo
libass/ass_coretext.c: In function 'get_font_file':
libass/ass_coretext.c:92:30: error: 'kCTFontURLAttribute' undeclared (first use in this function); did you mean kCTFontSizeAttribute'?
     else if (CHECK_AVAILABLE(kCTFontURLAttribute, macOS 10.6, *)) {
                              ^
libass/ass_coretext.c:38:50: note: in definition of macro 'CHECK_AVAILABLE'
 #define CHECK_AVAILABLE(sym, ...) (!!(intptr_t) &sym)
                                                  ^~~
libass/ass_coretext.c:92:30: note: each undeclared identifier is reported only once for each function it appears in
     else if (CHECK_AVAILABLE(kCTFontURLAttribute, macOS 10.6, *)) {
                              ^
libass/ass_coretext.c:38:50: note: in definition of macro 'CHECK_AVAILABLE'
 #define CHECK_AVAILABLE(sym, ...) (!!(intptr_t) &sym)
                                                  ^~~
make[1]: *** [libass/ass_coretext.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

Configuration log

No response

Additional info

In libass/ass_coretext.c code for Mac OS X higher or equal to 10.6 is enclosed with check to __MAC_10_6 :

static char *get_font_file(CTFontDescriptorRef fontd)
{
    CFURLRef url = NULL;
    if (false) {}
#ifdef __MAC_10_6
    // Declared in SDKs since 10.6, including iOS SDKs
    else if (CHECK_AVAILABLE(kCTFontURLAttribute, macOS 10.6, *)) {
        url = CTFontDescriptorCopyAttribute(fontd, kCTFontURLAttribute);
    }
#endif
#if !TARGET_OS_IPHONE && (!defined(__MAC_10_6) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6)
    // ATS is declared deprecated in newer macOS SDKs
    // and not declared at all in iOS SDKs
    else {
        CTFontRef font = CTFontCreateWithFontDescriptor(fontd, 0, NULL);
        if (!font)
            return NULL;
        ATSFontRef ats_font = CTFontGetPlatformFont(font, NULL);
        FSRef fs_ref;
        if (ATSFontGetFileReference(ats_font, &fs_ref) == noErr)
            url = CFURLCreateFromFSRef(NULL, &fs_ref);
        CFRelease(font);
    }
#endif

But __MAC_10_6 is defined in 10.5 SDK.

#ifndef __AVAILABILITY__
#define __AVAILABILITY__


#define __MAC_10_0      1000
#define __MAC_10_1      1010
#define __MAC_10_2      1020
#define __MAC_10_3      1030
#define __MAC_10_4      1040
#define __MAC_10_5      1050
#define __MAC_10_6      1060
#define __MAC_NA        9999   /* not available */

#define __IPHONE_2_0     20000  
#define __IPHONE_NA      99999

#include <AvailabilityInternal.h>

With __MAC_10_6 available, compilation fails as it tries to use code for 10.6 or later. Rewriting conditional statement like this fixes incorrect detection and library works fine on 10.5.8 (tested with FFmpeg playback). As condition for OS version is not changed drastically, it should work correctly on higher OS versions.

--- libass/ass_coretext.c	2024-10-12 22:19:55.000000000 +0300
+++ libass/ass_coretext.c	2024-10-12 22:21:30.000000000 +0300
@@ -87,25 +87,21 @@
 static char *get_font_file(CTFontDescriptorRef fontd)
 {
     CFURLRef url = NULL;
-    if (false) {}
-#ifdef __MAC_10_6
-    // Declared in SDKs since 10.6, including iOS SDKs
-    else if (CHECK_AVAILABLE(kCTFontURLAttribute, macOS 10.6, *)) {
-        url = CTFontDescriptorCopyAttribute(fontd, kCTFontURLAttribute);
-    }
-#endif
-#if !TARGET_OS_IPHONE && (!defined(__MAC_10_6) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6)
+#if !TARGET_OS_IPHONE && (__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6)
     // ATS is declared deprecated in newer macOS SDKs
     // and not declared at all in iOS SDKs
-    else {
-        CTFontRef font = CTFontCreateWithFontDescriptor(fontd, 0, NULL);
-        if (!font)
-            return NULL;
-        ATSFontRef ats_font = CTFontGetPlatformFont(font, NULL);
-        FSRef fs_ref;
-        if (ATSFontGetFileReference(ats_font, &fs_ref) == noErr)
-            url = CFURLCreateFromFSRef(NULL, &fs_ref);
-        CFRelease(font);
+    CTFontRef font = CTFontCreateWithFontDescriptor(fontd, 0, NULL);
+    if (!font)
+        return NULL;
+    ATSFontRef ats_font = CTFontGetPlatformFont(font, NULL);
+    FSRef fs_ref;
+    if (ATSFontGetFileReference(ats_font, &fs_ref) == noErr)
+        url = CFURLCreateFromFSRef(NULL, &fs_ref);
+    CFRelease(font);
+#else
+    // Declared in SDKs since 10.6, including iOS SDKs
+    if (CHECK_AVAILABLE(kCTFontURLAttribute, macOS 10.6, *)) {
+        url = CTFontDescriptorCopyAttribute(fontd, kCTFontURLAttribute);
     }
 #endif
     if (!url)

harbuzz uses similar approach with MAC_OS_X_VERSION_MIN_REQUIRED: https://github.com/harfbuzz/harfbuzz/pull/1578/commits/87ea0abba236d784a8ecfb47faf94e8b8f1c240d.

Apple mentions in Availability.h that macros with OS version like __MAC_10_6 aren’t supposed to be used, their value must be used directly with __MAC_OS_X_VERSION_MIN_REQUIRED:

It is also possible to use the *_VERSION_MIN_REQUIRED in source code to make one
source base that can be compiled to target a range of OS versions.  It is best
to not use the _MAC_* and __IPHONE_* macros for comparisons, but rather their values.
That is because you might get compiled on an old OS that does not define a later
OS version macro, and in the C preprocessor undefined values evaluate to zero
in expresssions, which could cause the #if expression to evaluate in an unexpected
way.

    #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
        // code only compiled when targeting Mac OS X and not iPhone
        // note use of 1050 instead of __MAC_10_5
        #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
            // code in here might run on pre-Leopard OS
        #else
            // code here can assume Leopard or later
        #endif
    #endif

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 31 (19 by maintainers)

Commits related to this issue

Most upvoted comments

It should be possible to verify exactly if any relevant differences exist by extracting 10.5 SDK from images of Xcode 3.1.4, Xcode 3.2.6 and Xcode 4.2

Hmm. I have old copies of 3.1.4, 3.2.1 (several), 3.2.2 and 3.2.6 lying around, and it turns out that all of them, even 3.1.4 (xcode314_2809_developerdvd.dmg), already contained a definition of __MAC_10_6 in MacOSX10.5.sdk. I’ve just downloaded 3.1.3 and 3.1[.0] from Apple’s archive, and they contain it, too. The next older version is 2.5, which lacks MacOSX10.5.sdk entirely.

(Turns out 7-Zip alone can open everything, at least the Windows GUI version.)

Could it be that PPC Leopard shipped with a system header that differed from Xcode’s? or with a different Xcode build that isn’t available in Apple’s archive?

Thanks for the added context! So it seems plausible that @saxfun may have actually tested a version of the code with this block removed by accident. And your original test on 10.5 actually took place before I switched from AvailabilityMacros.h to Availability.h for consistency with #607, so that’s entirely on me. I’ve updated the commit message in #838 to reflect this.

@toreonify Completely unrelated to the issue discussed here, but I noticed you use ld64-127 +llvm33 on your system; it is generally held that ld64-97 works better across powerpc macOS, including Leopard (i.e. this is my personal conclusion as well, but also opinion of MacPorts upstream). You may wish to use that linker instead. It may be worth switching to +llvm34 as well, but I have no hard evidence it gonna improve performance, rather that it is safe to use.

This can be done as:

[ sudo port -v -n upgrade --enforce-variants ld64-97 -llvm33 +llvm34 ]
sudo port -v -n upgrade --enforce-variants ld64 -ld64_127 +ld64_97

It is also possible to switch the system to using modern gcc14 instead of gcc7, which gonna have very tangible benefits in terms of what can be successfully compiled, but that gonna require a bit of manual tweaks to MacPorts set-up. (Ping me if that is of interest.)

Yeah, I rather referred to AvailabilityInternal.h which was mentioned in passing above.

It’s just transitively included by Availability.h—and in newer SDKs, by AvailabilityMacros.h too—so some definitions are located inside it.

BTW, Availability.h does not exist in 10.4, so using it leaves broken the build on Tiger. (This is not my personal concern, but there are people using Tiger on older hardware.)

Tiger lacks Core Text entirely, so this module is not attempted to be built there.

It should be possible to verify exactly if any relevant differences exist by extracting 10.5 SDK from images of Xcode 3.1.4, Xcode 3.2.6 and Xcode 4.2 (with Pacifist or via a procedure described in XcodeLegacy repo, for example).

@barracuda156 I can download these versions and check for differences in 10.5 SDK for each version and post results here. I have Pacifist already on my machine, so it won’t be a problem.