From 04706f2dcd465aec35228eeeca322eb4aad1c079 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 31 Dec 2025 00:13:38 +0100 Subject: [PATCH] Fix issue when removing test files on abort. --- lib/std/io/formatter.c3 | 3 ++ lib/std/os/win32/exception.c3 | 62 ++++++++++++++++------------------- test/src/test_suite_runner.c3 | 2 +- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index fe8cd14d3..5a21e7e02 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -2,6 +2,9 @@ module std::io; import std::collections::map; import libc; +// It is vitally important that the formatter doesn't do any allocations, +// or it ceases to be useful in constrained environments. + const int PRINTF_NTOA_BUFFER_SIZE = 256; interface Printable diff --git a/lib/std/os/win32/exception.c3 b/lib/std/os/win32/exception.c3 index 884e81d66..46b435feb 100644 --- a/lib/std/os/win32/exception.c3 +++ b/lib/std/os/win32/exception.c3 @@ -135,41 +135,37 @@ fn Win32_LONG exception_handler(ExceptionPointers* exception_info) { if (!has_panicked) { - - @stack_mem(4096; Allocator allocator) + @stack_mem(2048; Allocator allocator) { - @pool_init(allocator, 2048) + DString s; + s.init(allocator: allocator); + Win32_DWORD code = exception_info.exception_record.exception_code; + void* addr = exception_info.exception_record.exception_address; + switch (code) { - DString s; - s.init(allocator: allocator); - Win32_DWORD code = exception_info.exception_record.exception_code; - void* addr = exception_info.exception_record.exception_address; - switch (code) - { - case 0x80000001: s.appendf("Guard page violation at address %p", addr); - case 0x80000002: s.appendf("Datatype misalignment at address %p", addr); - case 0xC0000005: s.appendf("Access Violation at address %p", addr); - case 0xC0000006: s.appendf("In page error at address %p", addr); - case 0xC000001D: s.appendf("Illegal instruction at address %p", addr); - case 0xC000008C: s.appendf("Array bounds exceeded at address %p", addr); - case 0xC000008D: s.appendf("Flt denormal operand at address %p", addr); - case 0xC000008E: s.appendf("Flt divide by zero at address %p", addr); - case 0xC0000090: s.appendf("Flt invalid operation at address %p", addr); - case 0xC0000094: s.appendf("Integer divide by zero at address %p", addr); - case 0xC00000FD: s.appendf("Stack overflow at address %p", addr); - case 0xC0000096: s.appendf("Privileged instruction at address %p", addr); - case 0xC0000374: s.appendf("Heap corruption detected at address %p", addr); - case 0xC0000409: s.appendf("Stack buffer overflow at address %p", addr); - case 0xC00004A2: s.appendf("Enclave violation at address %p", addr); - default: - s.appendf("Unhandled exception (%X) at %p", code, addr); - } - if (!builtin::print_backtrace(s.str_view(), 8)) - { - io::eprintfn("\nERROR: %s", s.str_view()); - } - }; - }; + case 0x80000001: s.appendf("Guard page violation at address %p", addr); + case 0x80000002: s.appendf("Datatype misalignment at address %p", addr); + case 0xC0000005: s.appendf("Access Violation at address %p", addr); + case 0xC0000006: s.appendf("In page error at address %p", addr); + case 0xC000001D: s.appendf("Illegal instruction at address %p", addr); + case 0xC000008C: s.appendf("Array bounds exceeded at address %p", addr); + case 0xC000008D: s.appendf("Flt denormal operand at address %p", addr); + case 0xC000008E: s.appendf("Flt divide by zero at address %p", addr); + case 0xC0000090: s.appendf("Flt invalid operation at address %p", addr); + case 0xC0000094: s.appendf("Integer divide by zero at address %p", addr); + case 0xC00000FD: s.appendf("Stack overflow at address %p", addr); + case 0xC0000096: s.appendf("Privileged instruction at address %p", addr); + case 0xC0000374: s.appendf("Heap corruption detected at address %p", addr); + case 0xC0000409: s.appendf("Stack buffer overflow at address %p", addr); + case 0xC00004A2: s.appendf("Enclave violation at address %p", addr); + default: + s.appendf("Unhandled exception (%X) at %p", code, addr); + } + if (!builtin::print_backtrace(s.str_view(), 8)) + { + io::eprintfn("\nERROR: %s", s.str_view()); + } + }; } if (previous_filter) { diff --git a/test/src/test_suite_runner.c3 b/test/src/test_suite_runner.c3 index 47d60afd6..32ca44167 100644 --- a/test/src/test_suite_runner.c3 +++ b/test/src/test_suite_runner.c3 @@ -38,7 +38,7 @@ fn int main(String[] args) libc::signal(libc::SIGINT, fn void (CInt _signal) { foreach (f : path::ls(mem, context.start_cwd)!!) { - if (f.str_view().starts_with("_c3test_")) (void)path::rmtree(context.start_cwd.tappend(f.str_view())!!); + if (f.str_view().starts_with("_c3test_")) (void)path::rmtree(context.start_cwd.append(mem, f.str_view())); } os::exit(1); });