-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Based on #28] Getting alignment right #33
base: master
Are you sure you want to change the base?
Conversation
By its very nature, Abomonation does very unsafe (and UB-ish) things. But we should strive to explain these as well as we can in the current state of the unsafe Rust formalization effort in order to reduce the potential for known misuse.
@frankmcsherry So, this PR is getting into a pretty nice shape now. It would be useful if you could have a look at it and comment on the general design direction at some point. In the end, I gave up on the idea of automatically reallocating
|
One safer alternative to the current design where passing unaligned bytes to decode is UB (and is checked only in debug build) would be to have EDIT: ...especially as it would interfere somewhat badly with |
Alright, I squashed my commit mess a bit to make it easier for you to review. Also, I think I've found a way to make EDIT: Nope, I don't think I can make it work without an unacceptable degree of type-level complexity. |
This allows Abomonation to correctly align serialized data by providing...
encode()
implementation that inserts padding so that all output data can be well-aligned if the bytes are aligned on a sufficiently strong boundary (specified byAbomonation::alignment()
).decode()
implementation that handles said padding correctly if the input data is suitably aligned (otherwise UB may occur).Other noteworthy changes include
extent()
going away (because alignment-related padding makes a type's extent dependent on the context in which it is entombed) andunsafe_abomonate
becoming even more messy, raising the question of when it should go away for good.At the documentation level, padding bytes related UB was significantly clarified.
For convenience reasons, this PR is based on #22, #24, #25, #26 and #28. Reviewing these PRs first is recommended, but if you want to review this one in isolation, please consider doing so commit-by-commit in order to get a clean diff.
Fixes #23.