diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-07-22 17:01:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 17:01:13 +0200 |
| commit | 315cd51f7652baa324086f82fef71eb6afd47e57 (patch) | |
| tree | 9c163e7ce2fd520926441959502f66826a2c0f73 | |
| parent | 19a075211f4b14c5e2bb999b987ff4ed099f2af1 (diff) | |
| parent | a0efdf26a6fef9d2db8d7659708b8b9fb142af32 (diff) | |
Merge pull request #5491 from Feoramund/buddy-2
Fix Linux-specific optimized test failure
| -rw-r--r-- | core/mem/allocators.odin | 5 | ||||
| -rw-r--r-- | tests/core/mem/test_core_mem.odin | 13 |
2 files changed, 13 insertions, 5 deletions
diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index 0eacb1b65..cb9301f60 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -2223,6 +2223,9 @@ Initialize a buddy allocator. This procedure initializes the buddy allocator `b` with a backing buffer `data` and block alignment specified by `alignment`. + +`alignment` may be any power of two, but the backing buffer must be aligned to +at least `size_of(Buddy_Block)`. */ buddy_allocator_init :: proc(b: ^Buddy_Allocator, data: []byte, alignment: uint, loc := #caller_location) { assert(data != nil) @@ -2233,7 +2236,7 @@ buddy_allocator_init :: proc(b: ^Buddy_Allocator, data: []byte, alignment: uint, alignment = size_of(Buddy_Block) } ptr := raw_data(data) - assert(uintptr(ptr) % uintptr(alignment) == 0, "data is not aligned to minimum alignment", loc) + assert(uintptr(ptr) % uintptr(alignment) == 0, "The data is not aligned to the minimum alignment, which must be at least `size_of(Buddy_Block)`.", loc) b.head = (^Buddy_Block)(ptr) b.head.size = len(data) b.head.is_free = true diff --git a/tests/core/mem/test_core_mem.odin b/tests/core/mem/test_core_mem.odin index c1cb59c68..9d64e50a3 100644 --- a/tests/core/mem/test_core_mem.odin +++ b/tests/core/mem/test_core_mem.odin @@ -282,13 +282,18 @@ test_dynamic_arena :: proc(t: ^testing.T) { @test test_buddy :: proc(t: ^testing.T) { - N :: 4096 + N :: 8192 buf: [N]u8 + base := &buf[0] + address := mem.align_forward(base, size_of(mem.Buddy_Block)) + delta := uintptr(address) - uintptr(base) + ba: mem.Buddy_Allocator - mem.buddy_allocator_init(&ba, buf[:], align_of(u8)) - basic_sanity_test(t, mem.buddy_allocator(&ba), N / 8) - basic_sanity_test(t, mem.buddy_allocator(&ba), N / 8) + + mem.buddy_allocator_init(&ba, buf[delta:delta+N/2], size_of(mem.Buddy_Block)) + basic_sanity_test(t, mem.buddy_allocator(&ba), N / 16) + basic_sanity_test(t, mem.buddy_allocator(&ba), N / 16) } @test |