summaryrefslogtreecommitdiff
path: root/examples/redis-unstable/src/redisassert.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/src/redisassert.h')
-rw-r--r--examples/redis-unstable/src/redisassert.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/redis-unstable/src/redisassert.h b/examples/redis-unstable/src/redisassert.h
new file mode 100644
index 0000000..4de8d5c
--- /dev/null
+++ b/examples/redis-unstable/src/redisassert.h
@@ -0,0 +1,35 @@
+/* redisassert.h -- Drop in replacements assert.h that prints the stack trace
+ * in the Redis logs.
+ *
+ * This file should be included instead of "assert.h" inside libraries used by
+ * Redis that are using assertions, so instead of Redis disappearing with
+ * SIGABORT, we get the details and stack trace inside the log file.
+ *
+ * ----------------------------------------------------------------------------
+ *
+ * Copyright (c) 2006-Present, Redis Ltd.
+ * All rights reserved.
+ *
+ * Licensed under your choice of (a) the Redis Source Available License 2.0
+ * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the
+ * GNU Affero General Public License v3 (AGPLv3).
+ */
+
+#ifndef __REDIS_ASSERT_H__
+#define __REDIS_ASSERT_H__
+
+#include "config.h"
+
+#define assert(_e) (likely((_e))?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),redis_unreachable()))
+#define panic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),redis_unreachable()
+
+void _serverAssert(const char *estr, const char *file, int line);
+void _serverPanic(const char *file, int line, const char *msg, ...);
+
+#ifdef DEBUG_ASSERTIONS
+#define debugAssert(_e) assert(_e)
+#else
+#define debugAssert(_e) ((void)0)
+#endif
+
+#endif