Also restore codepage on trap.

This commit is contained in:
Jeroen van Rijn
2026-08-16 17:50:49 +02:00
parent 7f532cad14
commit c63561b700
4 changed files with 26 additions and 20 deletions

View File

@@ -945,5 +945,25 @@ default_assertion_contextless_failure_proc :: proc "contextless" (prefix, messag
print_byte('\n')
}
}
when ODIN_CODEPAGE_MAGIC {
SetConsoleOutputCP(old_console_codepage)
}
trap()
}
ODIN_CODEPAGE_MAGIC :: ODIN_OS == .Windows && #config(ODIN_CODEPAGE_MAGIC, !ODIN_BEDROCK)
when ODIN_CODEPAGE_MAGIC {
@(private)
old_console_codepage: u32
@(private)
UTF_8 :: 65001
}
foreign import kernel32 "system:Kernel32.lib"
@(default_calling_convention="system")
foreign kernel32 {
GetConsoleOutputCP :: proc() -> u32 ---
SetConsoleOutputCP :: proc(codepage: u32) -> b32 ---
}

View File

@@ -5,16 +5,6 @@ package runtime
import "base:intrinsics"
ODIN_CODEPAGE_MAGIC :: #config(ODIN_CODEPAGE_MAGIC, !ODIN_BEDROCK)
when ODIN_CODEPAGE_MAGIC {
@(private="file")
old_console_codepage: u32
@(private="file")
UTF_8 :: 65001
}
when ODIN_BUILD_MODE == .Dynamic {
@(link_name="DllMain", linkage="strong", require)
DllMain :: proc "system" (hinstDLL: rawptr, fdwReason: u32, lpReserved: rawptr) -> b32 {
@@ -90,11 +80,4 @@ when ODIN_BUILD_MODE == .Dynamic {
return 0
}
}
}
foreign import kernel32 "system:Kernel32.lib"
@(default_calling_convention="system")
foreign kernel32 {
GetConsoleOutputCP :: proc() -> u32 ---
SetConsoleOutputCP :: proc(codepage: u32) -> b32 ---
}

View File

@@ -11,8 +11,9 @@ foreign kernel32 {
windows_trap_array_bounds :: proc "contextless" () -> ! {
EXCEPTION_ARRAY_BOUNDS_EXCEEDED :: 0xC000008C
when ODIN_CODEPAGE_MAGIC {
SetConsoleOutputCP(old_console_codepage)
}
RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, nil)
}

View File

@@ -15,7 +15,9 @@ windows_trap_array_bounds :: proc "contextless" () -> ! {
foreign kernel32 {
RaiseException :: proc "system" (dwExceptionCode, dwExceptionFlags, nNumberOfArguments: DWORD, lpArguments: ^ULONG_PTR) -> ! ---
}
when ODIN_CODEPAGE_MAGIC {
SetConsoleOutputCP(old_console_codepage)
}
RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, nil)
}