From 5f17c703c17d3a6574fd059bfb42bc515bc7bc7f Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Tue, 21 Apr 2026 19:32:06 -0500 Subject: [PATCH] Windows exceptions fix --- README.md | 4 +++- include/ci2_exception.h | 1 - src/linux_exception.c | 1 + src/win32_exception.c | 12 ++++++------ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 91eb895..50c55fd 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,14 @@ is a great fix. ` Finished adding Exceptions and Try/Catch. This was the worst example for a platform layers as these are just clever macros. From what I can read, this -approach to error handling is generally frowned upon due to debugging isssues.` +approach to error handling is generally frowned upon due to debugging isssues. +Also, noticed printf, doesn't work on Powershell only MSYS'` ## Todos - [?] Better makefile - [ ] Better Usage Examples +- [ ] Add Windows Dev Setup - [ ] Memory Allocator - [ ] Arena Allocator - [ ] Arrays diff --git a/include/ci2_exception.h b/include/ci2_exception.h index 2a0e16d..f65a090 100644 --- a/include/ci2_exception.h +++ b/include/ci2_exception.h @@ -2,7 +2,6 @@ #define CI2_EXCEPTION_H #include -#include struct Exception { const char *reason; diff --git a/src/linux_exception.c b/src/linux_exception.c index b30c4e6..8ca5f9a 100644 --- a/src/linux_exception.c +++ b/src/linux_exception.c @@ -4,6 +4,7 @@ struct Except_Frame *except_stack = NULL; const struct Exception assertion_failed = { "Assertion failed" }; + void ci2_assert(int e){ if(!e){ RAISE(assertion_failed); diff --git a/src/win32_exception.c b/src/win32_exception.c index 8e00291..16eaf26 100644 --- a/src/win32_exception.c +++ b/src/win32_exception.c @@ -4,7 +4,7 @@ DWORD except_index = -1; -const struct Exception assertion_failed = { "Assertion failed" }; +extern const struct Exception assertion_failed = { "Assertion failed" }; void ci2_assert(int e){ if(!e){ RAISE(assertion_failed); @@ -12,7 +12,7 @@ void ci2_assert(int e){ } #ifdef WIN32 -_CRTIMP void __cdecl _assert(void *, void *, unsigned); +#include // lets the CRT declare _assert correctly itself #undef assert #define ci2_assert(e) ((e) || (_assert(#e, __FILE__, __LINE__), 0)) #endif @@ -48,22 +48,22 @@ void except_raise(const struct Exception *e, const char *file,int line){ void except_init(void) { BOOL cond; except_index = TlsAlloc(); - assert(except_index != TLS_OUT_OF_INDEXES); + ci2_assert(except_index != TLS_OUT_OF_INDEXES); cond = TlsSetValue(except_index, NULL); - assert(cond == TRUE); + ci2_assert(cond == TRUE); } void except_push(Except_Frame *fp) { BOOL cond; fp->prev = TlsGetValue(except_index); cond = TlsSetValue(except_index, fp); - assert(cond == TRUE); + ci2_assert(cond == TRUE); } void except_pop(void) { BOOL cond; Except_Frame *tos = TlsGetValue(except_index); cond = TlsSetValue(except_index, tos->prev); - assert(cond == TRUE); + ci2_assert(cond == TRUE); }