add other failing test and fix them

This commit is contained in:
Laytan Laats
2023-12-18 15:17:27 +01:00
parent af962526df
commit 4ae021cd4c
2 changed files with 16 additions and 5 deletions
+3 -3
View File
@@ -103,13 +103,13 @@ arena_alloc :: proc(arena: ^Arena, size, alignment: uint, loc := #caller_locatio
return return
} }
if arena.curr_block == nil || (safe_add(arena.curr_block.used, size) or_else 0) > arena.curr_block.capacity { needed := align_forward_uint(size, alignment)
size = align_forward_uint(size, alignment) if arena.curr_block == nil || (safe_add(arena.curr_block.used, needed) or_else 0) > arena.curr_block.capacity {
if arena.minimum_block_size == 0 { if arena.minimum_block_size == 0 {
arena.minimum_block_size = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE arena.minimum_block_size = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE
} }
block_size := max(size, arena.minimum_block_size) block_size := max(needed, arena.minimum_block_size)
if arena.backing_allocator.procedure == nil { if arena.backing_allocator.procedure == nil {
arena.backing_allocator = default_allocator() arena.backing_allocator = default_allocator()
+11
View File
@@ -30,6 +30,7 @@ main :: proc() {
test_temp_allocator_big_alloc_and_alignment(&t) test_temp_allocator_big_alloc_and_alignment(&t)
test_temp_allocator_alignment_boundary(&t) test_temp_allocator_alignment_boundary(&t)
test_temp_allocator_returns_correct_size(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count) fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 { if TEST_fail > 0 {
@@ -59,3 +60,13 @@ test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) {
err := reserve(&mappy, 50000) err := reserve(&mappy, 50000)
expect_value(t, err, nil) expect_value(t, err, nil)
} }
@(test)
test_temp_allocator_returns_correct_size :: proc(t: ^testing.T) {
arena: runtime.Arena
context.allocator = runtime.arena_allocator(&arena)
bytes, err := mem.alloc_bytes(10, 16)
expect_value(t, err, nil)
expect_value(t, len(bytes), 10)
}