-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate darwin common "framework_shared" target to ARC #37049
Changes from all commits
425aea4
3f5368c
a92065a
1265796
3f8c2fb
7b6a5a4
6157ddf
35559e1
ea06e4e
1fde705
700da71
0dd00d5
12a7fd7
0a5aec4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h" | ||
|
||
FLUTTER_ASSERT_ARC | ||
|
||
#pragma mark - Basic message channel | ||
|
||
static NSString* const kFlutterChannelBuffersChannel = @"dev.flutter/channel-buffers"; | ||
|
@@ -51,9 +53,9 @@ + (instancetype)messageChannelWithName:(NSString*)name | |
+ (instancetype)messageChannelWithName:(NSString*)name | ||
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger | ||
codec:(NSObject<FlutterMessageCodec>*)codec { | ||
return [[[FlutterBasicMessageChannel alloc] initWithName:name | ||
binaryMessenger:messenger | ||
codec:codec] autorelease]; | ||
return [[FlutterBasicMessageChannel alloc] initWithName:name | ||
binaryMessenger:messenger | ||
codec:codec]; | ||
} | ||
|
||
- (instancetype)initWithName:(NSString*)name | ||
|
@@ -69,21 +71,13 @@ - (instancetype)initWithName:(NSString*)name | |
taskQueue:(NSObject<FlutterTaskQueue>*)taskQueue { | ||
self = [super init]; | ||
NSAssert(self, @"Super init cannot be nil"); | ||
_name = [name retain]; | ||
_messenger = [messenger retain]; | ||
_codec = [codec retain]; | ||
_taskQueue = [taskQueue retain]; | ||
_name = [name copy]; | ||
_messenger = messenger; | ||
_codec = codec; | ||
_taskQueue = taskQueue; | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_name release]; | ||
[_messenger release]; | ||
[_codec release]; | ||
[_taskQueue release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)sendMessage:(id)message { | ||
[_messenger sendOnChannel:_name message:[_codec encode:message]]; | ||
} | ||
|
@@ -108,7 +102,7 @@ - (void)setMessageHandler:(FlutterMessageHandler)handler { | |
return; | ||
} | ||
// Grab reference to avoid retain on self. | ||
NSObject<FlutterMessageCodec>* codec = _codec; | ||
__weak NSObject<FlutterMessageCodec>* codec = _codec; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong, codec needs to be captured by the block to live longer than the channel object. |
||
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) { | ||
handler([codec decode:message], ^(id reply) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just early return if codec is nil? if codec is nil, should this handler be called? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't looked into the implementation details. But just looking at this method without context, the behavior is different if we early return when codec is nil. The current behavior is that the handler is always called regardless of the codec's value. So I'd say we should keep it the same behavior and maybe update the code later if we think that's a bug. Edit: we probably shouldn't even support a nil codec, maybe we can add an FML_DCHECK. But it is probably a good idea doing it in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed there's not real-world case where a nil codec makes sense. Asserting it's not nil sgtm in a followup patch. |
||
callback([codec encode:reply]); | ||
|
@@ -128,26 +122,19 @@ - (void)resizeChannelBuffer:(NSInteger)newSize { | |
//////////////////////////////////////////////////////////////////////////////// | ||
@implementation FlutterError | ||
+ (instancetype)errorWithCode:(NSString*)code message:(NSString*)message details:(id)details { | ||
return [[[FlutterError alloc] initWithCode:code message:message details:details] autorelease]; | ||
return [[FlutterError alloc] initWithCode:code message:message details:details]; | ||
} | ||
|
||
- (instancetype)initWithCode:(NSString*)code message:(NSString*)message details:(id)details { | ||
NSAssert(code, @"Code cannot be nil"); | ||
self = [super init]; | ||
NSAssert(self, @"Super init cannot be nil"); | ||
_code = [code retain]; | ||
_message = [message retain]; | ||
_details = [details retain]; | ||
_code = [code copy]; | ||
_message = [message copy]; | ||
_details = details; | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_code release]; | ||
[_message release]; | ||
[_details release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (BOOL)isEqual:(id)object { | ||
if (self == object) { | ||
return YES; | ||
|
@@ -169,24 +156,18 @@ - (NSUInteger)hash { | |
//////////////////////////////////////////////////////////////////////////////// | ||
@implementation FlutterMethodCall | ||
+ (instancetype)methodCallWithMethodName:(NSString*)method arguments:(id)arguments { | ||
return [[[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments] autorelease]; | ||
return [[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments]; | ||
} | ||
|
||
- (instancetype)initWithMethodName:(NSString*)method arguments:(id)arguments { | ||
NSAssert(method, @"Method name cannot be nil"); | ||
self = [super init]; | ||
NSAssert(self, @"Super init cannot be nil"); | ||
_method = [method retain]; | ||
_arguments = [arguments retain]; | ||
_method = [method copy]; | ||
_arguments = arguments; | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_method release]; | ||
[_arguments release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (BOOL)isEqual:(id)object { | ||
if (self == object) { | ||
return YES; | ||
|
@@ -224,8 +205,7 @@ + (instancetype)methodChannelWithName:(NSString*)name | |
+ (instancetype)methodChannelWithName:(NSString*)name | ||
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger | ||
codec:(NSObject<FlutterMethodCodec>*)codec { | ||
return [[[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger | ||
codec:codec] autorelease]; | ||
return [[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger codec:codec]; | ||
} | ||
|
||
- (instancetype)initWithName:(NSString*)name | ||
|
@@ -240,21 +220,13 @@ - (instancetype)initWithName:(NSString*)name | |
taskQueue:(NSObject<FlutterTaskQueue>*)taskQueue { | ||
self = [super init]; | ||
NSAssert(self, @"Super init cannot be nil"); | ||
_name = [name retain]; | ||
_messenger = [messenger retain]; | ||
_codec = [codec retain]; | ||
_taskQueue = [taskQueue retain]; | ||
_name = [name copy]; | ||
_messenger = messenger; | ||
_codec = codec; | ||
_taskQueue = taskQueue; | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_name release]; | ||
[_messenger release]; | ||
[_codec release]; | ||
[_taskQueue release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)invokeMethod:(NSString*)method arguments:(id)arguments { | ||
FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:method | ||
arguments:arguments]; | ||
|
@@ -285,7 +257,7 @@ - (void)setMethodCallHandler:(FlutterMethodCallHandler)handler { | |
return; | ||
} | ||
// Make sure the block captures the codec, not self. | ||
NSObject<FlutterMethodCodec>* codec = _codec; | ||
__weak NSObject<FlutterMethodCodec>* codec = _codec; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same q here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong, codec needs to be captured by the block to live longer than the channel object. _codec was actually nil in some scenarios if not captured strongly. |
||
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) { | ||
FlutterMethodCall* call = [codec decodeMethodCall:message]; | ||
handler(call, ^(id result) { | ||
|
@@ -328,8 +300,7 @@ + (instancetype)eventChannelWithName:(NSString*)name | |
+ (instancetype)eventChannelWithName:(NSString*)name | ||
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger | ||
codec:(NSObject<FlutterMethodCodec>*)codec { | ||
return [[[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger | ||
codec:codec] autorelease]; | ||
return [[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger codec:codec]; | ||
} | ||
|
||
- (instancetype)initWithName:(NSString*)name | ||
|
@@ -344,21 +315,13 @@ - (instancetype)initWithName:(NSString*)name | |
taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue { | ||
self = [super init]; | ||
NSAssert(self, @"Super init cannot be nil"); | ||
_name = [name retain]; | ||
_messenger = [messenger retain]; | ||
_codec = [codec retain]; | ||
_taskQueue = [taskQueue retain]; | ||
_name = [name copy]; | ||
_messenger = messenger; | ||
_codec = codec; | ||
_taskQueue = taskQueue; | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_name release]; | ||
[_codec release]; | ||
[_messenger release]; | ||
[_taskQueue release]; | ||
[super dealloc]; | ||
} | ||
|
||
static FlutterBinaryMessengerConnection SetStreamHandlerMessageHandlerOnChannel( | ||
NSObject<FlutterStreamHandler>* handler, | ||
NSString* name, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other deps aren't necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. They were probably initially necessary but was forgotten to be removed at some point when refactoring the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if some of these were copy-pasted from the macOS embedder initially? I can't imagine why we'd depend on flow, for example, given the current code. Either way, nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were added 6 years ago so I guess the code structure was a lot different.