mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-27 04:20:24 +00:00
Merge pull request #235 from japaric/well-aligned-dangling-pointer
CAS Pool: make dangling Ptr well aligned
This commit is contained in:
commit
d5e092575b
@ -177,7 +177,8 @@ impl<T> Ptr<T> {
|
||||
}
|
||||
|
||||
pub fn dangling() -> Self {
|
||||
unsafe { Self::from_parts(initial_tag_value(), 1) }
|
||||
// `anchor()` returns a well-aligned pointer so an offset of 0 will also produce a well-aligned pointer
|
||||
unsafe { Self::from_parts(initial_tag_value(), 0) }
|
||||
}
|
||||
|
||||
pub unsafe fn as_ref(&self) -> &T {
|
||||
|
@ -354,6 +354,25 @@ 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);
|
||||
|
||||
#[repr(align(4096))]
|
||||
pub struct Zst4096;
|
||||
|
||||
pool!(B: Zst4096);
|
||||
|
||||
let x = B::alloc().unwrap().init(Zst4096);
|
||||
assert_eq!(0, &*x as *const Zst4096 as usize % 4096);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destructors() {
|
||||
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user