diff options
author | Christian Cunningham <cc@localhost> | 2022-08-20 13:49:11 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-08-20 13:49:11 -0700 |
commit | 65ddc0fbec22542f0c64baedc988af163a34d186 (patch) | |
tree | 50994f05b6e3ac29566adf564b60c03c6c1af844 /src/mem/alloc.rs | |
parent | 63f8487283f8b167846eb2562cca5b8fb504cc37 (diff) |
Custom assertion messages
Diffstat (limited to 'src/mem/alloc.rs')
-rw-r--r-- | src/mem/alloc.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs index e06230d..66a8778 100644 --- a/src/mem/alloc.rs +++ b/src/mem/alloc.rs @@ -274,8 +274,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + 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]); }); } @@ -284,8 +284,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + 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]); }); } @@ -294,8 +294,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + 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]); }); } @@ -304,8 +304,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + 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]); }); } @@ -314,8 +314,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + 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]); }); } @@ -324,8 +324,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + 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]); }); } |