[njs] Introduced njs_assert() macro.
Dmitry Volyntsev
xeioex at nginx.com
Thu Aug 27 14:43:55 UTC 2020
details: https://hg.nginx.org/njs/rev/fa50cc5b1128
branches:
changeset: 1509:fa50cc5b1128
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Aug 27 14:43:23 2020 +0000
description:
Introduced njs_assert() macro.
diffstat:
src/njs_assert.h | 27 +++++++++++++++++++++++++++
src/njs_main.h | 1 +
2 files changed, 28 insertions(+), 0 deletions(-)
diffs (42 lines):
diff -r 6f561e3d947e -r fa50cc5b1128 src/njs_assert.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/njs_assert.h Thu Aug 27 14:43:23 2020 +0000
@@ -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_ */
diff -r 6f561e3d947e -r fa50cc5b1128 src/njs_main.h
--- a/src/njs_main.h Thu Aug 27 14:43:22 2020 +0000
+++ b/src/njs_main.h Thu Aug 27 14:43:23 2020 +0000
@@ -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>
More information about the nginx-devel
mailing list