[pigeon] Fix async handling in C++ generator #3040
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reworks the structure of success and return value handling in the C++ generator in order to simplify the flows and eliminate undefined behavior due to references to stack-based objects in a long-lived lamba capture.
Core changes:
wrapped
is no longer created at the beginning of the method, populated, and then returned at the end, since that made async hard to do correctly. Instead, each distinct case that would return has its own call toreply
.reply
, which can be a source of multi-reply
errors (e.g., if areturn
afterward is forgotten), in practice those cases would have been errors anyway becausewrapped
would have had the wrong number of elements.&wrapped
, which had undefined behavior for any plugin code that actually calledreply
asynchronously.reply
is now passed as a copy, rather than a reference, again to avoid undefined behavior for actually async methods.Because this if fixing undefined behavior, this is tested with generator unit tests, as integration tests may or may not pass. In fact we have one test running right now, and it's luck that it's been passing. In practice most of the real testing will come from adding more async tests, which will happen in another PR that I have in progress (which I had to pause because the new integration tests crashed, which is how I ended up in this PR).
Minor change:
wrapped
's type,WrapError
returns anEncodableValue
to simplify its usage.Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).