2013-04-16 23:57:53 -04:00
|
|
|
#include <toku_portability.h>
|
2013-04-16 23:57:22 -04:00
|
|
|
#include "toku_assert.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2013-04-16 23:58:56 -04:00
|
|
|
#include <signal.h>
|
2008-02-07 16:35:39 +00:00
|
|
|
|
2008-05-17 01:06:03 +00:00
|
|
|
int toku_continue_on_assert_failure=0;
|
|
|
|
|
2013-04-16 23:57:20 -04:00
|
|
|
static void toku_assert_failed_but_continue_anyway (void) __attribute__((noinline));
|
2008-05-17 01:06:03 +00:00
|
|
|
|
2013-04-16 23:57:20 -04:00
|
|
|
static void
|
|
|
|
toku_assert_failed_but_continue_anyway (void) {
|
2008-05-17 01:06:03 +00:00
|
|
|
printf("Assertion failed, but continuing anyway\n");
|
|
|
|
}
|
|
|
|
|
2008-04-02 23:40:36 +00:00
|
|
|
void toku_do_assert(int expr,const char* expr_as_string,const char *function,const char*file,int line) {
|
2008-02-07 16:35:39 +00:00
|
|
|
if (expr==0) {
|
|
|
|
fprintf(stderr, "%s:%d %s: Assertion `%s' failed\n", file,line,function,expr_as_string);
|
2013-04-16 23:58:56 -04:00
|
|
|
if (!toku_continue_on_assert_failure) {
|
|
|
|
fflush(stderr);
|
|
|
|
#if TOKU_WINDOWS
|
|
|
|
//Following commented methods will not always end the process (could hang).
|
|
|
|
//They could be unacceptable for other reasons as well (popups,
|
|
|
|
//flush buffers before quitting, etc)
|
|
|
|
// abort()
|
|
|
|
// assert(FALSE) (assert.h assert)
|
|
|
|
// raise(SIGABRT)
|
|
|
|
// divide by 0
|
|
|
|
// null dereference
|
|
|
|
// _exit
|
|
|
|
// exit
|
|
|
|
// ExitProcess
|
|
|
|
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
|
|
|
|
//Terminate the process
|
|
|
|
#endif
|
2008-05-17 01:06:03 +00:00
|
|
|
abort();
|
2013-04-16 23:58:56 -04:00
|
|
|
}
|
2008-05-17 01:06:03 +00:00
|
|
|
else
|
|
|
|
toku_assert_failed_but_continue_anyway();
|
2008-02-07 16:35:39 +00:00
|
|
|
}
|
|
|
|
}
|