-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate darwin common "framework_shared" target to ARC #37049
Conversation
0848450
to
425aea4
Compare
@@ -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 comment
The 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 comment
The 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 comment
The 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 comment
The 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.
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.
overall LGTM
shell/platform/darwin/BUILD.gn
Outdated
"//flutter/fml", | ||
# "//flutter/runtime", | ||
# "//flutter/shell/common", | ||
# "//third_party/skia", |
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.
delete these?
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.
oops, forgot to push.
@@ -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; | |||
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 comment
The 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 comment
The 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 comment
The 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.
@@ -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 comment
The 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 comment
The 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.
_messenger = [messenger retain]; | ||
_codec = [codec retain]; | ||
_taskQueue = [taskQueue retain]; | ||
_name = 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.
Better to copy mutable objects like NSString
so if they are really NSMutableString
they don't get changed from under you.
_name = name; | |
_name = [name copy]; |
Also all the FlutterBasicMessageChannel
ivars should be properties... but that doesn't need to be done here.
_code = code; | ||
_message = message; | ||
_details = details; |
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.
And these properties are copy
but you only get that on the property setter, not when you set the synthesized ivar.
_code = code; | |
_message = message; | |
_details = details; | |
_code = [code copy]; | |
_message = [message copy]; | |
_details = [details copy]; |
} | ||
|
||
- (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; |
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.
_method = method; | |
_method = [method copy]; |
_messenger = [messenger retain]; | ||
_codec = [codec retain]; | ||
_taskQueue = [taskQueue retain]; | ||
_name = 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.
etc
@@ -182,18 +170,13 @@ - (instancetype)initWithData:(NSData*)data type:(FlutterStandardDataType)type { | |||
NSAssert(data.length % elementSize == 0, @"Data must contain integral number of elements"); | |||
self = [super init]; | |||
NSAssert(self, @"Super init cannot be nil"); | |||
_data = [data retain]; | |||
_data = data; |
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.
Same idea with NSMutableData
_data = data; | |
_data = [data copy]; |
"//third_party/dart/runtime:dart_api", | ||
"//third_party/skia", | ||
] | ||
deps = [ "//flutter/fml" ] |
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.
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
test-exemption: code refactor with no semantic change |
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 see FLUTTER_ASSERT_ARC
in a few places, but not many. Should that be added to the .mm
files so it's not accidentally built in the future with MRC?
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.
LGTM, nit about FLUTTER_ASSERT_ARC
.
@@ -80,7 +80,7 @@ - (void)testRestorationEnabledWaitsForData { | |||
[restorationPlugin setRestorationData:data]; | |||
XCTAssertEqual([capturedResult count], 2u); | |||
XCTAssertEqual([capturedResult objectForKey:@"enabled"], @YES); | |||
XCTAssertEqual([[capturedResult objectForKey:@"data"] data], data); | |||
XCTAssertEqualObjects([[capturedResult objectForKey:@"data"] data], data); |
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.
@goderbauer Could you take a look at the changes I made in this test file to see if they are ok? Did you remember if XCTAssertEqual
was intentionally used to compare the address of the 2 data objects, or we just need the content of the data
objects to be the same.
Original PR: #23495
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.
We just need the content of the data objects to be the same.
flutter#37049)" (flutter#37121)" This reverts commit 774cb34.
@@ -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 comment
The 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.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" This reverts commit cf22fc2.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" This reverts commit cf22fc2. remove copy format
…flutter#37049" (flutter#37219)" (flutter#37320) This reverts commit edb0492.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" This reverts commit cf22fc2.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" This reverts commit cf22fc2.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" This reverts commit cf22fc2.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" (flutter#37883) This reverts commit cf22fc2.
…et to ARC flutter#37049" (flutter#37219)" (flutter#37320)" (flutter#37883) This reverts commit cf22fc2.
The "framework_shared" target was built with arc, there is no blocker to move it to arc besides some standard mrc to arc code changes.
Code changes includes:
This helps the iOS embedder migration work, after this lands, we can now freely move shared code from macOS to "framework_shared"
part of flutter/flutter#112232
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.