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

View File

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

View File

@ -1,6 +1,7 @@
include './base' include './base'
include './f64' include './f64'
include './cbqnDefs' include './cbqnDefs'
include './sse3'
include './avx' include './avx'
include './avx2' include './avx2'
include './bitops' 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} f32mul:= cf32{w} * cf32{x}
tup{w*x, any{M{cast_v{[8]u32, emit{[8]f32, '_mm256_cmp_ps', abs{f32mul}, max, 29}}}}} 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 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 wp = unpackQ{w, broadcast{T, 0}}
# def xp = unpackQ{x, broadcast{T, 0}} # def xp = unpackQ{x, broadcast{T, 0}}
# def rp = each{__mul32, wp, xp} # def rp = each{__mul32, wp, xp}

View File

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