summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Derrick <keith.derrick@palm.com>2012-04-12 11:40:44 -0700
committerKeith Derrick <keith.derrick@palm.com>2012-04-12 11:47:56 -0700
commit74d830dc035db05e2d7c4fecc4aff69c2c6d17e7 (patch)
treee2c7b75d332ba84b13e364c5304123604c7fa842
parentca519fb81735bf8eb7a6cf4ddb77f036efcaac61 (diff)
downloadjson-c-74d830dc035db05e2d7c4fecc4aff69c2c6d17e7.tar.gz
Add JASSERT macro to guarantee aborts
-rw-r--r--debug.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/debug.h b/debug.h
index 59a4dfc..1e09701 100644
--- a/debug.h
+++ b/debug.h
@@ -3,6 +3,7 @@
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
+ * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See COPYING for details.
@@ -12,6 +13,8 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_
+#include <stdlib.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -25,21 +28,40 @@ extern void mc_debug(const char *msg, ...);
extern void mc_error(const char *msg, ...);
extern void mc_info(const char *msg, ...);
+#ifndef __STRING
+#define __STRING(x) #x
+#endif
+
+#ifndef PARSER_BROKEN_FIXED
+
+#define JASSERT(cond) do {} while(0)
+
+#else
+
+#define JASSERT(cond) do { \
+ if (!(cond)) { \
+ mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \
+ *(int *)0 = 1;\
+ abort(); \
+ }\
+ } while(0)
+
+#endif
+
+#define MC_ABORT(x, ...) mc_abort(x, ##__VA_ARGS__)
+#define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__)
+
#ifdef MC_MAINTAINER_MODE
#define MC_SET_DEBUG(x) mc_set_debug(x)
#define MC_GET_DEBUG() mc_get_debug()
#define MC_SET_SYSLOG(x) mc_set_syslog(x)
-#define MC_ABORT(x, ...) mc_abort(x, ##__VA_ARGS__)
#define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
-#define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__)
#define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
#else
#define MC_SET_DEBUG(x) if (0) mc_set_debug(x)
#define MC_GET_DEBUG() (0)
#define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x)
-#define MC_ABORT(x, ...) if (0) mc_abort(x, ##__VA_ARGS__)
#define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
-#define MC_ERROR(x, ...) if (0) mc_error(x, ##__VA_ARGS__)
#define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
#endif