Skip to content

Commit 866b670

Browse files
author
Chris Yang
authored
Migrate darwin common "framework_shared" target to ARC (flutter#37049)
1 parent d90e5b7 commit 866b670

File tree

7 files changed

+79
-134
lines changed

7 files changed

+79
-134
lines changed

shell/platform/darwin/BUILD.gn

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ source_set("flutter_channels") {
2626
sources = [
2727
"common/buffer_conversions.h",
2828
"common/buffer_conversions.mm",
29+
]
30+
31+
deps = [ "//flutter/fml" ]
32+
33+
public_deps = [ ":flutter_channels_arc" ]
34+
35+
public_configs = [ "//flutter:config" ]
36+
}
37+
38+
source_set("flutter_channels_arc") {
39+
cflags_objc = flutter_cflags_objc_arc
40+
cflags_objcc = flutter_cflags_objcc_arc
41+
42+
sources = [
2943
"common/framework/Headers/FlutterBinaryMessenger.h",
3044
"common/framework/Headers/FlutterChannels.h",
3145
"common/framework/Headers/FlutterCodecs.h",
@@ -36,13 +50,12 @@ source_set("flutter_channels") {
3650
"common/framework/Source/FlutterStandardCodec_Internal.h",
3751
]
3852

39-
deps = [
40-
"//flutter/common",
41-
"//flutter/flow",
42-
"//flutter/fml",
43-
"//flutter/runtime",
44-
"//flutter/shell/common",
45-
"//third_party/skia",
53+
public = [
54+
"common/framework/Headers/FlutterBinaryMessenger.h",
55+
"common/framework/Headers/FlutterChannels.h",
56+
"common/framework/Headers/FlutterCodecs.h",
57+
"common/framework/Headers/FlutterMacros.h",
58+
"common/framework/Source/FlutterStandardCodec_Internal.h",
4659
]
4760

4861
public_configs = [ "//flutter:config" ]

shell/platform/darwin/common/BUILD.gn

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ source_set("common") {
1616
"command_line.mm",
1717
]
1818

19-
deps = [
20-
"//flutter/common",
21-
"//flutter/flow",
22-
"//flutter/fml",
23-
"//flutter/runtime",
24-
"//flutter/shell/common",
25-
"//third_party/dart/runtime:dart_api",
26-
"//third_party/skia",
27-
]
19+
deps = [ "//flutter/fml" ]
2820

2921
public_configs = [ "//flutter:config" ]
3022
}
@@ -38,8 +30,8 @@ config("framework_relative_headers") {
3830

3931
# Framework code shared between iOS and macOS.
4032
source_set("framework_shared") {
41-
cflags_objc = flutter_cflags_objc
42-
cflags_objcc = flutter_cflags_objcc
33+
cflags_objc = flutter_cflags_objc_arc
34+
cflags_objcc = flutter_cflags_objcc_arc
4335

4436
sources = [
4537
"framework/Source/FlutterChannels.mm",

shell/platform/darwin/common/framework/Headers/FlutterCodecs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,17 @@ FLUTTER_DARWIN_EXPORT
344344
/**
345345
* The type of the encoded values.
346346
*/
347-
@property(readonly, nonatomic) FlutterStandardDataType type;
347+
@property(readonly, nonatomic, assign) FlutterStandardDataType type;
348348

349349
/**
350350
* The number of value items encoded.
351351
*/
352-
@property(readonly, nonatomic) UInt32 elementCount;
352+
@property(readonly, nonatomic, assign) UInt32 elementCount;
353353

354354
/**
355355
* The number of bytes used by the encoding of a single value item.
356356
*/
357-
@property(readonly, nonatomic) UInt8 elementSize;
357+
@property(readonly, nonatomic, assign) UInt8 elementSize;
358358
@end
359359

360360
/**

shell/platform/darwin/common/framework/Source/FlutterChannels.mm

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
66

7+
FLUTTER_ASSERT_ARC
8+
79
#pragma mark - Basic message channel
810

911
static NSString* const kFlutterChannelBuffersChannel = @"dev.flutter/channel-buffers";
@@ -51,9 +53,9 @@ + (instancetype)messageChannelWithName:(NSString*)name
5153
+ (instancetype)messageChannelWithName:(NSString*)name
5254
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
5355
codec:(NSObject<FlutterMessageCodec>*)codec {
54-
return [[[FlutterBasicMessageChannel alloc] initWithName:name
55-
binaryMessenger:messenger
56-
codec:codec] autorelease];
56+
return [[FlutterBasicMessageChannel alloc] initWithName:name
57+
binaryMessenger:messenger
58+
codec:codec];
5759
}
5860

5961
- (instancetype)initWithName:(NSString*)name
@@ -69,21 +71,13 @@ - (instancetype)initWithName:(NSString*)name
6971
taskQueue:(NSObject<FlutterTaskQueue>*)taskQueue {
7072
self = [super init];
7173
NSAssert(self, @"Super init cannot be nil");
72-
_name = [name retain];
73-
_messenger = [messenger retain];
74-
_codec = [codec retain];
75-
_taskQueue = [taskQueue retain];
74+
_name = [name copy];
75+
_messenger = messenger;
76+
_codec = codec;
77+
_taskQueue = taskQueue;
7678
return self;
7779
}
7880

79-
- (void)dealloc {
80-
[_name release];
81-
[_messenger release];
82-
[_codec release];
83-
[_taskQueue release];
84-
[super dealloc];
85-
}
86-
8781
- (void)sendMessage:(id)message {
8882
[_messenger sendOnChannel:_name message:[_codec encode:message]];
8983
}
@@ -108,7 +102,7 @@ - (void)setMessageHandler:(FlutterMessageHandler)handler {
108102
return;
109103
}
110104
// Grab reference to avoid retain on self.
111-
NSObject<FlutterMessageCodec>* codec = _codec;
105+
__weak NSObject<FlutterMessageCodec>* codec = _codec;
112106
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) {
113107
handler([codec decode:message], ^(id reply) {
114108
callback([codec encode:reply]);
@@ -128,26 +122,19 @@ - (void)resizeChannelBuffer:(NSInteger)newSize {
128122
////////////////////////////////////////////////////////////////////////////////
129123
@implementation FlutterError
130124
+ (instancetype)errorWithCode:(NSString*)code message:(NSString*)message details:(id)details {
131-
return [[[FlutterError alloc] initWithCode:code message:message details:details] autorelease];
125+
return [[FlutterError alloc] initWithCode:code message:message details:details];
132126
}
133127

134128
- (instancetype)initWithCode:(NSString*)code message:(NSString*)message details:(id)details {
135129
NSAssert(code, @"Code cannot be nil");
136130
self = [super init];
137131
NSAssert(self, @"Super init cannot be nil");
138-
_code = [code retain];
139-
_message = [message retain];
140-
_details = [details retain];
132+
_code = [code copy];
133+
_message = [message copy];
134+
_details = details;
141135
return self;
142136
}
143137

144-
- (void)dealloc {
145-
[_code release];
146-
[_message release];
147-
[_details release];
148-
[super dealloc];
149-
}
150-
151138
- (BOOL)isEqual:(id)object {
152139
if (self == object) {
153140
return YES;
@@ -169,24 +156,18 @@ - (NSUInteger)hash {
169156
////////////////////////////////////////////////////////////////////////////////
170157
@implementation FlutterMethodCall
171158
+ (instancetype)methodCallWithMethodName:(NSString*)method arguments:(id)arguments {
172-
return [[[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments] autorelease];
159+
return [[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments];
173160
}
174161

175162
- (instancetype)initWithMethodName:(NSString*)method arguments:(id)arguments {
176163
NSAssert(method, @"Method name cannot be nil");
177164
self = [super init];
178165
NSAssert(self, @"Super init cannot be nil");
179-
_method = [method retain];
180-
_arguments = [arguments retain];
166+
_method = [method copy];
167+
_arguments = arguments;
181168
return self;
182169
}
183170

184-
- (void)dealloc {
185-
[_method release];
186-
[_arguments release];
187-
[super dealloc];
188-
}
189-
190171
- (BOOL)isEqual:(id)object {
191172
if (self == object) {
192173
return YES;
@@ -224,8 +205,7 @@ + (instancetype)methodChannelWithName:(NSString*)name
224205
+ (instancetype)methodChannelWithName:(NSString*)name
225206
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
226207
codec:(NSObject<FlutterMethodCodec>*)codec {
227-
return [[[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger
228-
codec:codec] autorelease];
208+
return [[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger codec:codec];
229209
}
230210

231211
- (instancetype)initWithName:(NSString*)name
@@ -240,21 +220,13 @@ - (instancetype)initWithName:(NSString*)name
240220
taskQueue:(NSObject<FlutterTaskQueue>*)taskQueue {
241221
self = [super init];
242222
NSAssert(self, @"Super init cannot be nil");
243-
_name = [name retain];
244-
_messenger = [messenger retain];
245-
_codec = [codec retain];
246-
_taskQueue = [taskQueue retain];
223+
_name = [name copy];
224+
_messenger = messenger;
225+
_codec = codec;
226+
_taskQueue = taskQueue;
247227
return self;
248228
}
249229

250-
- (void)dealloc {
251-
[_name release];
252-
[_messenger release];
253-
[_codec release];
254-
[_taskQueue release];
255-
[super dealloc];
256-
}
257-
258230
- (void)invokeMethod:(NSString*)method arguments:(id)arguments {
259231
FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:method
260232
arguments:arguments];
@@ -285,7 +257,7 @@ - (void)setMethodCallHandler:(FlutterMethodCallHandler)handler {
285257
return;
286258
}
287259
// Make sure the block captures the codec, not self.
288-
NSObject<FlutterMethodCodec>* codec = _codec;
260+
__weak NSObject<FlutterMethodCodec>* codec = _codec;
289261
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) {
290262
FlutterMethodCall* call = [codec decodeMethodCall:message];
291263
handler(call, ^(id result) {
@@ -328,8 +300,7 @@ + (instancetype)eventChannelWithName:(NSString*)name
328300
+ (instancetype)eventChannelWithName:(NSString*)name
329301
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
330302
codec:(NSObject<FlutterMethodCodec>*)codec {
331-
return [[[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger
332-
codec:codec] autorelease];
303+
return [[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger codec:codec];
333304
}
334305

335306
- (instancetype)initWithName:(NSString*)name
@@ -344,21 +315,13 @@ - (instancetype)initWithName:(NSString*)name
344315
taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue {
345316
self = [super init];
346317
NSAssert(self, @"Super init cannot be nil");
347-
_name = [name retain];
348-
_messenger = [messenger retain];
349-
_codec = [codec retain];
350-
_taskQueue = [taskQueue retain];
318+
_name = [name copy];
319+
_messenger = messenger;
320+
_codec = codec;
321+
_taskQueue = taskQueue;
351322
return self;
352323
}
353324

354-
- (void)dealloc {
355-
[_name release];
356-
[_codec release];
357-
[_messenger release];
358-
[_taskQueue release];
359-
[super dealloc];
360-
}
361-
362325
static FlutterBinaryMessengerConnection SetStreamHandlerMessageHandlerOnChannel(
363326
NSObject<FlutterStreamHandler>* handler,
364327
NSString* name,

shell/platform/darwin/common/framework/Source/FlutterCodecs.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <cstring>
88

9+
FLUTTER_ASSERT_ARC
10+
911
@implementation FlutterBinaryCodec
1012
+ (instancetype)sharedInstance {
1113
static id _sharedInstance = nil;
@@ -48,7 +50,7 @@ - (NSString*)decode:(NSData*)message {
4850
if (message == nil) {
4951
return nil;
5052
}
51-
return [[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding] autorelease];
53+
return [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
5254
}
5355
@end
5456

0 commit comments

Comments
 (0)