mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-27 04:20:24 +00:00
CAS Pool: make dangling Ptr well aligned
the old logic didn't consider the pointee's alignment when creating a dangling pointer dangling pointers are used in pools of ZST (Zero Sized Types). the old logic resulted in these Boxed ZST not being well aligned. the test added in this PR was failing
This commit is contained in:
parent
9563b3546c
commit
959fc9b683
@ -177,7 +177,7 @@ impl<T> Ptr<T> {
|
||||
}
|
||||
|
||||
pub fn dangling() -> Self {
|
||||
unsafe { Self::from_parts(initial_tag_value(), 1) }
|
||||
unsafe { Self::from_parts(initial_tag_value(), core::mem::align_of::<T>() as i32) }
|
||||
}
|
||||
|
||||
pub unsafe fn as_ref(&self) -> &T {
|
||||
|
@ -354,6 +354,17 @@ mod tests {
|
||||
assert_eq!(*A::alloc().unwrap().init(1), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boxed_zst_is_well_aligned() {
|
||||
#[repr(align(2))]
|
||||
pub struct Zst2;
|
||||
|
||||
pool!(A: Zst2);
|
||||
|
||||
let x = A::alloc().unwrap().init(Zst2);
|
||||
assert_eq!(0, &*x as *const Zst2 as usize % 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destructors() {
|
||||
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user