diff options
| author | gingerBill <bill@gingerbill.org> | 2021-04-19 12:31:31 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-04-19 12:31:31 +0100 |
| commit | f98c4d683791e34a077e628bdcac0a0ed32dc065 (patch) | |
| tree | 976ec0dc20463352aafb4833637ce24529cbcd90 /core/runtime/dynamic_array_internal.odin | |
| parent | a4d0092b160cbdd0c5796f1f74e6f1407cb074b6 (diff) | |
Improve the `Allocator` interface to support returning `Allocator_Error` to allow for safer calls
Virtually all code (except for user-written custom allocators) should work as normal. Extra features will need to be added to make the current procedures support the `Allocator_Error` return value (akin to #optional_ok)
Diffstat (limited to 'core/runtime/dynamic_array_internal.odin')
| -rw-r--r-- | core/runtime/dynamic_array_internal.odin | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/core/runtime/dynamic_array_internal.odin b/core/runtime/dynamic_array_internal.odin index 55289bbe4..340f3be5e 100644 --- a/core/runtime/dynamic_array_internal.odin +++ b/core/runtime/dynamic_array_internal.odin @@ -29,10 +29,13 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: new_size := cap * elem_size; allocator := array.allocator; - new_data := allocator.procedure(allocator.data, .Resize, new_size, elem_align, array.data, old_size, 0, loc); + new_data, err := allocator.procedure(allocator.data, .Resize, new_size, elem_align, array.data, old_size, loc); + if err != nil { + return false; + } if new_data != nil || elem_size == 0 { - array.data = new_data; - array.cap = cap; + array.data = raw_data(new_data); + array.cap = min(cap, len(new_data)/elem_size); return true; } return false; |