fix really stupid bug

This commit is contained in:
husky 2025-07-01 16:50:41 -07:00 committed by Evie Viau
parent 6f6687429e
commit c87a434ce7
Signed by: evie
GPG key ID: 928652CDFCEC8099
2 changed files with 33 additions and 1 deletions

View file

@ -58,7 +58,7 @@ impl<const SLOTS: usize, const FRAME_SIZE: usize> AtomAlloc<SLOTS, FRAME_SIZE> {
} else {
// take and subtract head
self.head = Some(index - 1);
self.atoms[index - 1].take()
self.atoms[index].take()
}
} else {
None

View file

@ -29,4 +29,36 @@ fn noalloc() {
alloc.defragment(); // [(1024, 64)...]
assert_eq!(alloc.atoms[0], Some(Atom { start: 1024, frame_count: 64 }));
assert_eq!(alloc.head, Some(0));
}
#[test]
fn noalloc_irl() {
let mut alloc: AtomAlloc<1024, 4096> = AtomAlloc::default();
alloc.add_memory(0x51000, 2);
alloc.add_memory(0x54000, 72);
alloc.add_memory(0x100000, 259887);
alloc.add_memory(0x3f925000, 1);
alloc.add_memory(0x3fed3000, 15);
let mut first = alloc.allocate(1);
if first.is_none() {
alloc.defragment();
first = alloc.allocate(1);
}
assert!(first.is_some());
let mut second = alloc.allocate(1);
if second.is_none() {
alloc.defragment();
second = alloc.allocate(1);
}
assert!(second.is_some());
let mut third = alloc.allocate(1);
if third.is_none() {
alloc.defragment();
third = alloc.allocate(1);
}
assert!(third.is_some());
}