Browse Source

Merge pull request #1178 from Kelimion/new_clone

fix mem.new_clone
Jeroen van Rijn 3 years ago
parent
commit
70dff11b29
2 changed files with 7 additions and 6 deletions
  1. 2 2
      core/c/frontend/tokenizer/token.odin
  2. 5 4
      core/mem/alloc.odin

+ 2 - 2
core/c/frontend/tokenizer/token.odin

@@ -83,13 +83,13 @@ Token :: struct {
 Is_Keyword_Proc :: #type proc(tok: ^Token) -> bool
 Is_Keyword_Proc :: #type proc(tok: ^Token) -> bool
 
 
 copy_token :: proc(tok: ^Token) -> ^Token {
 copy_token :: proc(tok: ^Token) -> ^Token {
-	t := new_clone(tok^)
+	t, _ := new_clone(tok^)
 	t.next = nil
 	t.next = nil
 	return t
 	return t
 }
 }
 
 
 new_eof :: proc(tok: ^Token) -> ^Token {
 new_eof :: proc(tok: ^Token) -> ^Token {
-	t := new_clone(tok^)
+	t, _ := new_clone(tok^)
 	t.kind = .EOF
 	t.kind = .EOF
 	t.lit = ""
 	t.lit = ""
 	return t
 	return t

+ 5 - 4
core/mem/alloc.odin

@@ -215,13 +215,14 @@ new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator,
 	t = (^T)(raw_data(data))
 	t = (^T)(raw_data(data))
 	return
 	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 {
 	if t != nil {
 		t^ = data
 		t^ = data
+		return t, nil
 	}
 	}
-	return
+	return nil, .Out_Of_Memory
 }
 }
 
 
 DEFAULT_RESERVE_CAPACITY :: 16
 DEFAULT_RESERVE_CAPACITY :: 16