-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate darwin common "framework_shared" target to ARC #37049
Changes from 8 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 |
---|---|---|
|
@@ -230,7 +230,7 @@ FLUTTER_DARWIN_EXPORT | |
/** | ||
* The method name. | ||
*/ | ||
@property(readonly, nonatomic) NSString* method; | ||
@property(readonly, nonatomic, copy) NSString* method; | ||
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. Technically it is a breaking change. Though I don't think making it a "copy" is going to change the way the public API is actually used unless it was abused where someone intentionally make it mutable? Thoughts? 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. Since it's readonly, the setter is not synthesized, so it's not a breaking change 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. The breaking part I'm talking about is when someone assigns it to a MutableString, then changes the mutableString and this property will be changed. So it was originally a bug. By "breaking". I meant if someone is abusing this bug to update the value of these properties, their code will stop working. 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. After another look, I realized I was mixing stuff in my head. I think @hellohuanlin was right. And in addition, since the setters are not synthesized, copy doesn't even make sense here. I will revert these changes. |
||
|
||
/** | ||
* The arguments. | ||
|
@@ -257,12 +257,12 @@ FLUTTER_DARWIN_EXPORT | |
/** | ||
The error code. | ||
*/ | ||
@property(readonly, nonatomic) NSString* code; | ||
@property(readonly, nonatomic, copy) NSString* code; | ||
|
||
/** | ||
The error message. | ||
*/ | ||
@property(readonly, nonatomic, nullable) NSString* message; | ||
@property(readonly, nonatomic, nullable, copy) NSString* message; | ||
|
||
/** | ||
The error details. | ||
|
@@ -339,22 +339,22 @@ FLUTTER_DARWIN_EXPORT | |
/** | ||
* The raw underlying data buffer. | ||
*/ | ||
@property(readonly, nonatomic) NSData* data; | ||
@property(readonly, nonatomic, copy) NSData* data; | ||
|
||
/** | ||
* The type of the encoded values. | ||
*/ | ||
@property(readonly, nonatomic) FlutterStandardDataType type; | ||
@property(readonly, nonatomic, assign) FlutterStandardDataType type; | ||
|
||
/** | ||
* The number of value items encoded. | ||
*/ | ||
@property(readonly, nonatomic) UInt32 elementCount; | ||
@property(readonly, nonatomic, assign) UInt32 elementCount; | ||
|
||
/** | ||
* The number of bytes used by the encoding of a single value item. | ||
*/ | ||
@property(readonly, nonatomic) UInt8 elementSize; | ||
@property(readonly, nonatomic, assign) UInt8 elementSize; | ||
@end | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,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 +69,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 +100,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 +120,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 copy]; | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_code release]; | ||
[_message release]; | ||
[_details release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (BOOL)isEqual:(id)object { | ||
if (self == object) { | ||
return YES; | ||
|
@@ -169,24 +154,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 +203,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 +218,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 +255,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 +298,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 +313,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.