diff options
| author | gingerBill <bill@gingerbill.org> | 2017-11-26 15:25:45 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2017-11-26 15:25:45 +0000 |
| commit | 5a9223afdac7b97355be6c0441978f12175ede77 (patch) | |
| tree | 77147589e6a93387c9cdfb0576b35838a959ce6c /core/_preload.odin | |
| parent | febcd7332399233f7e3452b66b5cb4ef9f6a574b (diff) | |
`nil_allocator`; Fix IR type checking assert; `append_string`
Diffstat (limited to 'core/_preload.odin')
| -rw-r--r-- | core/_preload.odin | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/core/_preload.odin b/core/_preload.odin index 4fc0440be..9f790ca51 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -351,13 +351,12 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i if arg_len <= 0 do return len(array); - ok := true; if cap(array) <= len(array)+arg_len { cap := 2 * cap(array) + max(8, arg_len); - ok = reserve(array, cap, loc); + _ = reserve(array, cap, loc); } - // TODO(bill): Better error handling for failed reservation - if ok { + arg_len = min(cap(array)-len(array), arg_len); + if arg_len > 0 { a := cast(^raw.Dynamic_Array)array; data := cast(^E)a.data; assert(data != nil); @@ -367,13 +366,13 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i return len(array); } -append :: proc(array: ^$T/[]u8, args: ...string) -> int { +append_string :: proc(array: ^$T/[]u8, args: ...string) -> int { for arg in args { append(array, ...cast(T)arg); } return len(array); } -append :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller_location) -> int { +append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller_location) -> int { for arg in args { append(array = array, args = cast([]E)arg, loc = loc); } @@ -594,7 +593,7 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment: default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, size, alignment: int, - old_memory: rawptr, old_size: int, flags: u64, loc := #caller_location) -> rawptr { + old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr { using Allocator_Mode; switch mode { @@ -624,6 +623,19 @@ default_allocator :: proc() -> Allocator { }; } +nil_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, + size, alignment: int, + old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr { + return nil; +} + +nil_allocator :: proc() -> Allocator { + return Allocator{ + procedure = nil_allocator_proc, + data = nil, + }; +} + assert :: proc "contextless" (condition: bool, message := "", args: ...any, using loc := #caller_location) -> bool { if !condition { |