Rename free to delete for non pointer types

This commit is contained in:
gingerBill
2018-07-08 11:03:56 +01:00
parent e515220694
commit 0e91298fd1
8 changed files with 130 additions and 102 deletions
+33 -21
View File
@@ -32,7 +32,7 @@ free_ptr_with_allocator :: inline proc(a: Allocator, ptr: rawptr, loc := #caller
a.procedure(a.data, Allocator_Mode.Free, 0, 0, ptr, 0, 0, loc);
}
free_ptr :: inline proc(ptr: rawptr, loc := #caller_location) do free_ptr_with_allocator(context.allocator, ptr);
free :: inline proc(ptr: rawptr, loc := #caller_location) do free_ptr_with_allocator(context.allocator, ptr);
free_all :: inline proc(loc := #caller_location) {
a := context.allocator;
@@ -46,34 +46,46 @@ resize :: inline proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEF
}
free_string :: proc(str: string, loc := #caller_location) {
free_ptr(raw_data(str), loc);
delete_string :: proc(str: string, loc := #caller_location) {
free(raw_data(str), loc);
}
free_cstring :: proc(str: cstring, loc := #caller_location) {
free_ptr((^byte)(str), loc);
delete_cstring :: proc(str: cstring, loc := #caller_location) {
free((^byte)(str), loc);
}
free_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) {
free_ptr(raw_data(array), loc);
delete_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) {
free(raw_data(array), loc);
}
free_slice :: proc(array: $T/[]$E, loc := #caller_location) {
free_ptr(raw_data(array), loc);
delete_slice :: proc(array: $T/[]$E, loc := #caller_location) {
free(raw_data(array), loc);
}
free_map :: proc(m: $T/map[$K]$V, loc := #caller_location) {
delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) {
raw := transmute(Raw_Map)m;
free_dynamic_array(raw.hashes, loc);
free_ptr(raw.entries.data, loc);
delete_dynamic_array(raw.hashes, loc);
free(raw.entries.data, loc);
}
free :: proc[
free_ptr,
free_string,
free_cstring,
free_dynamic_array,
free_slice,
free_map,
delete :: proc[
delete_string,
delete_cstring,
delete_dynamic_array,
delete_slice,
delete_map,
];
new :: inline proc(T: type, loc := #caller_location) -> ^T {
ptr := (^T)(alloc(size_of(T), align_of(T), loc));
ptr^ = T{};
return ptr;
}
new_clone :: inline proc(data: $T, loc := #caller_location) -> ^T {
ptr := (^T)(alloc(size_of(T), align_of(T), loc));
ptr^ = data;
return ptr;
}
default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment: int, loc := #caller_location) -> rawptr {
if old_memory == nil do return alloc(new_size, alignment, loc);
@@ -182,8 +194,8 @@ pool_init :: proc(pool: ^Pool,
pool_destroy :: proc(using pool: ^Pool) {
pool_free_all(pool);
free(unused_blocks);
free(used_blocks);
delete(unused_blocks);
delete(used_blocks);
zero(pool, size_of(pool^));
}
+1 -1
View File
@@ -34,7 +34,7 @@ read_entire_file :: proc(name: string) -> (data: []byte, success: bool) {
bytes_read, read_err := read(fd, data);
if read_err != 0 {
free(data);
delete(data);
return nil, false;
}
return data[0..bytes_read], true;
+18 -25
View File
@@ -254,10 +254,10 @@ foreign {
assume :: proc(cond: bool) ---;
@(link_name="llvm.debugtrap")
__debug_trap :: proc() ---;
debug_trap :: proc() ---;
@(link_name="llvm.trap")
__trap :: proc() ---;
trap :: proc() ---;
@(link_name="llvm.readcyclecounter")
read_cycle_counter :: proc() -> u64 ---;
@@ -309,32 +309,25 @@ reserve :: proc[reserve_dynamic_array, reserve_map];
@(builtin)
new :: inline proc(T: type, loc := #caller_location) -> ^T {
ptr := (^T)(mem.alloc(size_of(T), align_of(T), loc));
ptr^ = T{};
return ptr;
}
new :: proc[mem.new];
@(builtin)
new_clone :: inline proc(data: $T, loc := #caller_location) -> ^T {
ptr := (^T)(mem.alloc(size_of(T), align_of(T), loc));
ptr^ = data;
return ptr;
}
new_clone :: proc[mem.new_clone];
@(builtin)
free :: proc[
mem.free_ptr,
mem.free_string,
mem.free_cstring,
mem.free_dynamic_array,
mem.free_slice,
mem.free_map,
free :: proc[mem.free];
@(builtin)
delete :: proc[
mem.delete_string,
mem.delete_cstring,
mem.delete_dynamic_array,
mem.delete_slice,
mem.delete_map,
];
@(builtin)
clear_map :: inline proc "contextless" (m: ^$T/map[$K]$V) {
if m == nil do return;
@@ -351,8 +344,8 @@ reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int) {
}
@(builtin)
delete :: proc(m: ^$T/map[$K]$V, key: K) {
if m != nil do __dynamic_map_delete(__get_map_header(m), __get_map_key(key));
delete_key :: proc(m: ^$T/map[$K]$V, key: K) {
if m != nil do __dynamic_map_delete_key(__get_map_header(m), __get_map_key(key));
}
@@ -436,7 +429,7 @@ assert :: proc "contextless" (condition: bool, message := "", using loc := #call
os.write_string(fd, message);
}
os.write_byte(fd, '\n');
__debug_trap();
debug_trap();
}
return condition;
}
@@ -451,7 +444,7 @@ panic :: proc "contextless" (message := "", using loc := #caller_location) {
os.write_string(fd, message);
}
os.write_byte(fd, '\n');
__debug_trap();
debug_trap();
}
@@ -742,7 +735,7 @@ __dynamic_map_add_entry :: proc(using h: Map_Header, key: Map_Key, loc := #calle
return prev;
}
__dynamic_map_delete :: proc(using h: Map_Header, key: Map_Key) {
__dynamic_map_delete_key :: proc(using h: Map_Header, key: Map_Key) {
fr := __dynamic_map_find(h, key);
if fr.entry_index >= 0 {
__dynamic_map_erase(h, fr);
+4 -4
View File
@@ -259,7 +259,7 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
os.write_string(fd, " is out of bounds range 0..");
__print_i64(fd, i64(count));
os.write_byte(fd, '\n');
__debug_trap();
debug_trap();
}
slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
@@ -275,7 +275,7 @@ slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi:
os.write_string(fd, "..");
__print_i64(fd, i64(len));
os.write_byte(fd, '\n');
__debug_trap();
debug_trap();
}
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
@@ -290,7 +290,7 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int,
os.write_string(fd, "..");
__print_i64(fd, i64(max));
os.write_byte(fd, '\n');
__debug_trap();
debug_trap();
}
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
@@ -303,7 +303,7 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column
os.write_string(fd, " to ");
__print_typeid(fd, to);
os.write_byte(fd, '\n');
__debug_trap();
debug_trap();
}
__string_decode_rune :: inline proc "contextless" (s: string) -> (rune, int) {