]> git.kaiwu.me - njs.git/commitdiff
Introduced njs_assert() macro.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 27 Aug 2020 14:43:23 +0000 (14:43 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 27 Aug 2020 14:43:23 +0000 (14:43 +0000)
src/njs_assert.h [new file with mode: 0644]
src/njs_main.h

diff --git a/src/njs_assert.h b/src/njs_assert.h
new file mode 100644 (file)
index 0000000..55583ca
--- /dev/null
@@ -0,0 +1,27 @@
+
+/*
+ * Copyright (C) Dmitry Volyntsev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NJS_ASSERT_H_INCLUDED_
+#define _NJS_ASSERT_H_INCLUDED_
+
+#if (NJS_DEBUG)
+
+#define njs_assert(condition)                                                 \
+    do {                                                                      \
+        if (!(condition)) {                                                   \
+            njs_stderror("Assertion \"%s\" failed at %s:%d\n", #condition,    \
+                         __FILE__, __LINE__);                                 \
+            abort();                                                          \
+        }                                                                     \
+    } while (0)
+
+#else
+
+#define njs_assert(condition) (void) (condition)
+
+#endif
+
+#endif /* _NJS_ASSERT_H_INCLUDED_ */
index f59791d4359cbf04635c99f8c5e25b6ac29bdaf3..9884d2b10548bdeb324acda12ec2fc2e7ad761ab 100644 (file)
@@ -36,6 +36,7 @@
 #include <njs_chb.h>
 #include <njs_utils.h>
 #include <njs_sprintf.h>
+#include <njs_assert.h>
 
 #include <njs_pcre.h>
 #include <njs_regex.h>