Skip to content

Commit cf22fc2

Browse files
author
Chris Yang
authored
Revert "reland "Migrate darwin common "framework_shared" target to ARC flutter#37049" (flutter#37219)" (flutter#37320)
This reverts commit edb0492.
1 parent 6950689 commit cf22fc2

File tree

8 files changed

+132
-154
lines changed

8 files changed

+132
-154
lines changed

shell/platform/darwin/BUILD.gn

+7-20
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@ 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 = [
4329
"common/framework/Headers/FlutterBinaryMessenger.h",
4430
"common/framework/Headers/FlutterChannels.h",
4531
"common/framework/Headers/FlutterCodecs.h",
@@ -50,12 +36,13 @@ source_set("flutter_channels_arc") {
5036
"common/framework/Source/FlutterStandardCodec_Internal.h",
5137
]
5238

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",
39+
deps = [
40+
"//flutter/common",
41+
"//flutter/flow",
42+
"//flutter/fml",
43+
"//flutter/runtime",
44+
"//flutter/shell/common",
45+
"//third_party/skia",
5946
]
6047

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

shell/platform/darwin/common/BUILD.gn

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

19-
deps = [ "//flutter/fml" ]
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+
]
2028

2129
public_configs = [ "//flutter:config" ]
2230
}
@@ -30,8 +38,8 @@ config("framework_relative_headers") {
3038

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

3644
sources = [
3745
"framework/Source/FlutterChannels.mm",

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

+3-3
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, assign) FlutterStandardDataType type;
347+
@property(readonly, nonatomic) FlutterStandardDataType type;
348348

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

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

360360
/**

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

+63-31
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

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

7-
FLUTTER_ASSERT_ARC
8-
97
#pragma mark - Basic message channel
108

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

6159
- (instancetype)initWithName:(NSString*)name
@@ -71,13 +69,21 @@ - (instancetype)initWithName:(NSString*)name
7169
taskQueue:(NSObject<FlutterTaskQueue>*)taskQueue {
7270
self = [super init];
7371
NSAssert(self, @"Super init cannot be nil");
74-
_name = [name copy];
75-
_messenger = messenger;
76-
_codec = codec;
77-
_taskQueue = taskQueue;
72+
_name = [name retain];
73+
_messenger = [messenger retain];
74+
_codec = [codec retain];
75+
_taskQueue = [taskQueue retain];
7876
return self;
7977
}
8078

79+
- (void)dealloc {
80+
[_name release];
81+
[_messenger release];
82+
[_codec release];
83+
[_taskQueue release];
84+
[super dealloc];
85+
}
86+
8187
- (void)sendMessage:(id)message {
8288
[_messenger sendOnChannel:_name message:[_codec encode:message]];
8389
}
@@ -101,10 +107,7 @@ - (void)setMessageHandler:(FlutterMessageHandler)handler {
101107
}
102108
return;
103109
}
104-
105110
// Grab reference to avoid retain on self.
106-
// `self` might be released before the block, so the block needs to retain the codec to
107-
// make sure it is not released with `self`
108111
NSObject<FlutterMessageCodec>* codec = _codec;
109112
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) {
110113
handler([codec decode:message], ^(id reply) {
@@ -125,19 +128,26 @@ - (void)resizeChannelBuffer:(NSInteger)newSize {
125128
////////////////////////////////////////////////////////////////////////////////
126129
@implementation FlutterError
127130
+ (instancetype)errorWithCode:(NSString*)code message:(NSString*)message details:(id)details {
128-
return [[FlutterError alloc] initWithCode:code message:message details:details];
131+
return [[[FlutterError alloc] initWithCode:code message:message details:details] autorelease];
129132
}
130133

131134
- (instancetype)initWithCode:(NSString*)code message:(NSString*)message details:(id)details {
132135
NSAssert(code, @"Code cannot be nil");
133136
self = [super init];
134137
NSAssert(self, @"Super init cannot be nil");
135-
_code = [code copy];
136-
_message = [message copy];
137-
_details = details;
138+
_code = [code retain];
139+
_message = [message retain];
140+
_details = [details retain];
138141
return self;
139142
}
140143

144+
- (void)dealloc {
145+
[_code release];
146+
[_message release];
147+
[_details release];
148+
[super dealloc];
149+
}
150+
141151
- (BOOL)isEqual:(id)object {
142152
if (self == object) {
143153
return YES;
@@ -159,18 +169,24 @@ - (NSUInteger)hash {
159169
////////////////////////////////////////////////////////////////////////////////
160170
@implementation FlutterMethodCall
161171
+ (instancetype)methodCallWithMethodName:(NSString*)method arguments:(id)arguments {
162-
return [[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments];
172+
return [[[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments] autorelease];
163173
}
164174

165175
- (instancetype)initWithMethodName:(NSString*)method arguments:(id)arguments {
166176
NSAssert(method, @"Method name cannot be nil");
167177
self = [super init];
168178
NSAssert(self, @"Super init cannot be nil");
169-
_method = [method copy];
170-
_arguments = arguments;
179+
_method = [method retain];
180+
_arguments = [arguments retain];
171181
return self;
172182
}
173183

184+
- (void)dealloc {
185+
[_method release];
186+
[_arguments release];
187+
[super dealloc];
188+
}
189+
174190
- (BOOL)isEqual:(id)object {
175191
if (self == object) {
176192
return YES;
@@ -208,7 +224,8 @@ + (instancetype)methodChannelWithName:(NSString*)name
208224
+ (instancetype)methodChannelWithName:(NSString*)name
209225
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
210226
codec:(NSObject<FlutterMethodCodec>*)codec {
211-
return [[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger codec:codec];
227+
return [[[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger
228+
codec:codec] autorelease];
212229
}
213230

214231
- (instancetype)initWithName:(NSString*)name
@@ -223,13 +240,21 @@ - (instancetype)initWithName:(NSString*)name
223240
taskQueue:(NSObject<FlutterTaskQueue>*)taskQueue {
224241
self = [super init];
225242
NSAssert(self, @"Super init cannot be nil");
226-
_name = [name copy];
227-
_messenger = messenger;
228-
_codec = codec;
229-
_taskQueue = taskQueue;
243+
_name = [name retain];
244+
_messenger = [messenger retain];
245+
_codec = [codec retain];
246+
_taskQueue = [taskQueue retain];
230247
return self;
231248
}
232249

250+
- (void)dealloc {
251+
[_name release];
252+
[_messenger release];
253+
[_codec release];
254+
[_taskQueue release];
255+
[super dealloc];
256+
}
257+
233258
- (void)invokeMethod:(NSString*)method arguments:(id)arguments {
234259
FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:method
235260
arguments:arguments];
@@ -260,8 +285,6 @@ - (void)setMethodCallHandler:(FlutterMethodCallHandler)handler {
260285
return;
261286
}
262287
// Make sure the block captures the codec, not self.
263-
// `self` might be released before the block, so the block needs to retain the codec to
264-
// make sure it is not released with `self`
265288
NSObject<FlutterMethodCodec>* codec = _codec;
266289
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) {
267290
FlutterMethodCall* call = [codec decodeMethodCall:message];
@@ -305,7 +328,8 @@ + (instancetype)eventChannelWithName:(NSString*)name
305328
+ (instancetype)eventChannelWithName:(NSString*)name
306329
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
307330
codec:(NSObject<FlutterMethodCodec>*)codec {
308-
return [[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger codec:codec];
331+
return [[[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger
332+
codec:codec] autorelease];
309333
}
310334

311335
- (instancetype)initWithName:(NSString*)name
@@ -320,13 +344,21 @@ - (instancetype)initWithName:(NSString*)name
320344
taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue {
321345
self = [super init];
322346
NSAssert(self, @"Super init cannot be nil");
323-
_name = [name copy];
324-
_messenger = messenger;
325-
_codec = codec;
326-
_taskQueue = taskQueue;
347+
_name = [name retain];
348+
_messenger = [messenger retain];
349+
_codec = [codec retain];
350+
_taskQueue = [taskQueue retain];
327351
return self;
328352
}
329353

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

shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m

-72
Original file line numberDiff line numberDiff line change
@@ -234,78 +234,6 @@ - (void)testBasicMessageChannelTaskQueue {
234234
OCMVerify([binaryMessenger cleanUpConnection:connection]);
235235
}
236236

237-
- (void)testBasicMessageChannelInvokeHandlerAfterChannelReleased {
238-
NSString* channelName = @"foo";
239-
__block NSString* handlerMessage;
240-
__block FlutterBinaryMessageHandler messageHandler;
241-
@autoreleasepool {
242-
FlutterBinaryMessengerConnection connection = 123;
243-
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
244-
id codec = OCMProtocolMock(@protocol(FlutterMessageCodec));
245-
id taskQueue = OCMClassMock([NSObject class]);
246-
FlutterBasicMessageChannel* channel =
247-
[[FlutterBasicMessageChannel alloc] initWithName:channelName
248-
binaryMessenger:binaryMessenger
249-
codec:codec
250-
taskQueue:taskQueue];
251-
252-
FlutterMessageHandler handler = ^(id _Nullable message, FlutterReply callback) {
253-
handlerMessage = message;
254-
};
255-
OCMStub([binaryMessenger
256-
setMessageHandlerOnChannel:channelName
257-
binaryMessageHandler:[OCMArg checkWithBlock:^BOOL(
258-
FlutterBinaryMessageHandler handler) {
259-
messageHandler = handler;
260-
return YES;
261-
}]
262-
taskQueue:taskQueue])
263-
.andReturn(connection);
264-
OCMStub([codec decode:[OCMArg any]]).andReturn(@"decoded message");
265-
[channel setMessageHandler:handler];
266-
}
267-
// Channel is released, messageHandler should still retain the codec. The codec
268-
// internally makes a `decode` call and updates the `handlerMessage` to "decoded message".
269-
messageHandler([NSData data], ^(NSData* data){
270-
});
271-
XCTAssertEqualObjects(handlerMessage, @"decoded message");
272-
}
273-
274-
- (void)testMethodChannelInvokeHandlerAfterChannelReleased {
275-
NSString* channelName = @"foo";
276-
FlutterBinaryMessengerConnection connection = 123;
277-
__block FlutterMethodCall* decodedMethodCall;
278-
__block FlutterBinaryMessageHandler messageHandler;
279-
@autoreleasepool {
280-
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
281-
id codec = OCMProtocolMock(@protocol(FlutterMethodCodec));
282-
id taskQueue = OCMClassMock([NSObject class]);
283-
FlutterMethodChannel* channel = [[FlutterMethodChannel alloc] initWithName:channelName
284-
binaryMessenger:binaryMessenger
285-
codec:codec
286-
taskQueue:taskQueue];
287-
FlutterMethodCallHandler handler = ^(FlutterMethodCall* call, FlutterResult result) {
288-
decodedMethodCall = call;
289-
};
290-
OCMStub([binaryMessenger
291-
setMessageHandlerOnChannel:channelName
292-
binaryMessageHandler:[OCMArg checkWithBlock:^BOOL(
293-
FlutterBinaryMessageHandler handler) {
294-
messageHandler = handler;
295-
return YES;
296-
}]
297-
taskQueue:taskQueue])
298-
.andReturn(connection);
299-
OCMStub([codec decodeMethodCall:[OCMArg any]])
300-
.andReturn([FlutterMethodCall methodCallWithMethodName:@"decoded method call"
301-
arguments:nil]);
302-
[channel setMethodCallHandler:handler];
303-
}
304-
messageHandler([NSData data], ^(NSData* data){
305-
});
306-
XCTAssertEqualObjects(decodedMethodCall.method, @"decoded method call");
307-
}
308-
309237
- (void)testMethodChannelTaskQueue {
310238
NSString* channelName = @"foo";
311239
FlutterBinaryMessengerConnection connection = 123;

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include <cstring>
88

9-
FLUTTER_ASSERT_ARC
10-
119
@implementation FlutterBinaryCodec
1210
+ (instancetype)sharedInstance {
1311
static id _sharedInstance = nil;
@@ -50,7 +48,7 @@ - (NSString*)decode:(NSData*)message {
5048
if (message == nil) {
5149
return nil;
5250
}
53-
return [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
51+
return [[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding] autorelease];
5452
}
5553
@end
5654

0 commit comments

Comments
 (0)