-
Notifications
You must be signed in to change notification settings - Fork 6k
[Embedder API] Add 'array of pointers' guidance #39804
[Embedder API] Add 'array of pointers' guidance #39804
Conversation
This looks okay to me.
Agreed with this one, but I also suspect it's not worth fixing this one; it seems really unlikely we'll ever add any additional fields here. It may be worth adding a comment to that effect though.
I could definitely imagine someone wanting to add further fields to this struct, so we definitely want to add a comment at minimum. Something that might be nice to have is a test we can run as part of CI that verifies that certain "locked down" structs are never altered. I don't even think it needs to be particularly complicated - even a tool that greps for certain blocks of code would do it. |
@cbracken Thanks for the feedback! I opened the following issues to fix ABI stability:
These will be addressed in subsequent changes. This pull request is ready for review :) |
@@ -25,6 +25,9 @@ | |||
// - Function signatures (names, argument counts, argument order, and argument | |||
// type) cannot change. | |||
// - The core behavior of existing functions cannot change. | |||
// - Instead of array of structures, prefer array of pointers to structures. | |||
// This ensures that array indexing does not break if members are added | |||
// to the structure. |
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 LGTM.
As you noted separately, we could limit this to embedder-facing arrays of structs passed back in e.g. callbacks since for incoming structs, since for structs going the other way (being passed into the engine) we always use safe dereference macros, but we can't guarantee that third-party embedders do the same.
All that said, I think there's a lot of value in keeping the advice here as succinct as possible and there are no downsides to doing this in both directions aside from making things a very small amount more onerous for embedders. @chinmaygarde probably has thoughts on this.
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; please wait for @chinmaygarde's thoughts on the question of whether we want to have separate advice for outgoing/incoming arrays.
I think both incoming and outgoing structures have to be arrays of pointers. We can't depend on the embedder struct sizes being ones we expect to be consistent. We have the do the same struct size checks on our end so we don't read past the end. |
…gine#39804) (#121652) Roll Flutter Engine from 43f28d2ff87b to 9ffe548bd842 (1 revision)
…lutter/engine#39804) (#121652) Commit: b3f7699def92a569f09a33767a21d9ab1d93f0b6
Update the embedder API's documentation to recommend arrays of pointers to structures instead of arrays to structures.
Violations of this new guidance:
FlutterSemanticsUpdate
- Tracked by [Embedder API] Fix ABI stability of the update semantics API flutter#121176FlutterFrameBufferWithDamageCallback
- Adding members toFlutterRect
will break the ABI, tracked by [Embedder API] Lock theFlutterRect
struct to guarantee ABI stability flutter#121347FlutterEngineNotifyDisplayUpdate
- Adding members toFlutterEngineDisplay
will break the ABI (here), tracked by [Embedder API] FixFlutterEngineNotifyDisplayUpdate
's ABI stability flutter#121352FlutterEngineSendPointerEvent
- ✅ The engine usesstruct_size
correctlyPart of: flutter/flutter#121176
See go/flutter-semantics-abi
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.