Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Embedder API] Add 'array of pointers' guidance #39804

Merged
merged 4 commits into from
Feb 28, 2023

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Feb 22, 2023

Update the embedder API's documentation to recommend arrays of pointers to structures instead of arrays to structures.

Violations of this new guidance:

  1. FlutterSemanticsUpdate - Tracked by [Embedder API] Fix ABI stability of the update semantics API flutter#121176
  2. FlutterFrameBufferWithDamageCallback - Adding members to FlutterRect will break the ABI, tracked by [Embedder API] Lock the FlutterRect struct to guarantee ABI stability  flutter#121347
  3. FlutterEngineNotifyDisplayUpdate - Adding members to FlutterEngineDisplay will break the ABI (here), tracked by [Embedder API] Fix FlutterEngineNotifyDisplayUpdate's ABI stability  flutter#121352
  4. FlutterEngineSendPointerEvent - ✅ The engine uses struct_size correctly

Part of: flutter/flutter#121176
See go/flutter-semantics-abi

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the embedder Related to the embedder API label Feb 22, 2023
@cbracken
Copy link
Member

FlutterMetalTextureFrameCallback - ⚠️ Adding members to FlutterMetalTextureHandle will break the ABI

This looks okay to me. FlutterMetalTextureHandle is just a typedef of void* so it'll always be sized to the size of a pointer.

FlutterFrameBufferWithDamageCallback - ⚠️ Adding members to FlutterRect will break the ABI

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.

FlutterEngineNotifyDisplayUpdate - ⚠️ Adding members to FlutterEngineDisplay will break the ABI (here)

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.

@loic-sharma
Copy link
Member Author

@cbracken Thanks for the feedback! I opened the following issues to fix ABI stability:

  1. [Embedder API] Lock the FlutterRect struct to guarantee ABI stability  flutter#121347
  2. [Embedder API] Fix FlutterEngineNotifyDisplayUpdate's ABI stability  flutter#121352

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.
Copy link
Member

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.

Copy link
Member

@cbracken cbracken left a 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.

@chinmaygarde
Copy link
Member

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.

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 28, 2023
@auto-submit auto-submit bot merged commit 9ffe548 into flutter:main Feb 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 1, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 1, 2023
…gine#39804) (#121652)

Roll Flutter Engine from 43f28d2ff87b to 9ffe548bd842 (1 revision)
sourcegraph-bot pushed a commit to sgtest/megarepo that referenced this pull request Mar 1, 2023
…lutter/engine#39804) (#121652)

Commit: b3f7699def92a569f09a33767a21d9ab1d93f0b6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App embedder Related to the embedder API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants