Repository navigation
Conversation
If the buffer can't grow while the header of a submessage is written (e.g. a full fixed_size_buffer_adaptor), open_submessage() threw after having already written part of the field key and length. The parent then contained a stray partial field. open_submessage() now removes the partially written header before rethrowing, so the parent is unchanged and can still be used. Also document in the tutorial that the destructor of a submessage writer always commits, and how to roll back a submessage when an exception is thrown while writing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If the buffer can't grow while the header of a submessage is written (e.g. a full
fixed_size_buffer_adaptor),open_submessage()threw after having already written part of the field key and length. Since the submessage writer was never constructed, there was nothing to roll back, and the parent was left with a stray partial field.This PR contains the following changes:
open_submessage()now removes the partially written header before rethrowing, so the parent is unchanged and can still be used.rollback()instead. With Support rolling back submessages with known size #169, this also works for submessages opened with a known size.I also looked into rolling back submessages automatically in the destructor if an exception is leaving its scope. However, this requires calling
std::uncaught_exceptions()in every submessage destructor, which made the microbenchmark ~65% slower with GCC 13/libstdc++ on Linux (55 ms → 91 ms, ~12 ns per submessage) and ~17% slower with Apple clang/libc++. Since most users discard the entire buffer when encoding fails anyway, they'd pay this cost without any benefit. Additionally, it can't distinguish an exception leaving the scope of the writer from a writer used in a destructor during stack unwinding. Therefore, I think a documentation "fix" is the better alternative.