From eb9665f83661158ac06f0fdf0c28935b9e62aa62 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sun, 19 Sep 2021 22:19:06 +0200 Subject: [PATCH] fix mem.new_clone --- core/c/frontend/tokenizer/token.odin | 4 ++-- core/mem/alloc.odin | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/c/frontend/tokenizer/token.odin b/core/c/frontend/tokenizer/token.odin index c4760ea42..1376a651f 100644 --- a/core/c/frontend/tokenizer/token.odin +++ b/core/c/frontend/tokenizer/token.odin @@ -83,13 +83,13 @@ Token :: struct { Is_Keyword_Proc :: #type proc(tok: ^Token) -> bool copy_token :: proc(tok: ^Token) -> ^Token { - t := new_clone(tok^) + t, _ := new_clone(tok^) t.next = nil return t } new_eof :: proc(tok: ^Token) -> ^Token { - t := new_clone(tok^) + t, _ := new_clone(tok^) t.kind = .EOF t.lit = "" return t diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index 796d5c20a..bdd2899a9 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -215,13 +215,14 @@ new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator, t = (^T)(raw_data(data)) return } -new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> ^T { - data := alloc_bytes(size_of(T), alignment, allocator, loc) or_return - t = (^T)(raw_data(data)) +new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) { + backing := alloc_bytes(size_of(T), align_of(T), allocator, loc) or_return + t = (^T)(raw_data(backing)) if t != nil { t^ = data + return t, nil } - return + return nil, .Out_Of_Memory } DEFAULT_RESERVE_CAPACITY :: 16