From b34903977707ad344c53f3e1367063b0bb944176 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 20 Aug 2022 22:45:29 -0700 Subject: Fix index offset --- src/mem/alloc.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs index f4ba935..1a4ad77 100644 --- a/src/mem/alloc.rs +++ b/src/mem/alloc.rs @@ -60,7 +60,7 @@ impl Debug for QueueItem<'_,T> { /// /// Output the encapsulated data fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.data) + write!(f, "{:?} {:x} {:?}", self.data, self as *const QueueItem<'_,T> as usize, self.next) } } @@ -85,15 +85,15 @@ impl<'a, T: Sized,const COUNT: usize> QueueAllocator<'a, T, COUNT> { /// one and the final element points to `None` pub fn init(&self) { self.inner.lock(|queue| { - for idx in 2..queue.len() { - if idx != queue.len()-1 { - queue[idx].next = Some(&mut queue[idx+1] as *mut QueueItem<'_, T>); + for idx in 2..COUNT { + if idx != COUNT-1 { + queue[idx].next = Some(&mut queue[idx+1] as *mut QueueItem<'a, T>); } else { queue[idx].next = None; } } - queue[0].next = Some(&mut queue[2] as *mut QueueItem<'_, T>); - queue[1].next = Some(&mut queue[queue.len()-1] as *mut QueueItem<'_, T>); + queue[0].next = Some(&mut queue[2] as *mut QueueItem<'a, T>); + queue[1].next = Some(&mut queue[COUNT-1] as *mut QueueItem<'a, T>); }); } @@ -375,7 +375,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U8_GRAND_ALLOC.free(&mut pool[index]); + U8_GRAND_ALLOC.free(&mut pool[index+2]); }); } 2 => { @@ -385,7 +385,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U16_GRAND_ALLOC.free(&mut pool[index]); + U16_GRAND_ALLOC.free(&mut pool[index+2]); }); } 3..=4 => { @@ -395,7 +395,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U32_GRAND_ALLOC.free(&mut pool[index]); + U32_GRAND_ALLOC.free(&mut pool[index+2]); }); } 5..=8 => { @@ -405,7 +405,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U64_GRAND_ALLOC.free(&mut pool[index]); + U64_GRAND_ALLOC.free(&mut pool[index+2]); }); } 9..=16 => { @@ -415,7 +415,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U128_GRAND_ALLOC.free(&mut pool[index]); + U128_GRAND_ALLOC.free(&mut pool[index+2]); }); } 17..=32 => { @@ -425,7 +425,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U256_GRAND_ALLOC.free(&mut pool[index]); + U256_GRAND_ALLOC.free(&mut pool[index+2]); }); } 33..=64 => { @@ -435,7 +435,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U512_GRAND_ALLOC.free(&mut pool[index]); + U512_GRAND_ALLOC.free(&mut pool[index+2]); }); } 65..=128 => { @@ -445,7 +445,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U1024_GRAND_ALLOC.free(&mut pool[index]); + U1024_GRAND_ALLOC.free(&mut pool[index+2]); }); } 129..=256 => { @@ -455,7 +455,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U2048_GRAND_ALLOC.free(&mut pool[index]); + U2048_GRAND_ALLOC.free(&mut pool[index+2]); }); } 257..=512 => { @@ -465,7 +465,7 @@ unsafe impl GlobalAlloc for GrandAllocator { let index: usize = diff/spacing; assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); - U4096_GRAND_ALLOC.free(&mut pool[index]); + U4096_GRAND_ALLOC.free(&mut pool[index+2]); }); } _ => { -- cgit v1.2.1