Merge pull request #3443 from dreampiggy/project/move_assert_check_to_demo_tests

Move the SD_CHECK_CGIMAGE_RETAIN_SOURCE assertion to SDWebImage Demo and Tests only
This commit is contained in:
DreamPiggy 2022-11-14 18:47:05 +08:00 committed by GitHub
commit 430ef4d73c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 25 deletions

View File

@ -173,9 +173,8 @@
53761299155AB74D005750A4 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
5376129B155AB74D005750A4 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
5376129D155AB74D005750A4 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
537612A1155AB74D005750A4 /* SDWebImage Demo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SDWebImage Demo-Info.plist"; sourceTree = "<group>"; };
537612A1155AB74D005750A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
537612A5155AB74D005750A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
537612A7155AB74D005750A4 /* SDWebImage Demo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SDWebImage Demo-Prefix.pch"; sourceTree = "<group>"; };
537612A8155AB74D005750A4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
537612A9155AB74D005750A4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
537612AB155AB74D005750A4 /* MasterViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MasterViewController.h; sourceTree = "<group>"; };
@ -393,9 +392,8 @@
537612A0155AB74D005750A4 /* Supporting Files */ = {
isa = PBXGroup;
children = (
537612A1155AB74D005750A4 /* SDWebImage Demo-Info.plist */,
537612A1155AB74D005750A4 /* Info.plist */,
537612A5155AB74D005750A4 /* main.m */,
537612A7155AB74D005750A4 /* SDWebImage Demo-Prefix.pch */,
);
name = "Supporting Files";
sourceTree = "<group>";
@ -1031,8 +1029,7 @@
baseConfigurationReference = 789EDF4244C66933FDF3E181 /* Pods-SDWebImage iOS Demo.debug.xcconfig */;
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SDWebImage Demo/SDWebImage Demo-Prefix.pch";
INFOPLIST_FILE = "SDWebImage Demo/SDWebImage Demo-Info.plist";
INFOPLIST_FILE = "SDWebImage Demo/Info.plist";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
TARGETED_DEVICE_FAMILY = "1,2";
@ -1044,8 +1041,7 @@
baseConfigurationReference = 0829378FA7103DD8649CCCF3 /* Pods-SDWebImage iOS Demo.release.xcconfig */;
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SDWebImage Demo/SDWebImage Demo-Prefix.pch";
INFOPLIST_FILE = "SDWebImage Demo/SDWebImage Demo-Info.plist";
INFOPLIST_FILE = "SDWebImage Demo/Info.plist";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
TARGETED_DEVICE_FAMILY = "1,2";

View File

@ -1,10 +0,0 @@
//
// Prefix header for all source files of the 'SDWebImage Demo' target in the 'SDWebImage Demo' project
//
#import <Availability.h>
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif

17
Podfile
View File

@ -64,3 +64,20 @@ target 'Tests TV' do
platform :tvos, '9.0'
all_test_pods
end
# Inject macro during SDWebImage Demo and Tests
post_install do |installer_representation|
installer_representation.generated_pod_targets.each do |target|
if target.pod_name == "SDWebImage"
build_settings = target.build_settings
build_settings.each do |configuration, build_setting|
if configuration == :debug
config = build_setting.xcconfig
old_value = config.attributes['GCC_PREPROCESSOR_DEFINITIONS']
config.attributes['GCC_PREPROCESSOR_DEFINITIONS'] = old_value + ' SD_CHECK_CGIMAGE_RETAIN_SOURCE=1'
config.save_as(target.xcconfig_path(configuration))
end
end
end
end
end

View File

@ -18,14 +18,16 @@
#import <ImageIO/ImageIO.h>
#import <CoreServices/CoreServices.h>
#if SD_CHECK_CGIMAGE_RETAIN_SOURCE
#import <dlfcn.h>
// SPI to check thread safe during Example and Test
static CGImageSourceRef (*SDCGImageGetImageSource)(CGImageRef);
#endif
// Specify File Size for lossy format encoding, like JPEG
static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestinationRequestedFileSize";
// Only assert on Debug mode
#define SD_CHECK_CGIMAGE_RETAIN_SOURCE DEBUG && \
((__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_15_0)) || \
((__TV_OS_VERSION_MAX_ALLOWED >= __TVOS_15_0))
// This strip the un-wanted CGImageProperty, like the internal CGImageSourceRef in iOS 15+
// However, CGImageCreateCopy still keep those CGImageProperty, not suit for our use case
static CGImageRef __nullable SDCGImageCreateCopy(CGImageRef cg_nullable image) {
@ -301,8 +303,13 @@ static CGImageRef __nullable SDCGImageCreateCopy(CGImageRef cg_nullable image) {
if (@available(iOS 15, tvOS 15, *)) {
// Assert here to check CGImageRef should not retain the CGImageSourceRef and has possible thread-safe issue (this is behavior on iOS 15+)
// If assert hit, fire issue to https://github.com/SDWebImage/SDWebImage/issues and we update the condition for this behavior check
extern CGImageSourceRef CGImageGetImageSource(CGImageRef);
NSCAssert(!CGImageGetImageSource(imageRef), @"Animated Coder created CGImageRef should not retain CGImageSourceRef, which may cause thread-safe issue without lock");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SDCGImageGetImageSource = dlsym(RTLD_DEFAULT, "CGImageGetImageSource");
});
if (SDCGImageGetImageSource) {
NSCAssert(!SDCGImageGetImageSource(imageRef), @"Animated Coder created CGImageRef should not retain CGImageSourceRef, which may cause thread-safe issue without lock");
}
}
#endif