about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins2017-08-13 05:46:50 +0000
committerPjotr Prins2017-08-13 05:46:50 +0000
commitcfcd91563e90e0492d93ab273e72fe73a97af94f (patch)
treee02f4d80bf28f7f0c0f13486373c6226c5547249
parent6a4238e668fa701c59b1ad8c8461db6d571d75b9 (diff)
downloadpangemma-cfcd91563e90e0492d93ab273e72fe73a97af94f.tar.gz
Fixes https://github.com/genetics-statistics/GEMMA/issues/64
debug.h: replaced assert_fail with enforce_fail
-rw-r--r--src/debug.h24
-rwxr-xr-x[-rw-r--r--]test/dev_test_suite.sh0
2 files changed, 15 insertions, 9 deletions
diff --git a/src/debug.h b/src/debug.h
index 84637e1..fafebcf 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -1,6 +1,9 @@
 #ifndef __DEBUG_H__
 #define __DEBUG_H__
 
+#include <assert.h>
+#include <iostream>
+
 // enforce works like assert but also when NDEBUG is set (i.e., it
 // always works). enforce_msg prints message instead of expr
 
@@ -11,26 +14,29 @@
 #endif
 
 /* This prints an "Assertion failed" message and aborts.  */
-extern "C" void __assert_fail(const char *__assertion, const char *__file,
-                              unsigned int __line,
-                              const char *__function) __THROW
-    __attribute__((__noreturn__));
+inline void __enforce_fail(const char *__assertion, const char *__file,
+                    unsigned int __line,
+                    const char *__function)
+{
+  std::cout << "ERROR: Enforce failed for " << __assertion << " in " << __file << " at line " << __line << " in " << __function << std::endl;
+  exit(1);
+}
 
 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
 
 #define enforce(expr)                                                          \
   ((expr)                                                                      \
        ? __ASSERT_VOID_CAST(0)                                                 \
-       : __assert_fail(__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
+       : __enforce_fail(__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
 
 #define enforce_msg(expr, msg)                                                 \
   ((expr) ? __ASSERT_VOID_CAST(0)                                              \
-          : __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION))
+          : __enforce_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION))
 
 #define enforce_str(expr, msg)                                                 \
   ((expr)                                                                      \
        ? __ASSERT_VOID_CAST(0)                                                 \
-       : __assert_fail((msg).c_str(), __FILE__, __LINE__, __ASSERT_FUNCTION))
+       : __enforce_fail((msg).c_str(), __FILE__, __LINE__, __ASSERT_FUNCTION))
 
 // Helpers to create a unique varname per MACRO
 #define COMBINE1(X, Y) X##Y
@@ -40,7 +46,7 @@ extern "C" void __assert_fail(const char *__assertion, const char *__file,
   auto COMBINE(res, __LINE__) = (expr);                                        \
   (COMBINE(res, __LINE__) == 0                                                 \
        ? __ASSERT_VOID_CAST(0)                                                 \
-       : __assert_fail(gsl_strerror(COMBINE(res, __LINE__)), __FILE__,         \
-                       __LINE__, __ASSERT_FUNCTION))
+       : __enforce_fail(gsl_strerror(COMBINE(res, __LINE__)), __FILE__,         \
+                        __LINE__, __ASSERT_FUNCTION))
 
 #endif
diff --git a/test/dev_test_suite.sh b/test/dev_test_suite.sh
index 522cf3d..522cf3d 100644..100755
--- a/test/dev_test_suite.sh
+++ b/test/dev_test_suite.sh