From 830d2007a6bb11f45b3d90f75dc5d0bef63bef44 Mon Sep 17 00:00:00 2001 From: Fabian Sperber Date: Mon, 13 Mar 2023 20:05:46 +0100 Subject: [PATCH 1/3] Remove usage of global_default_temp_allocator_data when there is no default allocator (freestanding, JS or --default-to-nil-allocator) --- core/runtime/core.odin | 4 +++- core/runtime/core_builtin.odin | 10 +++++++--- core/runtime/default_temporary_allocator.odin | 14 +++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 2d20310ae..040590b4a 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -621,7 +621,9 @@ __init_context :: proc "contextless" (c: ^Context) { c.allocator.data = nil c.temp_allocator.procedure = default_temp_allocator_proc - c.temp_allocator.data = &global_default_temp_allocator_data + when !NO_DEFAULT_TEMP_ALLOCATOR { + c.temp_allocator.data = &global_default_temp_allocator_data + } when !ODIN_DISABLE_ASSERT { c.assertion_failure_proc = default_assertion_failure_proc diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index ae6a4aaf4..84fe5e522 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -15,11 +15,15 @@ container_of :: #force_inline proc "contextless" (ptr: $P/^$Field_Type, $T: type } -@thread_local global_default_temp_allocator_data: Default_Temp_Allocator +when !NO_DEFAULT_TEMP_ALLOCATOR { + @thread_local global_default_temp_allocator_data: Default_Temp_Allocator +} -@builtin +@(builtin, disabled=NO_DEFAULT_TEMP_ALLOCATOR) init_global_temporary_allocator :: proc(size: int, backup_allocator := context.allocator) { - default_temp_allocator_init(&global_default_temp_allocator_data, size, backup_allocator) + when !NO_DEFAULT_TEMP_ALLOCATOR { + default_temp_allocator_init(&global_default_temp_allocator_data, size, backup_allocator) + } } diff --git a/core/runtime/default_temporary_allocator.odin b/core/runtime/default_temporary_allocator.odin index 296ead722..c90f0388d 100644 --- a/core/runtime/default_temporary_allocator.odin +++ b/core/runtime/default_temporary_allocator.odin @@ -1,9 +1,9 @@ package runtime DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE: int : #config(DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE, 4 * Megabyte) +NO_DEFAULT_TEMP_ALLOCATOR: bool : ODIN_OS == .Freestanding || ODIN_OS == .JS || ODIN_DEFAULT_TO_NIL_ALLOCATOR - -when ODIN_OS == .Freestanding || ODIN_OS == .JS || ODIN_DEFAULT_TO_NIL_ALLOCATOR { +when NO_DEFAULT_TEMP_ALLOCATOR { Default_Temp_Allocator :: struct {} default_temp_allocator_init :: proc(s: ^Default_Temp_Allocator, size: int, backing_allocator := context.allocator) {} @@ -54,6 +54,11 @@ when ODIN_OS == .Freestanding || ODIN_OS == .JS || ODIN_DEFAULT_TO_NIL_ALLOCATOR default_temp_allocator_temp_end :: proc(temp: Arena_Temp, loc := #caller_location) { arena_temp_end(temp, loc) } + + @(fini, private) + _destroy_temp_allocator_fini :: proc() { + default_temp_allocator_destroy(&global_default_temp_allocator_data) + } } @(deferred_out=default_temp_allocator_temp_end) @@ -72,8 +77,3 @@ 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) -} From adcc865c7018011240378c2b8ac21e255aa6e26e Mon Sep 17 00:00:00 2001 From: WraithGlade <8360085+WraithGlade@users.noreply.github.com> Date: Sun, 19 Mar 2023 22:06:39 -0400 Subject: [PATCH 2/3] Fixed incorrect precision value in `fmt` doc. It seems like `%.2f` is the correct implementation of "precision 2" for displaying floats, not `$.3f`. It prints two decimal places. Either that or the next case (`%8.3f`) would be wrong instead, if it's the other way around. So, there's a mistake here one way or the other at the least. --- core/fmt/doc.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/fmt/doc.odin b/core/fmt/doc.odin index 668fc9bc6..991058661 100644 --- a/core/fmt/doc.odin +++ b/core/fmt/doc.odin @@ -68,7 +68,7 @@ A period with no following number specifies a precision of 0. Examples: %f default width, default precision %8f width 8, default precision - %.3f default width, precision 2 + %.2f default width, precision 2 %8.3f width 8, precision 3 %8.f width 8, precision 0 From 33798b8b801e549c1ad3ca33c5857c7a6e2b4d38 Mon Sep 17 00:00:00 2001 From: Fabian Sperber Date: Wed, 8 Mar 2023 21:07:54 +0100 Subject: [PATCH 3/3] Need to forward the name of the directive, not the hash token --- core/odin/parser/parser.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index b70c8528e..29af7e71e 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -1425,7 +1425,7 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt { return es case "force_inline", "force_no_inline": - expr := parse_inlining_operand(p, true, tok) + expr := parse_inlining_operand(p, true, tag) es := ast.new(ast.Expr_Stmt, expr.pos, expr.end) es.expr = expr return es