Make dependency on file location in Block explicit #3570
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.
A small refactoring to make dependency of the
Block::write_data()
byte offset explicit.The
Block::write_data()
function depended on being called with thedata_stream
being at the locationit should write, which was unlike any of the other
write_*
functions. Thewrite_header()
function wouldguarantee that this was the case. This ment the order of operations in
write
was very much significant althoughit may not look like it.
The
write_*
functions follow a general pattern which is not uncommon. Theyfseek()
in thestream
to where they should write and afterwordsstream
is at the end of where we wrote. Another common pattern is to not enforce the location, and simply write wherever the stream is currently pointing, but the current design makes that infeasible for all of the functions, yetwrite_data()
followed that convention. Instead of having this surprising inconsistency, thewrite_header()
function now supplies the data offset which is passed towrite_data()
, making the dependency explicit.All the
write_*
functions now have the following behaviorPoints 2. and 3. is the same behavior as
fwrite
. Point 1. is a reasonable convention.Pre review checklist
Adding labels helps the maintainers when writing release notes. This is the list of release note labels.