summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwatt%jwatt.org <devnull@localhost>2007-04-02 09:05:50 +0000
committerjwatt%jwatt.org <devnull@localhost>2007-04-02 09:05:50 +0000
commit55caee49e19b843a679bf0380bcd04ddd417426f (patch)
treef6e29fa5aa50f238e922c15c5782f611aef37d88
parent806ee4140c48ae151467977ffd121c2b1aeed335 (diff)
downloadnspr-hg-55caee49e19b843a679bf0380bcd04ddd417426f.tar.gz
Fixing bug 375985. Add compile time assertions to NSPR. r=wtchang@gmail.com
-rw-r--r--pr/include/prerror.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/pr/include/prerror.h b/pr/include/prerror.h
index cf94872e..af2cb916 100644
--- a/pr/include/prerror.h
+++ b/pr/include/prerror.h
@@ -49,6 +49,21 @@ typedef PRInt32 PRErrorCode;
#include "prerr.h"
/*
+** Compile-time assert. "condition" must be a constant expression.
+** The macro should be used only once per source line in places where
+** a "typedef" declaration is allowed.
+** For stringification of the line numbers where the macro is used we need some
+** macro indirection. IMPL is required to get macro-expansion of __LINE__ to
+** its integer value so that IMPL2 will stringify the number, not "__LINE__".
+*/
+#define PR_STATIC_ASSERT(condition) \
+ PR_STATIC_ASSERT_IMPL(condition, __LINE__)
+#define PR_STATIC_ASSERT_IMPL(condition, line) \
+ PR_STATIC_ASSERT_IMPL2(condition, line)
+#define PR_STATIC_ASSERT_IMPL2(condition, line) \
+ typedef int pr_static_assert_line_##line[(condition) ? 1 : -1]
+
+/*
** Set error will preserve an error condition within a thread context.
** The values stored are the NSPR (platform independent) translation of
** the error. Also, if available, the platform specific oserror is stored.