From 8be9b5082cb8270df6af1ef2369c5990a2478f42 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 9 Aug 2018 18:15:49 +0100 Subject: [PATCH] Fix default make parameters for dynamic arrays --- core/mem/alloc.odin | 12 ++++++++---- core/runtime/core.odin | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index 555aa5f51..267d3270e 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -110,10 +110,13 @@ make_slice :: proc(T: type/[]$E, auto_cast len: int, loc := #caller_location) -> s := Raw_Slice{data, len}; return transmute(T)s; } -make_dynamic_array_len :: proc(T: type/[dynamic]$E, auto_cast len: int = 16, loc := #caller_location) -> T { - return make_dynamic_array(T, len, len, loc); +make_dynamic_array :: proc(T: type/[dynamic]$E, loc := #caller_location) -> T { + return make_dynamic_array_len_cap(T, 0, 16, loc); } -make_dynamic_array :: proc(T: type/[dynamic]$E, auto_cast len: int, auto_cast cap: int, loc := #caller_location) -> T { +make_dynamic_array_len :: proc(T: type/[dynamic]$E, auto_cast len: int, loc := #caller_location) -> T { + return make_dynamic_array_len_cap(T, len, len, loc); +} +make_dynamic_array_len_cap :: proc(T: type/[dynamic]$E, auto_cast len: int, auto_cast cap: int, loc := #caller_location) -> T { runtime.make_dynamic_array_error_loc(loc, len, cap); data := alloc(size_of(E)*cap, align_of(E)); s := Raw_Dynamic_Array{data, len, cap, context.allocator}; @@ -128,8 +131,9 @@ make_map :: proc(T: type/map[$K]$E, auto_cast cap: int = 16, loc := #caller_loca make :: proc[ make_slice, - make_dynamic_array_len, make_dynamic_array, + make_dynamic_array_len, + make_dynamic_array_len_cap, make_map, ]; diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 8eb830048..3d19fe0eb 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -328,8 +328,9 @@ delete :: proc[ @(builtin) make :: proc[ mem.make_slice, - mem.make_dynamic_array_len, mem.make_dynamic_array, + mem.make_dynamic_array_len, + mem.make_dynamic_array_len_cap, mem.make_map, ];