mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 01:44:36 +00:00
add other failing test and fix them
This commit is contained in:
@@ -102,14 +102,14 @@ arena_alloc :: proc(arena: ^Arena, size, alignment: uint, loc := #caller_locatio
|
||||
if size == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if arena.curr_block == nil || (safe_add(arena.curr_block.used, size) or_else 0) > arena.curr_block.capacity {
|
||||
size = align_forward_uint(size, alignment)
|
||||
|
||||
needed := 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 {
|
||||
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 {
|
||||
arena.backing_allocator = default_allocator()
|
||||
|
||||
@@ -30,6 +30,7 @@ main :: proc() {
|
||||
|
||||
test_temp_allocator_big_alloc_and_alignment(&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)
|
||||
if TEST_fail > 0 {
|
||||
@@ -56,6 +57,16 @@ test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) {
|
||||
context.allocator = runtime.arena_allocator(&arena)
|
||||
|
||||
mappy: map[[8]int]int
|
||||
err := reserve(&mappy, 50000)
|
||||
err := reserve(&mappy, 50000)
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user