diff --git a/example.c b/example.c index fb06578..ac2c3f5 100644 --- a/example.c +++ b/example.c @@ -20,7 +20,7 @@ closeable int close_me(int a){ [[noreturn]] void my_handler(int signum){ if(except_handler.frame) - xsiglongjmp(*except_handler.frame, signum); + siglongjmp(*except_handler.frame, signum); exit(1); } diff --git a/exception.h b/exception.h index 05c85f2..a185414 100644 --- a/exception.h +++ b/exception.h @@ -5,15 +5,11 @@ #ifndef _EXCEPTION_H_ #define _EXCEPTION_H_ -#if defined __godbolt__ || defined __GODBOLT__ -#include "https://raw.githubusercontent.com/m1lkweed/handy-headers/main/xsetjmp.h" -#else -#include "xsetjmp.h" -#endif +#include #include struct exception_frame { - xsigjmp_buf *frame; + sigjmp_buf *frame; volatile sig_atomic_t exception; }; @@ -24,15 +20,15 @@ void _$except_init$(void); void throw(int id); #define try do{ \ - xsigjmp_buf *_$old_exception_frame$, _$new_exception_frame$; \ + sigjmp_buf *_$old_exception_frame$, _$new_exception_frame$; \ volatile int _$except_dummy$ = -1; \ typedef int _$except_no_gotos$[_$except_dummy$]; \ _$old_exception_frame$ = except_handler.frame; \ except_handler.frame = &_$new_exception_frame$; \ except_handler.exception = 0; \ _$except_init$(); \ - if((except_handler.exception = xsigsetjmp(_$new_exception_frame$, 0)) == 0){ \ - for(; _$except_dummy$; ++_$except_dummy$) + if((except_handler.exception = sigsetjmp(_$new_exception_frame$, 0)) == 0){ \ + for(_$except_dummy$ = 1; _$except_dummy$; --_$except_dummy$) #define _$EXCEPT_EMPTY$_HELPER(...) = except_handler.exception, ## __VA_ARGS__ #define _$EXCEPT_EMPTY$(default, ...) default _$EXCEPT_EMPTY$_HELPER(__VA_ARGS__) @@ -55,7 +51,7 @@ _Thread_local struct exception_frame except_handler = {0}; _Noreturn void _$exception_handler$(int signum){ if(except_handler.frame){ - xsiglongjmp(*except_handler.frame, signum); + siglongjmp(*except_handler.frame, signum); }else{ //Set handler to SIG_DFL and reraise signal, in case //the system wants to print a message or core dump @@ -148,7 +144,7 @@ _Noreturn void _$exception_handler$(int signum){ if(id != 0){ except_handler.exception = id; if(except_handler.frame) - xsiglongjmp(*except_handler.frame, id); + siglongjmp(*except_handler.frame, id); _$exception_handler$(id); } }