diff options
| author | gingerBill <bill@gingerbill.org> | 2020-01-03 10:17:30 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-01-03 10:17:30 +0000 |
| commit | b8324b0776d0d8d653e44c9f7876d01509b60e77 (patch) | |
| tree | 113667fc504a5cd532f3e4d776b079558c26b2da | |
| parent | d0ca0455869229b93425396c94be0d685107bded (diff) | |
Fix behaviour for `make` to return `nil` when alloc returns `nil`
| -rw-r--r-- | core/mem/alloc.odin | 2 | ||||
| -rw-r--r-- | core/runtime/core.odin | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index 52ba19738..9feac7958 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -111,6 +111,7 @@ make_slice :: inline proc($T: typeid/[]$E, auto_cast len: int, allocator := cont make_aligned :: proc($T: typeid/[]$E, auto_cast len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> T { runtime.make_slice_error_loc(loc, len); data := alloc(size_of(E)*len, alignment, allocator, loc); + if data == nil do return nil; s := Raw_Slice{data, len}; return transmute(T)s; } @@ -123,6 +124,7 @@ make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, auto_cast len: int, alloc make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, auto_cast len: int, auto_cast cap: int, allocator := context.allocator, loc := #caller_location) -> T { runtime.make_dynamic_array_error_loc(loc, len, cap); data := alloc(size_of(E)*cap, align_of(E), allocator, loc); + if data == nil do return nil; s := Raw_Dynamic_Array{data, len, cap, allocator}; return transmute(T)s; } diff --git a/core/runtime/core.odin b/core/runtime/core.odin index aa2d9affa..067d3d7fb 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -604,6 +604,7 @@ new_clone :: inline proc(data: $T, allocator := context.allocator, loc := #calle make_aligned :: proc($T: typeid/[]$E, auto_cast len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> T { make_slice_error_loc(loc, len); data := mem_alloc(size_of(E)*len, alignment, allocator, loc); + if data == nil do return nil; s := Raw_Slice{data, len}; return transmute(T)s; } @@ -627,6 +628,7 @@ make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, auto_cast len: int, alloc make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, auto_cast len: int, auto_cast cap: int, allocator := context.allocator, loc := #caller_location) -> T { make_dynamic_array_error_loc(loc, len, cap); data := mem_alloc(size_of(E)*cap, align_of(E), allocator, loc); + if data == nil do return nil; s := Raw_Dynamic_Array{data, len, cap, allocator}; return transmute(T)s; } |