From 9e37dc46b62c3a0509f80f56db5d3993587243e5 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Fri, 30 Jun 2023 11:39:44 -0400 Subject: [PATCH] Convert Crashpad to use ARC See https://chromium.googlesource.com/chromium/src/+/main/docs/mac/arc.md for information about this conversion. Bug: chromium:1280726 Change-Id: I9ed10e9a255eb6b13035b05bcc587c4b6cb7b78e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4651106 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- DEPS | 2 +- build/BUILD.gn | 14 +++--- build/crashpad_buildconfig.gni | 2 + client/BUILD.gn | 20 ++++++-- client/crash_report_database_mac.mm | 4 ++ client/crashpad_client_ios_test.mm | 4 ++ client/ios_handler/exception_processor.mm | 12 +++-- .../ios_handler/exception_processor_test.mm | 4 ++ compat/BUILD.gn | 6 +-- handler/BUILD.gn | 2 +- snapshot/BUILD.gn | 2 +- test/BUILD.gn | 16 +++--- test/ios/BUILD.gn | 6 +-- test/ios/host/BUILD.gn | 4 +- third_party/edo/BUILD.gn | 2 +- tools/BUILD.gn | 20 ++++---- tools/mac/on_demand_service_tool.mm | 10 ++-- util/BUILD.gn | 31 +++++++----- util/ios/ios_system_data_collector.mm | 4 ++ util/mac/launchd.mm | 22 ++++---- util/mac/launchd_test.mm | 50 ++++++++++++------- util/mac/mac_util_test.mm | 9 ++-- util/mac/service_management_test.mm | 8 ++- util/net/http_transport_mac.mm | 22 ++++---- 24 files changed, 174 insertions(+), 102 deletions(-) diff --git a/DEPS b/DEPS index 9258a579..3b97d622 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'f0eebea8bd59215be300ffbe5e7883e85a6fdc0e', + 'e009af846ef4790a90d69fe13ed54df25b93fdef', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/build/BUILD.gn b/build/BUILD.gn index 49a2afa3..3763d2e1 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -31,9 +31,8 @@ config("crashpad_is_in_fuchsia") { } config("flock_always_supported_defines") { - defines = [ - "CRASHPAD_FLOCK_ALWAYS_SUPPORTED=$crashpad_flock_always_supported", - ] + defines = + [ "CRASHPAD_FLOCK_ALWAYS_SUPPORTED=$crashpad_flock_always_supported" ] } group("default_exe_manifest_win") { @@ -52,16 +51,17 @@ config("crashpad_fuzzer_flags") { ldflags = [ "-fsanitize=address" ] } -if (crashpad_is_ios) { - group("ios_enable_arc") { +if (crashpad_is_apple) { + group("apple_enable_arc") { if (crashpad_is_in_chromium) { public_configs = [ "//build/config/compiler:enable_arc" ] } else if (crashpad_is_standalone) { - public_configs = - [ "//third_party/mini_chromium/mini_chromium/build/config:ios_enable_arc" ] + public_configs = [ "//third_party/mini_chromium/mini_chromium/build/config:apple_enable_arc" ] } } +} +if (crashpad_is_ios) { group("ios_xctest") { if (crashpad_is_in_chromium) { public_configs = [ "//build/config/ios:xctest_config" ] diff --git a/build/crashpad_buildconfig.gni b/build/crashpad_buildconfig.gni index 3de3f8db..4e9091a2 100644 --- a/build/crashpad_buildconfig.gni +++ b/build/crashpad_buildconfig.gni @@ -59,6 +59,7 @@ if (crashpad_is_external || crashpad_is_in_dart) { if (crashpad_is_in_chromium) { crashpad_is_mac = is_mac crashpad_is_ios = is_ios + crashpad_is_apple = is_apple crashpad_is_win = is_win crashpad_is_linux = is_linux || is_chromeos crashpad_is_android = is_android @@ -73,6 +74,7 @@ if (crashpad_is_in_chromium) { crashpad_is_mac = mini_chromium_is_mac crashpad_is_ios = mini_chromium_is_ios + crashpad_is_apple = mini_chromium_is_apple crashpad_is_win = mini_chromium_is_win crashpad_is_linux = mini_chromium_is_linux crashpad_is_android = mini_chromium_is_android diff --git a/client/BUILD.gn b/client/BUILD.gn index 5c71dcc9..bc67b32f 100644 --- a/client/BUILD.gn +++ b/client/BUILD.gn @@ -89,6 +89,10 @@ crashpad_static_library("client") { cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union } + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_ios) { deps += [ "../handler:common", @@ -127,7 +131,7 @@ static_library("common") { "simple_string_dictionary.h", ] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "crash_report_database_mac.mm" ] } if (crashpad_is_win) { @@ -147,17 +151,19 @@ static_library("common") { ] deps = [ "../util" ] configs += [ "../build:flock_always_supported_defines" ] + + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } } crashpad_executable("ring_buffer_annotation_load_test") { testonly = true - sources = [ - "ring_buffer_annotation_load_test_main.cc", - ] + sources = [ "ring_buffer_annotation_load_test_main.cc" ] deps = [ ":client", - "../tools:tool_support", "$mini_chromium_source_parent:base", + "../tools:tool_support", ] } @@ -212,6 +218,10 @@ source_set("client_test") { data_deps = [ "../handler:crashpad_handler" ] } + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_win) { data_deps += [ "../handler:crashpad_handler_console", diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index 7221b595..d3bf9850 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -49,6 +49,10 @@ #include "util/ios/scoped_background_task.h" #endif // BUILDFLAG(IS_IOS) +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace { diff --git a/client/crashpad_client_ios_test.mm b/client/crashpad_client_ios_test.mm index 29f3df65..409de95b 100644 --- a/client/crashpad_client_ios_test.mm +++ b/client/crashpad_client_ios_test.mm @@ -27,6 +27,10 @@ #include "testing/platform_test.h" #include "util/thread/thread.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { diff --git a/client/ios_handler/exception_processor.mm b/client/ios_handler/exception_processor.mm index e0b0dcf2..920825dc 100644 --- a/client/ios_handler/exception_processor.mm +++ b/client/ios_handler/exception_processor.mm @@ -54,6 +54,10 @@ #include "client/annotation.h" #include "client/simulate_crash_ios.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace { @@ -65,7 +69,7 @@ struct objc_typeinfo { Class cls_unremapped; }; struct objc_exception { - id obj; + id __unsafe_unretained obj; objc_typeinfo tinfo; }; @@ -219,7 +223,7 @@ class ExceptionPreprocessorState { // preprocessor didn't catch anything, so pass the frames or just the context // to the exception_delegate. void FinalizeUncaughtNSException(id exception) { - if (last_exception() == exception && + if (last_exception() == (__bridge void*)exception && !last_handled_intermediate_dump_.empty() && exception_delegate_->MoveIntermediateDumpAtPathToPending( last_handled_intermediate_dump_)) { @@ -331,10 +335,10 @@ id ObjcExceptionPreprocessor(id exception) { // ignore it. ExceptionPreprocessorState* preprocessor_state = ExceptionPreprocessorState::Get(); - if (preprocessor_state->last_exception() == exception) { + if (preprocessor_state->last_exception() == (__bridge void*)exception) { return preprocessor_state->MaybeCallNextPreprocessor(exception); } - preprocessor_state->set_last_exception(exception); + preprocessor_state->set_last_exception((__bridge void*)exception); static bool seen_first_exception; diff --git a/client/ios_handler/exception_processor_test.mm b/client/ios_handler/exception_processor_test.mm index 8be70890..ad5ea7b6 100644 --- a/client/ios_handler/exception_processor_test.mm +++ b/client/ios_handler/exception_processor_test.mm @@ -19,6 +19,10 @@ #include "gtest/gtest.h" #include "testing/platform_test.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { diff --git a/compat/BUILD.gn b/compat/BUILD.gn index 63cfa6eb..d75c26e1 100644 --- a/compat/BUILD.gn +++ b/compat/BUILD.gn @@ -17,7 +17,7 @@ import("../build/crashpad_buildconfig.gni") config("compat_config") { include_dirs = [] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { include_dirs += [ "mac" ] } @@ -41,7 +41,7 @@ config("compat_config") { } template("compat_target") { - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { # There are no sources to compile, which doesn’t mix will with a # static_library. group(target_name) { @@ -64,7 +64,7 @@ template("compat_target") { compat_target("compat") { sources = [] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/Availability.h", "mac/AvailabilityVersions.h", diff --git a/handler/BUILD.gn b/handler/BUILD.gn index 7cab5191..a2d6f7fb 100644 --- a/handler/BUILD.gn +++ b/handler/BUILD.gn @@ -100,7 +100,7 @@ static_library("common") { "minidump_to_upload_parameters.cc", "minidump_to_upload_parameters.h", ] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/file_limit_annotation.cc", "mac/file_limit_annotation.h", diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 044f33db..a364f956 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -566,7 +566,7 @@ if ((crashpad_is_linux || crashpad_is_android || crashpad_is_fuchsia) && } } -if (crashpad_is_mac || crashpad_is_ios) { +if (crashpad_is_apple) { crashpad_loadable_module("crashpad_snapshot_test_module_crashy_initializer") { testonly = true sources = [ diff --git a/test/BUILD.gn b/test/BUILD.gn index bf21bfee..f20c66f2 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -61,12 +61,10 @@ static_library("test") { # TODO(crbug.com/812974): Remove !crashpad_is_fuchsia when Fuchsia is no # longer treated as a posix platform. if (crashpad_is_posix && !crashpad_is_fuchsia) { - sources += [ - "scoped_set_thread_name_posix.cc", - ] + sources += [ "scoped_set_thread_name_posix.cc" ] } - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/mach_errors.cc", "mac/mach_errors.h", @@ -135,9 +133,9 @@ static_library("test") { data = [ "test_paths_test_data_root.txt" ] deps = [ + "$mini_chromium_source_parent:base", "../compat", "../third_party/googletest:googletest", - "$mini_chromium_source_parent:base", "../util", ] @@ -214,10 +212,10 @@ source_set("test_test") { deps = [ ":test", + "$mini_chromium_source_parent:base", "../compat", "../third_party/googletest:googlemock", "../third_party/googletest:googletest", - "$mini_chromium_source_parent:base", "../util", ] @@ -243,10 +241,10 @@ static_library("googlemock_main") { defines = [ "CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK" ] deps = [ ":test", - "../third_party/googletest:googlemock", - "../third_party/googletest:googletest", "$mini_chromium_source_parent:base", "$mini_chromium_source_parent:base_test_support", + "../third_party/googletest:googlemock", + "../third_party/googletest:googletest", ] if (crashpad_is_android) { deps += [ "../util" ] @@ -263,9 +261,9 @@ static_library("googletest_main") { defines = [ "CRASHPAD_TEST_LAUNCHER_GOOGLETEST" ] deps = [ ":test", - "../third_party/googletest:googletest", "$mini_chromium_source_parent:base", "$mini_chromium_source_parent:base_test_support", + "../third_party/googletest:googletest", ] if (crashpad_is_android) { deps += [ "../util" ] diff --git a/test/ios/BUILD.gn b/test/ios/BUILD.gn index 6e4195ad..6b1deca8 100644 --- a/test/ios/BUILD.gn +++ b/test/ios/BUILD.gn @@ -40,7 +40,7 @@ source_set("google_test_runner") { configs += [ "../..:crashpad_config" ] deps = [ "../$mini_chromium_source_parent:base", - "../../build:ios_enable_arc", + "../../build:apple_enable_arc", "../../build:ios_xctest", "../../test/ios:google_test_runner_shared_headers", ] @@ -57,7 +57,7 @@ source_set("google_test_setup") { deps = [ ":google_test_runner_shared_headers", "../$mini_chromium_source_parent:base", - "../../build:ios_enable_arc", + "../../build:apple_enable_arc", "../../third_party/googletest:googletest", ] frameworks = [ "UIKit.framework" ] @@ -72,7 +72,7 @@ source_set("xcuitests") { ] deps = [ - "../../build:ios_enable_arc", + "../../build:apple_enable_arc", "../../build:ios_xctest", "../../client:common", "../../test/ios/host:app_shared_sources", diff --git a/test/ios/host/BUILD.gn b/test/ios/host/BUILD.gn index 77f145d0..7d2e9849 100644 --- a/test/ios/host/BUILD.gn +++ b/test/ios/host/BUILD.gn @@ -24,7 +24,7 @@ source_set("app_shared_sources") { testonly = true sources = [ "cptest_shared_object.h" ] configs += [ "../../..:crashpad_config" ] - deps = [ "../../../build:ios_enable_arc" ] + deps = [ "../../../build:apple_enable_arc" ] frameworks = [ "UIKit.framework" ] } @@ -42,7 +42,7 @@ static_library("app_host_sources") { configs += [ "../../..:crashpad_config" ] deps = [ ":app_shared_sources", - "../../../build:ios_enable_arc", + "../../../build:apple_enable_arc", "../../../client", "../../../snapshot", "../../../test", diff --git a/third_party/edo/BUILD.gn b/third_party/edo/BUILD.gn index f026f61d..1bd98e17 100644 --- a/third_party/edo/BUILD.gn +++ b/third_party/edo/BUILD.gn @@ -139,6 +139,6 @@ if (crashpad_is_in_chromium) { ] public_configs = [ ":config" ] - deps = [ "../../build:ios_enable_arc" ] + deps = [ "../../build:apple_enable_arc" ] } } diff --git a/tools/BUILD.gn b/tools/BUILD.gn index 845dab47..157ee929 100644 --- a/tools/BUILD.gn +++ b/tools/BUILD.gn @@ -36,8 +36,7 @@ crashpad_executable("dump_minidump_annotations") { ] if (crashpad_is_win) { - cflags = - [ "/wd4201" ] # nonstandard extension used : nameless struct/union + cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union } } @@ -47,10 +46,10 @@ if (!crashpad_is_ios && !crashpad_is_fuchsia) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../build:default_exe_manifest_win", "../client", "../compat", - "$mini_chromium_source_parent:base", "../util", ] } @@ -60,9 +59,9 @@ if (!crashpad_is_ios && !crashpad_is_fuchsia) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../build:default_exe_manifest_win", "../compat", - "$mini_chromium_source_parent:base", "../util", "../util:net", ] @@ -73,8 +72,8 @@ crashpad_executable("base94_encoder") { sources = [ "base94_encoder.cc" ] deps = [ ":tool_support", - "../build:default_exe_manifest_win", "$mini_chromium_source_parent:base", + "../build:default_exe_manifest_win", "../util", ] } @@ -85,11 +84,11 @@ if (!crashpad_is_fuchsia && !crashpad_is_ios) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../build:default_exe_manifest_win", "../compat", "../minidump", "../snapshot", - "$mini_chromium_source_parent:base", "../util", ] @@ -119,9 +118,9 @@ if (crashpad_is_mac || crashpad_is_fuchsia) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../client", "../compat", - "$mini_chromium_source_parent:base", "../util", ] } @@ -133,8 +132,8 @@ if (crashpad_is_mac) { deps = [ ":tool_support", - "../compat", "$mini_chromium_source_parent:base", + "../compat", "../util", ] } @@ -154,8 +153,8 @@ if (crashpad_is_mac) { deps = [ ":tool_support", - "../compat", "$mini_chromium_source_parent:base", + "../compat", "../util", ] } @@ -170,8 +169,9 @@ if (crashpad_is_mac) { deps = [ ":tool_support", - "../compat", "$mini_chromium_source_parent:base", + "../build:apple_enable_arc", + "../compat", "../util", ] } diff --git a/tools/mac/on_demand_service_tool.mm b/tools/mac/on_demand_service_tool.mm index 41896ff8..3faec7a6 100644 --- a/tools/mac/on_demand_service_tool.mm +++ b/tools/mac/on_demand_service_tool.mm @@ -24,12 +24,16 @@ #include #include -#include "base/mac/foundation_util.h" +#include "base/apple/bridging.h" #include "base/strings/sys_string_conversions.h" #include "tools/tool_support.h" #include "util/mac/service_management.h" #include "util/stdlib/objc.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace { @@ -158,13 +162,13 @@ int OnDemandServiceToolMain(int argc, char* argv[]) { } NSMutableDictionary* mutable_job_dictionary = - [[job_dictionary mutableCopy] autorelease]; + [job_dictionary mutableCopy]; mutable_job_dictionary[@LAUNCH_JOBKEY_MACHSERVICES] = mach_services; job_dictionary = mutable_job_dictionary; } CFDictionaryRef job_dictionary_cf = - base::mac::NSToCFCast(job_dictionary); + base::apple::NSToCFPtrCast(job_dictionary); if (!ServiceManagementSubmitJob(job_dictionary_cf)) { fprintf(stderr, "%s: failed to submit job\n", me.c_str()); return EXIT_FAILURE; diff --git a/util/BUILD.gn b/util/BUILD.gn index 4a828a6a..207d3808 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -19,7 +19,7 @@ if (crashpad_is_in_chromium) { import("//build/config/sanitizers/sanitizers.gni") } -if (crashpad_is_mac || crashpad_is_ios) { +if (crashpad_is_apple) { if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { import("//build/config/sysroot.gni") } else { @@ -317,7 +317,7 @@ crashpad_static_library("util") { } } - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/xattr.cc", "mac/xattr.h", @@ -401,10 +401,10 @@ crashpad_static_library("util") { "ios/raw_logging.h", "ios/scoped_background_task.h", "ios/scoped_background_task.mm", - "ios/scoped_vm_read.cc", - "ios/scoped_vm_read.h", "ios/scoped_vm_map.cc", "ios/scoped_vm_map.h", + "ios/scoped_vm_read.cc", + "ios/scoped_vm_read.h", ] } @@ -585,13 +585,12 @@ crashpad_static_library("util") { configs = [ "../build:flock_always_supported_defines" ] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { include_dirs += [ "$root_gen_dir" ] - deps += [ ":mig_output" ] - } - - if (crashpad_is_ios) { - deps += [ "../build:ios_enable_arc" ] + deps += [ + ":mig_output", + "../build:apple_enable_arc", + ] } if (crashpad_is_mac && !crashpad_is_in_fuchsia) { @@ -652,6 +651,10 @@ crashpad_static_library("net") { "$mini_chromium_source_parent:base", ] + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_mac && !crashpad_is_in_fuchsia) { sources += [ "net/http_transport_mac.mm" ] } @@ -804,7 +807,7 @@ source_set("util_test") { sources += [ "posix/scoped_mmap_test.cc" ] } - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/xattr_test.cc", "mach/composite_mach_message_server_test.cc", @@ -840,8 +843,8 @@ source_set("util_test") { sources += [ "ios/ios_intermediate_dump_reader_test.cc", "ios/ios_intermediate_dump_writer_test.cc", - "ios/scoped_vm_read_test.cc", "ios/scoped_vm_map_test.cc", + "ios/scoped_vm_read_test.cc", ] sources -= [ @@ -919,6 +922,10 @@ source_set("util_test") { } } + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_mac) { frameworks = [ "Foundation.framework" ] } diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 564c8e79..93e81dc8 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -27,6 +27,10 @@ #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace { std::string ReadStringSysctlByName(const char* name) { diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index eb94ff37..18149f3d 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -16,12 +16,17 @@ #import +#include "base/apple/bridging.h" #include "base/mac/foundation_util.h" -#include "base/mac/scoped_launch_data.h" #include "base/mac/scoped_cftyperef.h" +#include "base/mac/scoped_launch_data.h" #include "base/strings/sys_string_conversions.h" #include "util/misc/implicit_cast.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { @@ -34,7 +39,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { CFTypeID type_id_cf = CFGetTypeID(property_cf); if (type_id_cf == CFDictionaryGetTypeID()) { - NSDictionary* dictionary_ns = base::mac::CFToNSCast( + NSDictionary* dictionary_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); base::mac::ScopedLaunchData dictionary_launch( LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); @@ -45,7 +50,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } CFPropertyListRef value_cf = - implicit_cast(dictionary_ns[key]); + (__bridge CFPropertyListRef)dictionary_ns[key]; launch_data_t value_launch = CFPropertyToLaunchData(value_cf); if (!value_launch) { return nullptr; @@ -58,15 +63,14 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = dictionary_launch.release(); } else if (type_id_cf == CFArrayGetTypeID()) { - NSArray* array_ns = base::mac::CFToNSCast( + NSArray* array_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); base::mac::ScopedLaunchData array_launch( LaunchDataAlloc(LAUNCH_DATA_ARRAY)); size_t index = 0; for (id element_ns in array_ns) { - CFPropertyListRef element_cf = - implicit_cast(element_ns); + CFPropertyListRef element_cf = (__bridge CFPropertyListRef)element_ns; launch_data_t element_launch = CFPropertyToLaunchData(element_cf); if (!element_launch) { return nullptr; @@ -79,7 +83,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } else if (type_id_cf == CFNumberGetTypeID()) { CFNumberRef number_cf = base::mac::CFCastStrict(property_cf); - NSNumber* number_ns = base::mac::CFToNSCast(number_cf); + NSNumber* number_ns = base::apple::CFToNSPtrCast(number_cf); switch (CFNumberGetType(number_cf)) { case kCFNumberSInt8Type: case kCFNumberSInt16Type: @@ -113,7 +117,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = LaunchDataNewBool(CFBooleanGetValue(boolean_cf)); } else if (type_id_cf == CFStringGetTypeID()) { - NSString* string_ns = base::mac::CFToNSCast( + NSString* string_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); // -fileSystemRepresentation might be more correct than -UTF8String, @@ -125,7 +129,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = LaunchDataNewString([string_ns UTF8String]); } else if (type_id_cf == CFDataGetTypeID()) { - NSData* data_ns = base::mac::CFToNSCast( + NSData* data_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); data_launch = LaunchDataNewOpaque([data_ns bytes], [data_ns length]); } else { diff --git a/util/mac/launchd_test.mm b/util/mac/launchd_test.mm index 5949594c..c069919a 100644 --- a/util/mac/launchd_test.mm +++ b/util/mac/launchd_test.mm @@ -23,10 +23,15 @@ #include #include +#include "base/apple/bridging.h" #include "base/mac/scoped_launch_data.h" #include "gtest/gtest.h" #include "util/stdlib/objc.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { @@ -60,7 +65,8 @@ TEST(Launchd, CFPropertyToLaunchData_Integer) { for (size_t index = 0; index < std::size(integer_nses); ++index) { NSNumber* integer_ns = integer_nses[index]; - launch_data.reset(CFPropertyToLaunchData(integer_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(integer_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_INTEGER); EXPECT_EQ(LaunchDataGetInteger(launch_data.get()), @@ -90,7 +96,8 @@ TEST(Launchd, CFPropertyToLaunchData_FloatingPoint) { for (size_t index = 0; index < std::size(double_nses); ++index) { NSNumber* double_ns = double_nses[index]; - launch_data.reset(CFPropertyToLaunchData(double_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(double_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_REAL); double expected_double_value = [double_ns doubleValue]; @@ -109,17 +116,19 @@ TEST(Launchd, CFPropertyToLaunchData_Boolean) { @autoreleasepool { base::mac::ScopedLaunchData launch_data; - NSNumber* bool_nses[] = { - @NO, - @YES, + // Use CFBooleanRefs here because calling NSToCFPtrCast on an NSNumber + // boolean can fail. Casting an NSNumber expects a CFNumberRef as a result + // but a cast boolean will end up as a CFBooleanRef. + CFBooleanRef bools[] = { + kCFBooleanFalse, + kCFBooleanTrue, }; - for (size_t index = 0; index < std::size(bool_nses); ++index) { - NSNumber* bool_ns = bool_nses[index]; - launch_data.reset(CFPropertyToLaunchData(bool_ns)); + for (CFBooleanRef bool_cf : bools) { + launch_data.reset(CFPropertyToLaunchData(bool_cf)); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_BOOL); - if ([bool_ns boolValue]) { + if (CFBooleanGetValue(bool_cf)) { EXPECT_TRUE(LaunchDataGetBool(launch_data.get())); } else { EXPECT_FALSE(LaunchDataGetBool(launch_data.get())); @@ -140,7 +149,8 @@ TEST(Launchd, CFPropertyToLaunchData_String) { for (size_t index = 0; index < std::size(string_nses); ++index) { NSString* string_ns = string_nses[index]; - launch_data.reset(CFPropertyToLaunchData(string_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(string_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_STRING); EXPECT_STREQ([string_ns UTF8String], @@ -156,7 +166,8 @@ TEST(Launchd, CFPropertyToLaunchData_Data) { static constexpr uint8_t data_c[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2}; NSData* data_ns = [NSData dataWithBytes:data_c length:sizeof(data_c)]; - launch_data.reset(CFPropertyToLaunchData(data_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(data_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_OPAQUE); EXPECT_EQ(LaunchDataGetOpaqueSize(launch_data.get()), sizeof(data_c)); @@ -174,7 +185,8 @@ TEST(Launchd, CFPropertyToLaunchData_Dictionary) { @"key" : @"value", }; - launch_data.reset(CFPropertyToLaunchData(dictionary_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(dictionary_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_DICTIONARY); EXPECT_EQ(LaunchDataDictGetCount(launch_data.get()), [dictionary_ns count]); @@ -193,7 +205,8 @@ TEST(Launchd, CFPropertyToLaunchData_Array) { NSArray* array_ns = @[ @"element_1", @"element_2", ]; - launch_data.reset(CFPropertyToLaunchData(array_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(array_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_ARRAY); EXPECT_EQ(LaunchDataArrayGetCount(launch_data.get()), [array_ns count]); @@ -219,18 +232,20 @@ TEST(Launchd, CFPropertyToLaunchData_NSDate) { base::mac::ScopedLaunchData launch_data; NSDate* date = [NSDate date]; - launch_data.reset(CFPropertyToLaunchData(date)); + launch_data.reset(CFPropertyToLaunchData(base::apple::NSToCFPtrCast(date))); EXPECT_FALSE(launch_data.get()); NSDictionary* date_dictionary = @{ @"key" : @"value", @"date" : date, }; - launch_data.reset(CFPropertyToLaunchData(date_dictionary)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(date_dictionary))); EXPECT_FALSE(launch_data.get()); NSArray* date_array = @[ @"string_1", date, @"string_2", ]; - launch_data.reset(CFPropertyToLaunchData(date_array)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(date_array))); EXPECT_FALSE(launch_data.get()); } } @@ -249,7 +264,8 @@ TEST(Launchd, CFPropertyToLaunchData_RealWorldJobDictionary) { }, }; - launch_data.reset(CFPropertyToLaunchData(job_dictionary)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(job_dictionary))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_DICTIONARY); EXPECT_EQ(LaunchDataDictGetCount(launch_data.get()), 4u); diff --git a/util/mac/mac_util_test.mm b/util/mac/mac_util_test.mm index c086ac65..35c7904d 100644 --- a/util/mac/mac_util_test.mm +++ b/util/mac/mac_util_test.mm @@ -19,10 +19,13 @@ #include -#include "base/mac/scoped_nsobject.h" #include "base/strings/stringprintf.h" #include "gtest/gtest.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { @@ -33,8 +36,8 @@ namespace { // check for with ASSERT_NO_FATAL_FAILURE() or testing::Test::HasFatalFailure(). void SwVers(NSString* argument, std::string* output) { @autoreleasepool { - base::scoped_nsobject pipe([[NSPipe alloc] init]); - base::scoped_nsobject task([[NSTask alloc] init]); + NSPipe* pipe = [[NSPipe alloc] init]; + NSTask* task = [[NSTask alloc] init]; [task setStandardOutput:pipe]; [task setLaunchPath:@"/usr/bin/sw_vers"]; [task setArguments:@[ argument ]]; diff --git a/util/mac/service_management_test.mm b/util/mac/service_management_test.mm index 461228d8..fbf4fddd 100644 --- a/util/mac/service_management_test.mm +++ b/util/mac/service_management_test.mm @@ -20,7 +20,7 @@ #include #include -#include "base/mac/foundation_util.h" +#include "base/apple/bridging.h" #include "base/mac/scoped_cftyperef.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" @@ -30,6 +30,10 @@ #include "util/posix/process_info.h" #include "util/stdlib/objc.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { @@ -124,7 +128,7 @@ TEST(ServiceManagement, SubmitRemoveJob) { @[ @"/bin/sh", @"-c", shell_script_ns, ], }; CFDictionaryRef job_dictionary_cf = - base::mac::NSToCFCast(job_dictionary_ns); + base::apple::NSToCFPtrCast(job_dictionary_ns); // The job may be left over from a failed previous run. if (ServiceManagementIsJobLoaded(kJobLabel)) { diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index 04f5c347..41012799 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -17,8 +17,8 @@ #import #include +#include "base/apple/bridging.h" #include "base/mac/foundation_util.h" -#import "base/mac/scoped_nsobject.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" @@ -28,12 +28,16 @@ #include "util/misc/metrics.h" #include "util/net/http_body.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + // An implementation of NSInputStream that reads from a // crashpad::HTTPBodyStream. @interface CrashpadHTTPBodyStreamTransport : NSInputStream { @private NSStreamStatus _streamStatus; - id _delegate; + id __strong _delegate; crashpad::HTTPBodyStream* _bodyStream; // weak } - (instancetype)initWithBodyStream:(crashpad::HTTPBodyStream*)bodyStream; @@ -154,12 +158,13 @@ NSString* UserAgentString() { // Expected to be CFNetwork. NSBundle* nsurl_bundle = [NSBundle bundleForClass:[NSURLRequest class]]; NSString* bundle_name = base::mac::ObjCCast([nsurl_bundle - objectForInfoDictionaryKey:base::mac::CFToNSCast(kCFBundleNameKey)]); + objectForInfoDictionaryKey:base::apple::CFToNSPtrCast(kCFBundleNameKey)]); if (bundle_name) { user_agent = AppendEscapedFormat(user_agent, @" %@", bundle_name); - NSString* bundle_version = base::mac::ObjCCast([nsurl_bundle - objectForInfoDictionaryKey:base::mac::CFToNSCast(kCFBundleVersionKey)]); + NSString* bundle_version = base::mac::ObjCCast( + [nsurl_bundle objectForInfoDictionaryKey:base::apple::CFToNSPtrCast( + kCFBundleVersionKey)]); if (bundle_version) { user_agent = AppendEscapedFormat(user_agent, @"/%@", bundle_version); } @@ -240,10 +245,9 @@ bool HTTPTransportMac::ExecuteSynchronously(std::string* response_body) { forHTTPHeaderField:base::SysUTF8ToNSString(pair.first)]; } - base::scoped_nsobject input_stream( - [[CrashpadHTTPBodyStreamTransport alloc] - initWithBodyStream:body_stream()]); - [request setHTTPBodyStream:input_stream.get()]; + NSInputStream* input_stream = [[CrashpadHTTPBodyStreamTransport alloc] + initWithBodyStream:body_stream()]; + [request setHTTPBodyStream:input_stream]; NSURLResponse* response = nil; NSError* error = nil;