Windows exceptions fix
This commit is contained in:
@@ -28,12 +28,14 @@ is a great fix.
|
|||||||
|
|
||||||
` Finished adding Exceptions and Try/Catch. This was the worst example for a
|
` 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
|
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
|
## Todos
|
||||||
|
|
||||||
- [?] Better makefile
|
- [?] Better makefile
|
||||||
- [ ] Better Usage Examples
|
- [ ] Better Usage Examples
|
||||||
|
- [ ] Add Windows Dev Setup
|
||||||
- [ ] Memory Allocator
|
- [ ] Memory Allocator
|
||||||
- [ ] Arena Allocator
|
- [ ] Arena Allocator
|
||||||
- [ ] Arrays
|
- [ ] Arrays
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#define CI2_EXCEPTION_H
|
#define CI2_EXCEPTION_H
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
struct Exception {
|
struct Exception {
|
||||||
const char *reason;
|
const char *reason;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
struct Except_Frame *except_stack = NULL;
|
struct Except_Frame *except_stack = NULL;
|
||||||
const struct Exception assertion_failed = { "Assertion failed" };
|
const struct Exception assertion_failed = { "Assertion failed" };
|
||||||
|
|
||||||
void ci2_assert(int e){
|
void ci2_assert(int e){
|
||||||
if(!e){
|
if(!e){
|
||||||
RAISE(assertion_failed);
|
RAISE(assertion_failed);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
DWORD except_index = -1;
|
DWORD except_index = -1;
|
||||||
|
|
||||||
const struct Exception assertion_failed = { "Assertion failed" };
|
extern const struct Exception assertion_failed = { "Assertion failed" };
|
||||||
void ci2_assert(int e){
|
void ci2_assert(int e){
|
||||||
if(!e){
|
if(!e){
|
||||||
RAISE(assertion_failed);
|
RAISE(assertion_failed);
|
||||||
@@ -12,7 +12,7 @@ void ci2_assert(int e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
_CRTIMP void __cdecl _assert(void *, void *, unsigned);
|
#include <assert.h> // lets the CRT declare _assert correctly itself
|
||||||
#undef assert
|
#undef assert
|
||||||
#define ci2_assert(e) ((e) || (_assert(#e, __FILE__, __LINE__), 0))
|
#define ci2_assert(e) ((e) || (_assert(#e, __FILE__, __LINE__), 0))
|
||||||
#endif
|
#endif
|
||||||
@@ -48,22 +48,22 @@ void except_raise(const struct Exception *e, const char *file,int line){
|
|||||||
void except_init(void) {
|
void except_init(void) {
|
||||||
BOOL cond;
|
BOOL cond;
|
||||||
except_index = TlsAlloc();
|
except_index = TlsAlloc();
|
||||||
assert(except_index != TLS_OUT_OF_INDEXES);
|
ci2_assert(except_index != TLS_OUT_OF_INDEXES);
|
||||||
cond = TlsSetValue(except_index, NULL);
|
cond = TlsSetValue(except_index, NULL);
|
||||||
assert(cond == TRUE);
|
ci2_assert(cond == TRUE);
|
||||||
}
|
}
|
||||||
void except_push(Except_Frame *fp) {
|
void except_push(Except_Frame *fp) {
|
||||||
BOOL cond;
|
BOOL cond;
|
||||||
|
|
||||||
fp->prev = TlsGetValue(except_index);
|
fp->prev = TlsGetValue(except_index);
|
||||||
cond = TlsSetValue(except_index, fp);
|
cond = TlsSetValue(except_index, fp);
|
||||||
assert(cond == TRUE);
|
ci2_assert(cond == TRUE);
|
||||||
}
|
}
|
||||||
void except_pop(void) {
|
void except_pop(void) {
|
||||||
BOOL cond;
|
BOOL cond;
|
||||||
Except_Frame *tos = TlsGetValue(except_index);
|
Except_Frame *tos = TlsGetValue(except_index);
|
||||||
|
|
||||||
cond = TlsSetValue(except_index, tos->prev);
|
cond = TlsSetValue(except_index, tos->prev);
|
||||||
assert(cond == TRUE);
|
ci2_assert(cond == TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user