don't include setjmp.h when CATCH_ERRORS=0

This commit is contained in:
dzaima 2022-04-06 18:52:09 +03:00
parent 6bce21b55c
commit 4a316c9398
4 changed files with 18 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#include <unistd.h>
#include <poll.h>
#include <errno.h>
#include <sys/wait.h>
#include "../core.h"
#include "../utils/hash.h"
@ -758,9 +758,10 @@ B fromUtf8_c1(B t, B x) {
extern char** environ;
#if __has_include(<spawn.h>)
#if __has_include(<spawn.h>) && __has_include(<sys/wait.h>)
#include <spawn.h>
#include <fcntl.h>
#include <sys/wait.h>
typedef struct pollfd pollfd;
void shClose(int fd) { if (close(fd)) err("bad file descriptor close"); }

View File

@ -70,7 +70,9 @@
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#if CATCH_ERRORS
#include <setjmp.h>
#endif
#ifdef HEAP_VERIFY
#undef CATCH_ERRORS
#define CATCH_ERRORS 0
@ -342,8 +344,8 @@ NOINLINE NORETURN void rethrow();
NOINLINE NORETURN void thrM(char* s);
NOINLINE NORETURN void thrF(char* s, ...);
NOINLINE NORETURN void thrOOM(void);
jmp_buf* prepareCatch(void);
#if CATCH_ERRORS
jmp_buf* prepareCatch(void);
#define CATCH setjmp(*prepareCatch()) // use as `if (CATCH) { /*handle error*/ freeThrown(); return; } /*potentially erroring thing*/ popCatch(); /*no errors yay*/`
#else // note: popCatch() must always be called if no error was caught, so no returns before it!
#define CATCH false

View File

@ -1,6 +1,7 @@
include './base'
include './f64'
include './cbqnDefs'
include './sse3'
include './avx'
include './avx2'
include './bitops'
@ -59,6 +60,7 @@ def arithChk2{F, M, w:T, x:T, i & match{F,__mul} & isvec{T} & i32==eltype{T}} =
f32mul:= cf32{w} * cf32{x}
tup{w*x, any{M{cast_v{[8]u32, emit{[8]f32, '_mm256_cmp_ps', abs{f32mul}, max, 29}}}}}
# TODO fallback to the below if the above fails
# TODO don't do this, but instead shuffle one half, do math, unshuffle that half
# def wp = unpackQ{w, broadcast{T, 0}}
# def xp = unpackQ{x, broadcast{T, 0}}
# def rp = each{__mul32, wp, xp}

View File

@ -1076,9 +1076,10 @@ void comp_init() {
typedef struct CatchFrame {
jmp_buf jmp;
#if CATCH_ERRORS
jmp_buf jmp;
#endif
u64 gsDepth;
u64 envDepth;
u64 cfDepth;
@ -1087,6 +1088,7 @@ CatchFrame* cf; // points to after end
CatchFrame* cfStart;
CatchFrame* cfEnd;
#if CATCH_ERRORS
jmp_buf* prepareCatch() { // in the case of returning false, must call popCatch();
if (cf==cfEnd) {
u64 n = cfEnd-cfStart;
@ -1101,6 +1103,8 @@ jmp_buf* prepareCatch() { // in the case of returning false, must call popCatch(
cf->envDepth = (envCurr+1)-envStart;
return &(cf++)->jmp;
}
#endif
void popCatch() {
#if CATCH_ERRORS
assert(cf>cfStart);
@ -1225,6 +1229,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
// while (c>gStackStart) { print(*--c); putchar('\n'); } printf("gStack printed\n");
#if CATCH_ERRORS
if (cf>cfStart) { // something wants to catch errors
cf--;
@ -1239,6 +1244,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
cf = cfStart+cf->cfDepth;
longjmp(cf->jmp, 1);
} else { // uncaught error
#endif
assert(cf==cfStart);
fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fputc('\n',stderr); fflush(stderr);
Env* envEnd = envCurr+1;
@ -1249,7 +1255,9 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
#else
exit(1);
#endif
#if CATCH_ERRORS
}
#endif
}
NOINLINE NORETURN void thr(B msg) {