summaryrefslogtreecommitdiff
path: root/upb/upb.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-05-12 11:54:34 -0700
committerJoshua Haberman <jhaberman@gmail.com>2016-05-12 11:54:34 -0700
commitfa338b70a602d9f5657528d0322535959a92d4b0 (patch)
treea7ec8b8d61a1ff3657aff99316ec51a8b81726ad /upb/upb.h
parente16ed470be7d0d459e85e1d7b43893358a625d34 (diff)
Added UPB_ASSERT() that helps avoid unused var warnings.
* Added UPB_ASSERT() that helps avoid unused var warnings. * Addressed PR comments. * Fixed assert in the JIT.
Diffstat (limited to 'upb/upb.h')
-rw-r--r--upb/upb.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/upb/upb.h b/upb/upb.h
index 1ff47de..6c7a627 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -196,10 +196,17 @@ template <int N> class InlinedEnvironment;
#define UPB_UNUSED(var) (void)var
-/* For asserting something about a variable when the variable is not used for
- * anything else. This prevents "unused variable" warnings when compiling in
- * debug mode. */
-#define UPB_ASSERT_VAR(var, predicate) UPB_UNUSED(var); assert(predicate)
+/* UPB_ASSERT(): in release mode, we use the expression without letting it be
+ * evaluated. This prevents "unused variable" warnings. */
+#ifdef NDEBUG
+#define UPB_ASSERT(expr) do {} while (false && (expr))
+#else
+#define UPB_ASSERT(expr) assert(expr)
+#endif
+
+/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
+ * exist in debug mode. This turns into regular assert. */
+#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
/* Generic function type. */
typedef void upb_func();
@@ -434,13 +441,13 @@ struct upb_alloc {
};
UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
- assert(size > 0);
+ UPB_ASSERT(size > 0);
return alloc->func(alloc, NULL, 0, size);
}
UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
size_t size) {
- assert(size > 0);
+ UPB_ASSERT(size > 0);
return alloc->func(alloc, ptr, oldsize, size);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback