Windows exceptions fix

This commit is contained in:
2026-04-21 19:32:06 -05:00
parent ade8e8fcac
commit 5f17c703c1
4 changed files with 10 additions and 8 deletions

View File

@@ -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

View File

@@ -2,7 +2,6 @@
#define CI2_EXCEPTION_H
#include <setjmp.h>
#include <assert.h>
struct Exception {
const char *reason;

View File

@@ -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);

View File

@@ -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 <assert.h> // 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);
}