[MOAB-dev] r1584 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Tue Feb 5 11:17:26 CST 2008
Author: kraftche
Date: 2008-02-05 11:17:26 -0600 (Tue, 05 Feb 2008)
New Revision: 1584
Modified:
MOAB/trunk/TestUtil.hpp
Log:
Minor improvements to longjmp mode of error handling:
- use siglongjmp rather than longjmp: more portable because we're
sometimes doing long jumps out of signal handlers
- on error, just call siglongjmp rather than going through the
signal handler, and use -1 as the return code, because valgrind
interacts oddly with SIGUSR2 hanlding.
Modified: MOAB/trunk/TestUtil.hpp
===================================================================
--- MOAB/trunk/TestUtil.hpp 2008-02-04 21:31:13 UTC (rev 1583)
+++ MOAB/trunk/TestUtil.hpp 2008-02-05 17:17:26 UTC (rev 1584)
@@ -53,6 +53,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
+#include <setjmp.h>
#if MODE == EXCEPTION_MODE
struct ErrorExcept{};
@@ -66,22 +67,18 @@
#elif MODE == LONGJMP_MODE
# include <signal.h>
# include <setjmp.h>
-# ifdef SIGUSR2
-# define FLAG_ERROR raise(SIGUSR2)
-# else
-# define FLAG_ERROR abort()
-# endif
+# define FLAG_ERROR siglongjmp( jmpenv, -1 )
#else
# error "MODE not set"
#endif
#if MODE == LONGJMP_MODE
-jmp_buf jmpenv;
+sigjmp_buf jmpenv;
extern "C" {
void sighandler( int sig ) {
signal( sig, sighandler );
- longjmp(jmpenv, sig);
+ siglongjmp(jmpenv, sig);
// should never return from longjmp
exit(1);
}
@@ -228,19 +225,17 @@
}
#elif MODE == LONGJMP_MODE
- int sig = setjmp( jmpenv );
- if (!sig) {
+ int rval = sigsetjmp( jmpenv, 1 );
+ if (!rval) {
(*test)();
return 0;
}
-#ifdef SIGUSR2
- else if(sig == SIGUSR2) {
+ else if (rval == -1) {
printf( " %s: FAILED\n", func_name );
return 1;
}
-#endif
else {
- printf( " %s: TERMINATED (signal %d)\n", func_name, sig );
+ printf( " %s: TERMINATED (signal %d)\n", func_name, rval );
return 1;
}
#else
More information about the moab-dev
mailing list