Require @(init) and @(fini) to be proc "contextless" ()

This commit is contained in:
gingerBill
2025-08-08 12:10:01 +01:00
parent 3194fda8f3
commit 7642e0a0e0
47 changed files with 170 additions and 102 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ MAX_TEMP_ARENA_COLLISIONS :: MAX_TEMP_ARENA_COUNT - 1
global_default_temp_allocator_arenas: [MAX_TEMP_ARENA_COUNT]runtime.Arena
@(fini, private)
temp_allocator_fini :: proc() {
temp_allocator_fini :: proc "contextless" () {
for &arena in global_default_temp_allocator_arenas {
runtime.arena_destroy(&arena)
}
@@ -69,6 +69,6 @@ _temp_allocator_end :: proc(tmp: runtime.Arena_Temp) {
}
@(init, private)
init_thread_local_cleaner :: proc() {
init_thread_local_cleaner :: proc "contextless" () {
runtime.add_thread_local_cleaner(temp_allocator_fini)
}
+2 -2
View File
@@ -25,8 +25,8 @@ File_Impl :: struct {
}
@(init)
init_std_files :: proc() {
new_std :: proc(impl: ^File_Impl, fd: posix.FD, name: cstring) -> ^File {
init_std_files :: proc "contextless" () {
new_std :: proc "contextless" (impl: ^File_Impl, fd: posix.FD, name: cstring) -> ^File {
impl.file.impl = impl
impl.fd = fd
impl.allocator = runtime.nil_allocator()
+2 -2
View File
@@ -30,8 +30,8 @@ Preopen :: struct {
preopens: []Preopen
@(init)
init_std_files :: proc() {
new_std :: proc(impl: ^File_Impl, fd: wasi.fd_t, name: string) -> ^File {
init_std_files :: proc "contextless" () {
new_std :: proc "contextless" (impl: ^File_Impl, fd: wasi.fd_t, name: string) -> ^File {
impl.file.impl = impl
impl.allocator = runtime.nil_allocator()
impl.fd = fd
+4 -4
View File
@@ -43,8 +43,8 @@ File_Impl :: struct {
}
@(init)
init_std_files :: proc() {
new_std :: proc(impl: ^File_Impl, code: u32, name: string) -> ^File {
init_std_files :: proc "contextless" () {
new_std :: proc "contextless" (impl: ^File_Impl, code: u32, name: string) -> ^File {
impl.file.impl = impl
impl.allocator = runtime.nil_allocator()
@@ -77,7 +77,7 @@ init_std_files :: proc() {
stderr = new_std(&files[2], win32.STD_ERROR_HANDLE, "<stderr>")
}
_handle :: proc(f: ^File) -> win32.HANDLE {
_handle :: proc "contextless" (f: ^File) -> win32.HANDLE {
return win32.HANDLE(_fd(f))
}
@@ -234,7 +234,7 @@ _clone :: proc(f: ^File) -> (clone: ^File, err: Error) {
return _new_file(uintptr(clonefd), name(f), file_allocator())
}
_fd :: proc(f: ^File) -> uintptr {
_fd :: proc "contextless" (f: ^File) -> uintptr {
if f == nil || f.impl == nil {
return INVALID_HANDLE
}
+1 -1
View File
@@ -160,7 +160,7 @@ _get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err
can_use_long_paths: bool
@(init)
init_long_path_support :: proc() {
init_long_path_support :: proc "contextless" () {
can_use_long_paths = false
key: win32.HKEY
+4 -2
View File
@@ -1226,7 +1226,8 @@ _processor_core_count :: proc() -> int {
}
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
res := make([]string, len(runtime.args__))
for _, i in res {
res[i] = string(runtime.args__[i])
@@ -1235,7 +1236,8 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+4 -2
View File
@@ -965,7 +965,8 @@ _processor_core_count :: proc() -> int {
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
res := make([]string, len(runtime.args__))
for _, i in res {
res[i] = string(runtime.args__[i])
@@ -974,6 +975,7 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+4 -2
View File
@@ -317,7 +317,8 @@ file_size :: proc(fd: Handle) -> (i64, Error) {
args := _alloc_command_line_arguments()
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
res := make([]string, len(runtime.args__))
for arg, i in runtime.args__ {
res[i] = string(arg)
@@ -326,7 +327,8 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+4 -2
View File
@@ -1098,7 +1098,8 @@ _processor_core_count :: proc() -> int {
}
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
res := make([]string, len(runtime.args__))
for _, i in res {
res[i] = string(runtime.args__[i])
@@ -1107,7 +1108,8 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+4 -2
View File
@@ -1015,7 +1015,8 @@ _processor_core_count :: proc() -> int {
}
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
res := make([]string, len(runtime.args__))
for _, i in res {
res[i] = string(runtime.args__[i])
@@ -1024,6 +1025,7 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+4 -2
View File
@@ -915,7 +915,8 @@ _processor_core_count :: proc() -> int {
}
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
res := make([]string, len(runtime.args__))
for _, i in res {
res[i] = string(runtime.args__[i])
@@ -924,6 +925,7 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+6 -4
View File
@@ -28,16 +28,18 @@ stderr: Handle = 2
args := _alloc_command_line_arguments()
@(private, require_results)
_alloc_command_line_arguments :: proc() -> (args: []string) {
args = make([]string, len(runtime.args__))
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
args := make([]string, len(runtime.args__))
for &arg, i in args {
arg = string(runtime.args__[i])
}
return
return args
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
delete(args)
}
+4 -2
View File
@@ -194,7 +194,8 @@ current_thread_id :: proc "contextless" () -> int {
@(private, require_results)
_alloc_command_line_arguments :: proc() -> []string {
_alloc_command_line_arguments :: proc "contextless" () -> []string {
context = runtime.default_context()
arg_count: i32
arg_list_ptr := win32.CommandLineToArgvW(win32.GetCommandLineW(), &arg_count)
arg_list := make([]string, int(arg_count))
@@ -216,7 +217,8 @@ _alloc_command_line_arguments :: proc() -> []string {
}
@(private, fini)
_delete_command_line_arguments :: proc() {
_delete_command_line_arguments :: proc "contextless" () {
context = runtime.default_context()
for s in args {
delete(s)
}