mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Add runtime messages for make for the len/cap parameters
This commit is contained in:
+10
-5
@@ -1,5 +1,7 @@
|
|||||||
package mem
|
package mem
|
||||||
|
|
||||||
|
import "core:runtime"
|
||||||
|
|
||||||
DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
|
DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
|
||||||
|
|
||||||
Allocator_Mode :: enum byte {
|
Allocator_Mode :: enum byte {
|
||||||
@@ -102,20 +104,23 @@ new_clone_with_allocator :: inline proc(a: Allocator, data: $T, loc := #caller_l
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
make_slice :: proc(T: type/[]$E, len: int) -> T {
|
make_slice :: proc(T: type/[]$E, len: int, loc := #caller_location) -> T {
|
||||||
|
runtime.make_slice_error_loc(loc, len);
|
||||||
data := alloc(size_of(E)*len, align_of(E));
|
data := alloc(size_of(E)*len, align_of(E));
|
||||||
s := Raw_Slice{data, len};
|
s := Raw_Slice{data, len};
|
||||||
return transmute(T)s;
|
return transmute(T)s;
|
||||||
}
|
}
|
||||||
make_dynamic_array_len :: proc(T: type/[dynamic]$E, len: int = 16) -> T {
|
make_dynamic_array_len :: proc(T: type/[dynamic]$E, len: int = 16, loc := #caller_location) -> T {
|
||||||
return make_dynamic_array(T, len, len);
|
return make_dynamic_array(T, len, len, loc);
|
||||||
}
|
}
|
||||||
make_dynamic_array :: proc(T: type/[dynamic]$E, len, cap: int) -> T {
|
make_dynamic_array :: proc(T: type/[dynamic]$E, len, cap: int, loc := #caller_location) -> T {
|
||||||
|
runtime.make_dynamic_array_error_loc(loc, len, cap);
|
||||||
data := alloc(size_of(E)*cap, align_of(E));
|
data := alloc(size_of(E)*cap, align_of(E));
|
||||||
s := Raw_Dynamic_Array{data, len, cap, context.allocator};
|
s := Raw_Dynamic_Array{data, len, cap, context.allocator};
|
||||||
return transmute(T)s;
|
return transmute(T)s;
|
||||||
}
|
}
|
||||||
make_map :: proc(T: type/map[$K]$E, cap: int = 16) -> T {
|
make_map :: proc(T: type/map[$K]$E, cap: int = 16, loc := #caller_location) -> T {
|
||||||
|
runtime.make_map_array_error_loc(loc, cap);
|
||||||
m: T;
|
m: T;
|
||||||
reserve_map(&m, cap);
|
reserve_map(&m, cap);
|
||||||
return m;
|
return m;
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int,
|
|||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
|
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
|
||||||
if ok do return;
|
if ok do return;
|
||||||
|
|
||||||
@@ -318,6 +319,47 @@ slice_expr_error_loc :: inline proc "contextless" (using loc := #caller_location
|
|||||||
slice_expr_error(file_path, int(line), int(column), lo, hi, len);
|
slice_expr_error(file_path, int(line), int(column), lo, hi, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dynamic_array_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, low, high, max: int) {
|
||||||
|
dynamic_array_expr_error(file_path, int(line), int(column), low, high, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
make_slice_error_loc :: inline proc "contextless" (using loc := #caller_location, len: int) {
|
||||||
|
if 0 < len do return;
|
||||||
|
|
||||||
|
fd := os.stderr;
|
||||||
|
__print_caller_location(fd, loc);
|
||||||
|
os.write_string(fd, " Invalid slice length for make: ");
|
||||||
|
__print_i64(fd, i64(len));
|
||||||
|
os.write_byte(fd, '\n');
|
||||||
|
debug_trap();
|
||||||
|
}
|
||||||
|
|
||||||
|
make_dynamic_array_error_loc :: inline proc "contextless" (using loc := #caller_location, len, cap: int) {
|
||||||
|
if 0 < len && len < cap do return;
|
||||||
|
|
||||||
|
fd := os.stderr;
|
||||||
|
__print_caller_location(fd, loc);
|
||||||
|
os.write_string(fd, " Invalid dynamic array parameters for make: ");
|
||||||
|
__print_i64(fd, i64(len));
|
||||||
|
os.write_byte(fd, ':');
|
||||||
|
__print_i64(fd, i64(cap));
|
||||||
|
os.write_byte(fd, '\n');
|
||||||
|
debug_trap();
|
||||||
|
}
|
||||||
|
|
||||||
|
map_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, cap: int) {
|
||||||
|
if 0 < cap do return;
|
||||||
|
|
||||||
|
fd := os.stderr;
|
||||||
|
__print_caller_location(fd, loc);
|
||||||
|
os.write_string(fd, " Invalid map capacity for make: ");
|
||||||
|
__print_i64(fd, i64(cap));
|
||||||
|
os.write_byte(fd, '\n');
|
||||||
|
debug_trap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@(default_calling_convention = "c")
|
@(default_calling_convention = "c")
|
||||||
|
|||||||
Reference in New Issue
Block a user