From ad1ed2250e5cb506e5d1f2a47cb07f57734bd48d Mon Sep 17 00:00:00 2001
From: Mark Grondona <mgrondona@llnl.gov>
Date: Sat, 13 Apr 2002 00:46:51 +0000
Subject: [PATCH] xassert; Initial Revision

---
 src/common/xassert.c | 23 +++++++++++++++++++++++
 src/common/xassert.h | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 src/common/xassert.c
 create mode 100644 src/common/xassert.h

diff --git a/src/common/xassert.c b/src/common/xassert.c
new file mode 100644
index 00000000000..817335db3dc
--- /dev/null
+++ b/src/common/xassert.c
@@ -0,0 +1,23 @@
+/* $Id$ */
+
+/* 
+** xassert: replacement for assert which sends error to log instead of stderr
+**
+*/
+
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <src/common/log.h>
+
+void __xassert_failed(char *expr, const char *file, int line, char *func)
+{
+        fatal("%s:%d: %s(): Assertion (%s) failed.\n", file, line, func, expr);
+
+        /* in case abort was disabled in fatal() */
+        abort();
+}
diff --git a/src/common/xassert.h b/src/common/xassert.h
new file mode 100644
index 00000000000..7ee04fa9e8a
--- /dev/null
+++ b/src/common/xassert.h
@@ -0,0 +1,40 @@
+/* $Id$ */
+
+/*
+** xassert: assert type macro with configurable handling
+**          If NDEBUG is defined, do nothing.
+**          If not, and expression is zero, log an error message and abort.
+*/
+
+#ifndef _XASSERT_H
+#define _XASSERT_H	1
+
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "macros.h"
+
+#ifdef NDEBUG
+
+#  define assert(expr)	((void)0)
+
+#else /* !NDEBUG */
+
+#  define xassert(__ex)  _STMT_START { \
+     (__ex) ? ((void)0) : \
+     __xassert_failed(__STRING(__ex), __FILE__,  __LINE__, __CURRENT_FUNC__) \
+     } _STMT_END 
+
+/*  This prints the assertion failed message to the slurm log facility
+**  (see log.h) and aborts the calling program
+**  (messages go to stderr if log is not initialized)
+*/
+extern void __xassert_failed(char *, const char *, int, const char *) 
+	    __NORETURN_ATTR;
+
+#endif /* NDEBUG. */
+
+#endif /* !__XASSERT_H */
+
+/* vim: set sw=4 ts=4 expandtabs */
-- 
GitLab