CGColorSpaceCopyICCProfile() in 10.13 SDK results in code that won’t run pre-10.12

Originator:mark
Number:rdar://32883726 Date Originated:2017-06-20
Status:Duplicate/32277480 (Closed) Resolved:2017-06-21
Product:macOS + SDK Product Version:10.13db1 17A264c, Xcode 9b1 9M136h
Classification:Serious Bug Reproducible:Always
 
Area:
Core Graphics

Summary:
<CoreGraphics/CGColorSpace.h> provides two identical identifiers, CGColorSpaceCopyICCProfile() (the older name, since 10.5) and CGColorSpaceCopyICCData() (the newer name, since 10.12). The 10.13 SDK declares these in such a way as to produce code that will not run on 10.11 or earlier.

The 10.13 SDK from Xcode 9b1 9M136h has:

CG_EXTERN CFDataRef __nullable CGColorSpaceCopyICCData(CGColorSpaceRef cg_nullable space)
CG_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0);

#define CGColorSpaceCopyICCProfile CGColorSpaceCopyICCData

meaning that any call to CGColorSpaceCopyICCProfile() will be translated at compile time to a call to CGColorSpaceCopyICCData(), which is only available on 10.12 and later. If you call CGColorSpaceCopyICCProfile() in your program, it’ll reference CGColorSpaceCopyICCData() and will crash at the point of use on 10.11 or earlier where that symbol is not present.

This change in the 10.13 SDK makes it impossible to use this SDK with code that calls CGColorSpaceCopyICCProfile() and is compatible with 10.11 and earlier.

By contrast, the 10.12 SDK has:

CG_EXTERN CFDataRef __nullable CGColorSpaceCopyICCProfile(CGColorSpaceRef cg_nul
lable space);
//__CG_DEPRECATED_WITH_MSG("Don't this function; call "
//                         "`CGColorSpaceCopyICCData' instead.");

CG_EXTERN CFDataRef __nullable CGColorSpaceCopyICCData(CGColorSpaceRef cg_nullable space)
CG_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0);

and the 10.11 SDK (and earlier) has:

CG_EXTERN CFDataRef __nullable CGColorSpaceCopyICCProfile(CGColorSpaceRef __nullable space)
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_6_0);

In order to make it possible to build code that will run on 10.11 and earlier while calling this function, you need to maintain separate declarations of CGColorSpaceCopyICCProfile() and CGColorSpaceCopyICCData() as was done in the 10.12 SDK. If you’d like to transition to the newer name, CGColorSpaceCopyICCData(), it would be prudent to mark CGColorSpaceCopyICCProfile() as deprecated in 10.13 to give developers the opportunity to migrate code to the newer name.

Steps to Reproduce:
Build this program with the 10.13 SDK and run it on 10.11 or earlier.

thirteen$ cat cgcolorspacecopyiccprofile.c
// clang -mmacosx-version-min=10.5 cgcolorspacecopyiccprofile.c -o cgcolorspacecopyiccprofile -framework CoreGraphics
#include <CoreGraphics/CGColorSpace.h>
int main(int argc, char* argv[]) {
  CFDataRef data = CGColorSpaceCopyICCProfile(CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
  return 0;
}
thirteen$ clang -mmacosx-version-min=10.5 cgcolorspacecopyiccprofile.c -o cgcolorspacecopyiccprofile -framework CoreGraphics
thirteen$ ./cgcolorspacecopyiccprofile
thirteen$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.13
BuildVersion:	17A264c

Now, copy it to a 10.11 or earlier system and run it.

ten$ ./cgcolorspacecopyiccprofile

Expected Results:
The program should run on 10.10 or earlier as it did on 10.13. Here, on 10.10:

ten$ ./cgcolorspacecopyiccprofile
ten$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.10.5
BuildVersion:	14F1509

Observed Results:
The program crashes on 10.11 and earlier.

ten$ ./cgcolorspacecopyiccprofile
Segmentation fault: 11
ten$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.10.5
BuildVersion:	14F1509

Version:
10.13db1 17A264c
Xcode 9b1 9M136h with SDK 10.13

Configuration:
When built with the 10.12 SDK or earlier, the program runs correctly (no crash) on all operating system versions, including 10.13, 10.12, 10.11 and earlier.

Comments

Fixed in Xcode 9b2 9M137d.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!