mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Add -disallow-rtti
This commit is contained in:
@@ -508,16 +508,18 @@ __type_info_of :: proc "contextless" (id: typeid) -> ^Type_Info #no_bounds_check
|
|||||||
return &type_table[n]
|
return &type_table[n]
|
||||||
}
|
}
|
||||||
|
|
||||||
typeid_base :: proc "contextless" (id: typeid) -> typeid {
|
when !ODIN_DISALLOW_RTTI {
|
||||||
|
typeid_base :: proc "contextless" (id: typeid) -> typeid {
|
||||||
ti := type_info_of(id)
|
ti := type_info_of(id)
|
||||||
ti = type_info_base(ti)
|
ti = type_info_base(ti)
|
||||||
return ti.id
|
return ti.id
|
||||||
}
|
}
|
||||||
typeid_core :: proc "contextless" (id: typeid) -> typeid {
|
typeid_core :: proc "contextless" (id: typeid) -> typeid {
|
||||||
ti := type_info_core(type_info_of(id))
|
ti := type_info_core(type_info_of(id))
|
||||||
return ti.id
|
return ti.id
|
||||||
|
}
|
||||||
|
typeid_base_without_enum :: typeid_core
|
||||||
}
|
}
|
||||||
typeid_base_without_enum :: typeid_core
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,41 +17,11 @@ type_assertion_trap :: proc "contextless" () -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bounds_check_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, index, count: int) {
|
bounds_check_error :: proc "contextless" (file: string, line, column: i32, index, count: int) {
|
||||||
bounds_check_error(file_path, line, column, index, count)
|
|
||||||
}
|
|
||||||
|
|
||||||
slice_expr_error_hi_loc :: #force_inline proc "contextless" (using loc := #caller_location, hi: int, len: int) {
|
|
||||||
slice_expr_error_hi(file_path, line, column, hi, len)
|
|
||||||
}
|
|
||||||
|
|
||||||
slice_expr_error_lo_hi_loc :: #force_inline proc "contextless" (using loc := #caller_location, lo, hi: int, len: int) {
|
|
||||||
slice_expr_error_lo_hi(file_path, line, column, lo, hi, len)
|
|
||||||
}
|
|
||||||
|
|
||||||
dynamic_array_expr_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, low, high, max: int) {
|
|
||||||
dynamic_array_expr_error(file_path, line, column, low, high, max)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|
||||||
foreign {
|
|
||||||
bounds_check_error :: proc "contextless" (file: string, line, column: i32, index, count: int) ---
|
|
||||||
slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) -> ! ---
|
|
||||||
multi_pointer_slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int) -> ! ---
|
|
||||||
multi_pointer_slice_expr_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int) ---
|
|
||||||
slice_expr_error_hi :: proc "contextless" (file: string, line, column: i32, hi: int, len: int) ---
|
|
||||||
slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) ---
|
|
||||||
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) ---
|
|
||||||
matrix_bounds_check_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) ---
|
|
||||||
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid) ---
|
|
||||||
type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid, from_data: rawptr) ---
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bounds_check_error :: proc "contextless" (file: string, line, column: i32, index, count: int) {
|
|
||||||
if 0 <= index && index < count {
|
if 0 <= index && index < count {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (file: string, line, column: i32, index, count: int) {
|
handle_error :: proc "contextless" (file: string, line, column: i32, index, count: int) {
|
||||||
print_caller_location(Source_Code_Location{file, line, column, ""})
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
print_string(" Index ")
|
print_string(" Index ")
|
||||||
@@ -62,9 +32,9 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
bounds_trap()
|
bounds_trap()
|
||||||
}
|
}
|
||||||
handle_error(file, line, column, index, count)
|
handle_error(file, line, column, index, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) -> ! {
|
slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) -> ! {
|
||||||
print_caller_location(Source_Code_Location{file, line, column, ""})
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
print_string(" Invalid slice indices ")
|
print_string(" Invalid slice indices ")
|
||||||
print_i64(i64(lo))
|
print_i64(i64(lo))
|
||||||
@@ -74,9 +44,9 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
print_i64(i64(len))
|
print_i64(i64(len))
|
||||||
print_byte('\n')
|
print_byte('\n')
|
||||||
bounds_trap()
|
bounds_trap()
|
||||||
}
|
}
|
||||||
|
|
||||||
multi_pointer_slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int) -> ! {
|
multi_pointer_slice_handle_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int) -> ! {
|
||||||
print_caller_location(Source_Code_Location{file, line, column, ""})
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
print_string(" Invalid slice indices ")
|
print_string(" Invalid slice indices ")
|
||||||
print_i64(i64(lo))
|
print_i64(i64(lo))
|
||||||
@@ -84,34 +54,35 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
print_i64(i64(hi))
|
print_i64(i64(hi))
|
||||||
print_byte('\n')
|
print_byte('\n')
|
||||||
bounds_trap()
|
bounds_trap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
multi_pointer_slice_expr_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int) {
|
multi_pointer_slice_expr_error :: proc "contextless" (file: string, line, column: i32, lo, hi: int) {
|
||||||
if lo <= hi {
|
if lo <= hi {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
multi_pointer_slice_handle_error(file, line, column, lo, hi)
|
multi_pointer_slice_handle_error(file, line, column, lo, hi)
|
||||||
}
|
}
|
||||||
|
|
||||||
slice_expr_error_hi :: proc "contextless" (file: string, line, column: i32, hi: int, len: int) {
|
slice_expr_error_hi :: proc "contextless" (file: string, line, column: i32, hi: int, len: int) {
|
||||||
if 0 <= hi && hi <= len {
|
if 0 <= hi && hi <= len {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
slice_handle_error(file, line, column, 0, hi, len)
|
slice_handle_error(file, line, column, 0, hi, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) {
|
slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: i32, lo, hi: int, len: int) {
|
||||||
if 0 <= lo && lo <= len && lo <= hi && hi <= len {
|
if 0 <= lo && lo <= len && lo <= hi && hi <= len {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
slice_handle_error(file, line, column, lo, hi, len)
|
slice_handle_error(file, line, column, lo, hi, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) {
|
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) {
|
||||||
if 0 <= low && low <= high && high <= max {
|
if 0 <= low && low <= high && high <= max {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) {
|
handle_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) {
|
||||||
print_caller_location(Source_Code_Location{file, line, column, ""})
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
print_string(" Invalid dynamic array indices ")
|
print_string(" Invalid dynamic array indices ")
|
||||||
@@ -124,14 +95,15 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
bounds_trap()
|
bounds_trap()
|
||||||
}
|
}
|
||||||
handle_error(file, line, column, low, high, max)
|
handle_error(file, line, column, low, high, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
matrix_bounds_check_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) {
|
matrix_bounds_check_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) {
|
||||||
if 0 <= row_index && row_index < row_count &&
|
if 0 <= row_index && row_index < row_count &&
|
||||||
0 <= column_index && column_index < column_count {
|
0 <= column_index && column_index < column_count {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) {
|
handle_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) {
|
||||||
print_caller_location(Source_Code_Location{file, line, column, ""})
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
print_string(" Matrix indices [")
|
print_string(" Matrix indices [")
|
||||||
@@ -147,13 +119,41 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
bounds_trap()
|
bounds_trap()
|
||||||
}
|
}
|
||||||
handle_error(file, line, column, row_index, column_index, row_count, column_count)
|
handle_error(file, line, column, row_index, column_index, row_count, column_count)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
when ODIN_DISALLOW_RTTI {
|
||||||
|
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32) {
|
||||||
|
if ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@(cold)
|
||||||
|
handle_error :: proc "contextless" (file: string, line, column: i32) {
|
||||||
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
|
print_string(" Invalid type assertion\n")
|
||||||
|
type_assertion_trap()
|
||||||
|
}
|
||||||
|
handle_error(file, line, column)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: i32) {
|
||||||
|
if ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@(cold)
|
||||||
|
handle_error :: proc "contextless" (file: string, line, column: i32) {
|
||||||
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
|
print_string(" Invalid type assertion\n")
|
||||||
|
type_assertion_trap()
|
||||||
|
}
|
||||||
|
handle_error(file, line, column)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid) {
|
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid) {
|
||||||
if ok {
|
if ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid) {
|
handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid) {
|
||||||
print_caller_location(Source_Code_Location{file, line, column, ""})
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
||||||
print_string(" Invalid type assertion from ")
|
print_string(" Invalid type assertion from ")
|
||||||
@@ -198,6 +198,7 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid, from_data: rawptr) {
|
handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid, from_data: rawptr) {
|
||||||
|
|
||||||
actual := variant_type(from, from_data)
|
actual := variant_type(from, from_data)
|
||||||
@@ -219,13 +220,11 @@ when ODIN_FOREIGN_ERROR_PROCEDURES {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// `make` related procedures below
|
|
||||||
|
|
||||||
|
|
||||||
make_slice_error_loc :: #force_inline proc "contextless" (loc := #caller_location, len: int) {
|
make_slice_error_loc :: #force_inline proc "contextless" (loc := #caller_location, len: int) {
|
||||||
if 0 <= len {
|
if 0 <= len {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (loc: Source_Code_Location, len: int) {
|
handle_error :: proc "contextless" (loc: Source_Code_Location, len: int) {
|
||||||
print_caller_location(loc)
|
print_caller_location(loc)
|
||||||
print_string(" Invalid slice length for make: ")
|
print_string(" Invalid slice length for make: ")
|
||||||
@@ -236,10 +235,11 @@ make_slice_error_loc :: #force_inline proc "contextless" (loc := #caller_locatio
|
|||||||
handle_error(loc, len)
|
handle_error(loc, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
make_dynamic_array_error_loc :: #force_inline proc "contextless" (loc := #caller_location, len, cap: int) {
|
make_dynamic_array_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, len, cap: int) {
|
||||||
if 0 <= len && len <= cap {
|
if 0 <= len && len <= cap {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (loc: Source_Code_Location, len, cap: int) {
|
handle_error :: proc "contextless" (loc: Source_Code_Location, len, cap: int) {
|
||||||
print_caller_location(loc)
|
print_caller_location(loc)
|
||||||
print_string(" Invalid dynamic array parameters for make: ")
|
print_string(" Invalid dynamic array parameters for make: ")
|
||||||
@@ -256,6 +256,7 @@ make_map_expr_error_loc :: #force_inline proc "contextless" (loc := #caller_loca
|
|||||||
if 0 <= cap {
|
if 0 <= cap {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@(cold)
|
||||||
handle_error :: proc "contextless" (loc: Source_Code_Location, cap: int) {
|
handle_error :: proc "contextless" (loc: Source_Code_Location, cap: int) {
|
||||||
print_caller_location(loc)
|
print_caller_location(loc)
|
||||||
print_string(" Invalid map capacity for make: ")
|
print_string(" Invalid map capacity for make: ")
|
||||||
@@ -265,3 +266,23 @@ make_map_expr_error_loc :: #force_inline proc "contextless" (loc := #caller_loca
|
|||||||
}
|
}
|
||||||
handle_error(loc, cap)
|
handle_error(loc, cap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bounds_check_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, index, count: int) {
|
||||||
|
bounds_check_error(file_path, line, column, index, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
slice_expr_error_hi_loc :: #force_inline proc "contextless" (using loc := #caller_location, hi: int, len: int) {
|
||||||
|
slice_expr_error_hi(file_path, line, column, hi, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
slice_expr_error_lo_hi_loc :: #force_inline proc "contextless" (using loc := #caller_location, lo, hi: int, len: int) {
|
||||||
|
slice_expr_error_lo_hi(file_path, line, column, lo, hi, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamic_array_expr_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, low, high, max: int) {
|
||||||
|
dynamic_array_expr_error(file_path, line, column, low, high, max)
|
||||||
|
}
|
||||||
|
|||||||
@@ -160,12 +160,20 @@ print_caller_location :: proc "contextless" (using loc: Source_Code_Location) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_typeid :: proc "contextless" (id: typeid) {
|
print_typeid :: proc "contextless" (id: typeid) {
|
||||||
|
when ODIN_DISALLOW_RTTI {
|
||||||
|
if id == nil {
|
||||||
|
print_string("nil")
|
||||||
|
} else {
|
||||||
|
print_string("<unknown type>")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if id == nil {
|
if id == nil {
|
||||||
print_string("nil")
|
print_string("nil")
|
||||||
} else {
|
} else {
|
||||||
ti := type_info_of(id)
|
ti := type_info_of(id)
|
||||||
print_type(ti)
|
print_type(ti)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print_type :: proc "contextless" (ti: ^Type_Info) {
|
print_type :: proc "contextless" (ti: ^Type_Info) {
|
||||||
if ti == nil {
|
if ti == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user