From a149a724b52b4f3f9b4017020535f6be9f843fbe Mon Sep 17 00:00:00 2001 From: "jwatt%jwatt.org" Date: Mon, 2 Apr 2007 09:05:50 +0000 Subject: [PATCH] Fixing bug 375985. Add compile time assertions to NSPR. r=wtchang@gmail.com --- nsprpub/pr/include/prerror.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nsprpub/pr/include/prerror.h b/nsprpub/pr/include/prerror.h index cf94872e306..af2cb9164ab 100644 --- a/nsprpub/pr/include/prerror.h +++ b/nsprpub/pr/include/prerror.h @@ -48,6 +48,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