From 3a112cfefdc636d2e937d665d85c3c9da181c9d7 Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Tue, 18 May 2021 14:34:34 -0400 Subject: [PATCH] Modernize Objective-C Via tools/mac/rewrite_modern_objc.py in the Chromium repo Bug: chromium:324079 Change-Id: I3160331899b3ea75e0ebc78abd9a0a84e9339b40 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2904179 Reviewed-by: Mark Mentovai Commit-Queue: Leonard Grey --- tools/mac/on_demand_service_tool.mm | 5 ++--- util/mac/launchd.mm | 2 +- util/mac/launchd_test.mm | 14 +++++++------- util/net/http_transport_mac.mm | 14 +++++--------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tools/mac/on_demand_service_tool.mm b/tools/mac/on_demand_service_tool.mm index 70de1b52..7b3e1041 100644 --- a/tools/mac/on_demand_service_tool.mm +++ b/tools/mac/on_demand_service_tool.mm @@ -152,13 +152,12 @@ int OnDemandServiceToolMain(int argc, char* argv[]) { dictionaryWithCapacity:options.mach_services.size()]; for (std::string mach_service : options.mach_services) { NSString* mach_service_ns = base::SysUTF8ToNSString(mach_service); - [mach_services setObject:@YES forKey:mach_service_ns]; + mach_services[mach_service_ns] = @YES; } NSMutableDictionary* mutable_job_dictionary = [[job_dictionary mutableCopy] autorelease]; - [mutable_job_dictionary setObject:mach_services - forKey:@LAUNCH_JOBKEY_MACHSERVICES]; + mutable_job_dictionary[@LAUNCH_JOBKEY_MACHSERVICES] = mach_services; job_dictionary = mutable_job_dictionary; } diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index ef5a6061..37748eea 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -45,7 +45,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } CFPropertyListRef value_cf = - implicit_cast([dictionary_ns objectForKey:key]); + implicit_cast(dictionary_ns[key]); launch_data_t value_launch = CFPropertyToLaunchData(value_cf); if (!value_launch) { return nullptr; diff --git a/util/mac/launchd_test.mm b/util/mac/launchd_test.mm index b793a9b9..6b51ee29 100644 --- a/util/mac/launchd_test.mm +++ b/util/mac/launchd_test.mm @@ -78,14 +78,14 @@ TEST(Launchd, CFPropertyToLaunchData_FloatingPoint) { @0.0, @1.0, @-1.0, - [NSNumber numberWithFloat:std::numeric_limits::min()], - [NSNumber numberWithFloat:std::numeric_limits::max()], - [NSNumber numberWithDouble:std::numeric_limits::min()], - [NSNumber numberWithDouble:std::numeric_limits::max()], + @(std::numeric_limits::min()), + @(std::numeric_limits::max()), + @(std::numeric_limits::min()), + @(std::numeric_limits::max()), @3.1415926535897932, - [NSNumber numberWithDouble:std::numeric_limits::infinity()], - [NSNumber numberWithDouble:std::numeric_limits::quiet_NaN()], - [NSNumber numberWithDouble:std::numeric_limits::signaling_NaN()], + @(std::numeric_limits::infinity()), + @(std::numeric_limits::quiet_NaN()), + @(std::numeric_limits::signaling_NaN()), }; for (size_t index = 0; index < base::size(double_nses); ++index) { diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index 8faa1b8a..b9be11c8 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -52,13 +52,11 @@ NSString* UserAgentString() { // CFNetwork would use the main bundle’s CFBundleName, or the main // executable’s filename if none. - user_agent = AppendEscapedFormat( - user_agent, @"%@", [NSString stringWithUTF8String:PACKAGE_NAME]); + user_agent = AppendEscapedFormat(user_agent, @"%@", @PACKAGE_NAME); // CFNetwork would use the main bundle’s CFBundleVersion, or the string // “(unknown version)” if none. - user_agent = AppendEscapedFormat( - user_agent, @"/%@", [NSString stringWithUTF8String:PACKAGE_VERSION]); + user_agent = AppendEscapedFormat(user_agent, @"/%@", @PACKAGE_VERSION); // Expected to be CFNetwork. NSBundle* nsurl_bundle = [NSBundle bundleForClass:[NSURLRequest class]]; @@ -78,10 +76,8 @@ NSString* UserAgentString() { if (uname(&os) != 0) { PLOG(WARNING) << "uname"; } else { - user_agent = AppendEscapedFormat( - user_agent, @" %@", [NSString stringWithUTF8String:os.sysname]); - user_agent = AppendEscapedFormat( - user_agent, @"/%@", [NSString stringWithUTF8String:os.release]); + user_agent = AppendEscapedFormat(user_agent, @" %@", @(os.sysname)); + user_agent = AppendEscapedFormat(user_agent, @"/%@", @(os.release)); // CFNetwork just uses the equivalent of os.machine to obtain the native // (kernel) architecture. Here, give the process’ architecture as well as @@ -98,7 +94,7 @@ NSString* UserAgentString() { #endif user_agent = AppendEscapedFormat(user_agent, @" (%@", arch); - NSString* machine = [NSString stringWithUTF8String:os.machine]; + NSString* machine = @(os.machine); if (![machine isEqualToString:arch]) { user_agent = AppendEscapedFormat(user_agent, @"; %@", machine); }