-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Pad BlobVec
item size to multiple of alignment
#10127
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
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
@@ -440,6 +442,21 @@ fn repeat_layout(layout: &Layout, n: usize) -> Option<(Layout, usize)> { | |||
} | |||
} | |||
|
|||
// TODO: replace with `Layout::pad_to_align` if/when it stabilizes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a tracking issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The utility methods for Layout
are part of alloc_layout_extra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: replace with `Layout::pad_to_align` if/when it stabilizes | |
// TODO: replace with `Layout::pad_to_align` if/when it stabilizes (https://github.com/rust-lang/rust/issues/55724) |
Ok so simply changing the size of |
It would make more sense to me to store The common operations are going to be "Offset a pointer to find a cell in the array" and "Copy item_size bytes in/out of a cell". So it feels like less mental overhead to store those values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does repeat_layout()
need to recompute the padding anymore if self.item_layout
is being modified in the constructor to be "Item Size + Padding" anyway?
Objective
Some of the
BlobVec
code assumes the size of the contained item is a multiple of its alignment. However,std::alloc::Layout
by itself does not enforce this, and there are no checks inBlobVec::new
. (There is a debug assertion elsewhere, but it can be bypassed in release mode). Functions likeBlobVec::get_unchecked
will produce pointers that are not properly aligned.This problem is potentially observable with
World::init_component_with_descriptor
.Solution
BlobVec::new
.