Browse Source

Correct `mem.clone_slice`

gingerBill 4 years ago
parent
commit
81623861c0
2 changed files with 4 additions and 4 deletions
  1. 2 2
      core/mem/mem.odin
  2. 2 2
      core/runtime/core_builtin.odin

+ 2 - 2
core/mem/mem.odin

@@ -289,8 +289,8 @@ calc_padding_with_header :: proc(ptr: uintptr, align: uintptr, header_size: int)
 
 
 
 
 
 
-clone_slice :: proc(slice: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> T {
-	new_slice := make(T, len(slice), allocator, loc);
+clone_slice :: proc(slice: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> (new_slice: T) {
+	new_slice, _ = make(T, len(slice), allocator, loc);
 	runtime.copy(new_slice, slice);
 	runtime.copy(new_slice, slice);
 	return new_slice;
 	return new_slice;
 }
 }

+ 2 - 2
core/runtime/core_builtin.odin

@@ -180,8 +180,8 @@ new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator,
 
 
 @builtin
 @builtin
 new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) #optional_second {
 new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) #optional_second {
-	data := alloc_bytes(size_of(T), alignment, allocator, loc) or_return;
-	t = (^T)(raw_data(data));
+	t_data := mem_alloc_bytes(size_of(T), align_of(T), allocator, loc) or_return;
+	t = (^T)(raw_data(t_data));
 	if t != nil {
 	if t != nil {
 		t^ = data;
 		t^ = data;
 	}
 	}