Use setjmp to implement occam_stop in rangetest.

This stops GCC complaining about occam_stop failing to return.
This commit is contained in:
Adam Sampson 2011-07-21 14:34:01 +00:00
parent 2c4ccfbf39
commit 913aeadd01

View File

@ -1,6 +1,7 @@
int g_stopped; #include <setjmp.h>
#define occam_stop(pos, nargs, format, args...) do { g_stopped = 1; } while (0) jmp_buf g_stopped;
#define occam_stop(pos, nargs, format, args...) longjmp(g_stopped, 1)
#define occam_INT_size SIZEOF_VOIDP #define occam_INT_size SIZEOF_VOIDP
#define occam_extra_param #define occam_extra_param
@ -9,33 +10,27 @@ int g_stopped;
#define report_failure(msg, args...) { printf(msg, ##args); } #define report_failure(msg, args...) { printf(msg, ##args); }
#define testf(call) do { \ #define testf(call) do { \
g_stopped = 0; \ if (setjmp(g_stopped) == 0) { \
call; \ call; \
if (g_stopped == 1) { \
passes++; \
} else { \
failures++; \ failures++; \
report_failure(#call " failed, expected to stop, got: %lld\n", (int64_t)call); \ report_failure(#call " failed, expected to stop, got: %lld\n", (int64_t)call); \
} else { \
passes++; \
} \ } \
} while(0) } while(0)
#define testp(exp, call) do { \ #define testp(exp, call) do { \
g_stopped = 0; \ if (setjmp(g_stopped) == 0) { \
if (exp == call) { \ if (exp == call) { \
if (g_stopped == 0) { \
passes++; \ passes++; \
} else { \ } else { \
failures++; \ failures++; \
report_failure(#call "failed, unexpectedly stopped\n"); \ report_failure(#call " failed, expected %lld, got %lld\n", (int64_t)exp, (int64_t)call); \
} \ } \
} else { \ } else { \
failures++; \ failures++; \
if (g_stopped == 1) { \ report_failure(#call "failed, unexpectedly stopped\n"); \
report_failure(#call "failed, unexpectedly stopped\n"); \ } \
} else { \
report_failure(#call " failed, expected %lld, got %lld\n", (int64_t)exp, (int64_t)call); \
} \
} \
} while (0) } while (0)
#define mult(x,y) (x*y) #define mult(x,y) (x*y)
@ -44,12 +39,18 @@ int g_stopped;
#define test_commutative(t,f,fe) \ #define test_commutative(t,f,fe) \
do {int done_x = 0; for (t x = 0; !(x == 0 && done_x == 1);x+=1) { done_x = 1;\ do {int done_x = 0; for (t x = 0; !(x == 0 && done_x == 1);x+=1) { done_x = 1;\
int done_y = 0; for (t y = 0; !(y == x && done_y == 1);y+=1) { done_y = 1;\ int done_y = 0; for (t y = 0; !(y == x && done_y == 1);y+=1) { done_y = 1;\
g_stopped = 0; \ t r0 = 0, r1 = 0; \
const t r0 = f(x,y,""); \ int stopped_earlier = 0, stopped_later = 0; \
const int stopped_earlier = g_stopped; \ if (setjmp(g_stopped) == 0) { \
g_stopped = 0; \ r0 = f(x,y,""); \
const t r1 = f(y,x,""); \ } else { \
const int stopped_later = g_stopped; \ stopped_earlier = 1; \
} \
if (setjmp(g_stopped) == 0) { \
r1 = f(y,x,""); \
} else { \
stopped_later = 1; \
} \
if (stopped_later == 1 && stopped_earlier == 1) {} else if \ if (stopped_later == 1 && stopped_earlier == 1) {} else if \
(stopped_earlier == 0 && stopped_later == 0 && r0 == r1) { \ (stopped_earlier == 0 && stopped_later == 0 && r0 == r1) { \
if ((int)(t)(fe((int)x,(int)y)) != (int)(fe((int)x,(int)y))) { \ if ((int)(t)(fe((int)x,(int)y)) != (int)(fe((int)x,(int)y))) { \