diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-02-28 12:15:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-28 12:15:54 +0000 |
| commit | 9afd9f9beae310d2a3bea98cd713b22d2f167cf9 (patch) | |
| tree | 1f5ed60d50eeb282ae4dd451dfe75fab73e32052 /core/runtime | |
| parent | eb60ec3899922b6b98a5ee1a00766d5d9b9917e1 (diff) | |
| parent | c8d3a9121bbed1cff1fee45d6ecf0fa4748f4d21 (diff) | |
Merge branch 'master' into new-temp-allocator
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core.odin | 7 | ||||
| -rw-r--r-- | core/runtime/default_temporary_allocator.odin | 5 | ||||
| -rw-r--r-- | core/runtime/internal.odin | 21 | ||||
| -rw-r--r-- | core/runtime/print.odin | 39 |
4 files changed, 38 insertions, 34 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index c64ab7d3b..2d20310ae 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -507,11 +507,8 @@ Odin_Endian_Type :: type_of(ODIN_ENDIAN) foreign { @(link_name="__$startup_runtime") _startup_runtime :: proc "odin" () --- -} - -@(link_name="__$cleanup_runtime") -_cleanup_runtime :: proc() { - default_temp_allocator_destroy(&global_default_temp_allocator_data) + @(link_name="__$cleanup_runtime") + _cleanup_runtime :: proc "odin" () --- } _cleanup_runtime_contextless :: proc "contextless" () { diff --git a/core/runtime/default_temporary_allocator.odin b/core/runtime/default_temporary_allocator.odin index 3bfdaab3d..296ead722 100644 --- a/core/runtime/default_temporary_allocator.odin +++ b/core/runtime/default_temporary_allocator.odin @@ -72,3 +72,8 @@ default_temp_allocator :: proc(allocator: ^Default_Temp_Allocator) -> Allocator data = allocator, } } + +@(fini, private) +_destroy_temp_allocator_fini :: proc() { + default_temp_allocator_destroy(&global_default_temp_allocator_data) +} diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index cb04ff0aa..3c8cade39 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -184,32 +184,33 @@ mem_free_all :: #force_inline proc(allocator := context.allocator, loc := #calle return } -mem_resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) { +mem_resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: Allocator_Error) { if allocator.procedure == nil { return nil, nil } if new_size == 0 { if ptr != nil { - _, err := allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc) - return nil, err + _, err = allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc) + return } - return nil, nil + return } else if ptr == nil { return allocator.procedure(allocator.data, .Alloc, new_size, alignment, nil, 0, loc) } else if old_size == new_size && uintptr(ptr) % uintptr(alignment) == 0 { - return ([^]byte)(ptr)[:old_size], nil + data = ([^]byte)(ptr)[:old_size] + return } - data, err := allocator.procedure(allocator.data, .Resize, new_size, alignment, ptr, old_size, loc) + data, err = allocator.procedure(allocator.data, .Resize, new_size, alignment, ptr, old_size, loc) if err == .Mode_Not_Implemented { data, err = allocator.procedure(allocator.data, .Alloc, new_size, alignment, nil, 0, loc) if err != nil { - return data, err + return } copy(data, ([^]byte)(ptr)[:old_size]) _, err = allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc) } - return data, err + return } memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool { @@ -223,7 +224,7 @@ memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool { when size_of(uint) == 8 { if word_length := length >> 3; word_length != 0 { - for i in 0..<word_length { + for _ in 0..<word_length { if intrinsics.unaligned_load((^u64)(a)) != intrinsics.unaligned_load((^u64)(b)) { return false } @@ -254,7 +255,7 @@ memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool { return true } else { if word_length := length >> 2; word_length != 0 { - for i in 0..<word_length { + for _ in 0..<word_length { if intrinsics.unaligned_load((^u32)(a)) != intrinsics.unaligned_load((^u32)(b)) { return false } diff --git a/core/runtime/print.odin b/core/runtime/print.odin index 819cd5796..9696488a4 100644 --- a/core/runtime/print.odin +++ b/core/runtime/print.odin @@ -2,6 +2,9 @@ package runtime _INTEGER_DIGITS :: "0123456789abcdefghijklmnopqrstuvwxyz" +@(private="file") +_INTEGER_DIGITS_VAR := _INTEGER_DIGITS + when !ODIN_DISALLOW_RTTI { print_any_single :: proc(arg: any) { x := arg @@ -105,14 +108,14 @@ encode_rune :: proc "contextless" (c: rune) -> ([4]u8, int) { return buf, 4 } -print_string :: proc "contextless" (str: string) -> (int, _OS_Errno) { - return os_write(transmute([]byte)str) +print_string :: proc "contextless" (str: string) -> (n: int) { + n, _ = os_write(transmute([]byte)str) + return } -print_strings :: proc "contextless" (args: ..string) -> (n: int, err: _OS_Errno) { +print_strings :: proc "contextless" (args: ..string) -> (n: int) { for str in args { - m: int - m, err = os_write(transmute([]byte)str) + m, err := os_write(transmute([]byte)str) n += m if err != 0 { break @@ -121,8 +124,9 @@ print_strings :: proc "contextless" (args: ..string) -> (n: int, err: _OS_Errno) return } -print_byte :: proc "contextless" (b: byte) -> (int, _OS_Errno) { - return os_write([]byte{b}) +print_byte :: proc "contextless" (b: byte) -> (n: int) { + n, _ = os_write([]byte{b}) + return } print_encoded_rune :: proc "contextless" (r: rune) { @@ -141,11 +145,10 @@ print_encoded_rune :: proc "contextless" (r: rune) { if r <= 0 { print_string("\\x00") } else if r < 32 { - digits := _INTEGER_DIGITS n0, n1 := u8(r) >> 4, u8(r) & 0xf print_string("\\x") - print_byte(digits[n0]) - print_byte(digits[n1]) + print_byte(_INTEGER_DIGITS_VAR[n0]) + print_byte(_INTEGER_DIGITS_VAR[n1]) } else { print_rune(r) } @@ -153,7 +156,7 @@ print_encoded_rune :: proc "contextless" (r: rune) { print_byte('\'') } -print_rune :: proc "contextless" (r: rune) -> (int, _OS_Errno) #no_bounds_check { +print_rune :: proc "contextless" (r: rune) -> int #no_bounds_check { RUNE_SELF :: 0x80 if r < RUNE_SELF { @@ -161,29 +164,27 @@ print_rune :: proc "contextless" (r: rune) -> (int, _OS_Errno) #no_bounds_check } b, n := encode_rune(r) - return os_write(b[:n]) + m, _ := os_write(b[:n]) + return m } print_u64 :: proc "contextless" (x: u64) #no_bounds_check { - digits := _INTEGER_DIGITS - a: [129]byte i := len(a) b := u64(10) u := x for u >= b { - i -= 1; a[i] = digits[u % b] + i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b] u /= b } - i -= 1; a[i] = digits[u % b] + i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b] os_write(a[i:]) } print_i64 :: proc "contextless" (x: i64) #no_bounds_check { - digits := _INTEGER_DIGITS b :: i64(10) u := x @@ -193,10 +194,10 @@ print_i64 :: proc "contextless" (x: i64) #no_bounds_check { a: [129]byte i := len(a) for u >= b { - i -= 1; a[i] = digits[u % b] + i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b] u /= b } - i -= 1; a[i] = digits[u % b] + i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b] if neg { i -= 1; a[i] = '-' } |