aboutsummaryrefslogtreecommitdiff
path: root/src/zjs_common.h
diff options
context:
space:
mode:
authorGeoff Gustafson <geoff@linux.intel.com>2017-09-08 10:09:18 -0700
committerGeoff Gustafson <geoff@linux.intel.com>2017-09-11 16:13:23 -0700
commited720ccd631802d15966c2d506573bac410ada53 (patch)
tree8c62cd29f891b6630448bc0bb0dd3cd2b2d4dc80 /src/zjs_common.h
parente919c7120a0074a4e51d37279604c33bb3b19b84 (diff)
[common] Add flag for enabling ZJS_ASSERT even in release mode
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
Diffstat (limited to 'src/zjs_common.h')
-rw-r--r--src/zjs_common.h29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/zjs_common.h b/src/zjs_common.h
index 85a0351..d91d101 100644
--- a/src/zjs_common.h
+++ b/src/zjs_common.h
@@ -33,39 +33,40 @@
*/
char *zjs_shorten_filepath(char *filepath);
-#ifdef DEBUG_BUILD
+// enable to use asserts even in release mode, e.g. for terse debugging
+#if 0
+#define USE_ASSERT
+#endif
+#ifdef DEBUG_BUILD
int zjs_get_sec(void);
int zjs_get_ms(void);
-#define DBG_PRINT \
+#define DBG_PRINT \
ZJS_PRINT("\n%u.%3.3u %s:%d %s():\n(INFO) ", zjs_get_sec(), zjs_get_ms(), \
zjs_shorten_filepath(__FILE__), __LINE__, __func__); \
ZJS_PRINT
-
#define ERR_PRINT \
ZJS_PRINT("\n%u.%3.3u %s:%d %s():\n(ERROR) ", zjs_get_sec(), zjs_get_ms(), \
zjs_shorten_filepath(__FILE__), __LINE__, __func__); \
ZJS_PRINT
-
-#define ZJS_ASSERT(condition, str) \
- if (!(condition)) { \
- ERR_PRINT("ASSERTION FAILURE: %s\n", str); \
- do {} while (1); \
- }
-
#else // !DEBUG_BUILD
-
#define DBG_PRINT(fmt...) do {} while (0)
-
#define ERR_PRINT \
ZJS_PRINT("\n%s:%d %s():\n(ERROR) ", zjs_shorten_filepath(__FILE__), \
__LINE__, __func__); \
ZJS_PRINT
+#endif // DEBUG_BUILD
+#if defined(DEBUG_BUILD) || defined(USE_ASSERT)
+#define ZJS_ASSERT(condition, str) \
+ if (!(condition)) { \
+ ERR_PRINT("ASSERTION FAILURE: %s\n", str); \
+ do {} while (1); \
+ }
+#else
#define ZJS_ASSERT(condition, str) do {} while (0)
-
-#endif // DEBUG_BUILD
+#endif
// TODO: We should instead have a macro that changes in debug vs. release build,
// to save string space and instead print error codes or something for release.