Jeff Walden wrote:
> I also think we benefit greatly from having One Way To Perform An
> Assertion. New contributors shouldn't have to ask how to perform
> assertions in each module they touch. They don't in WebKit -- it's
> just ASSERT everywhere. (Port-specific code may differ, but that's
> much more third-party than any non-imported code we have.) And I can't
> see the value in having custom ways to say, "if this condition wasn't
> true, throw up a debugger".
I agree, which is why I think it must be PR_ASSERT, because I don't see NSPR or NSS (C libraries) changing to depend on mfbt (a C++ library), ever. (Not due to my preferences, but due to others').
> static_assert's a C++11 keyword and a new C11 (next-gen C) <assert.h>
> macro. Not defining it in C++11 compilers, and tiptoeing around
> <assert.h>'s potential definition, seems pretty messy. (Especially
> given compiler support won't advance uniformly.) It seems easiest to
> sidestep the complexity entirely.
Isn't this exactly the same kind of problem we had for stdint.h? And, isn't the solution the same or similar? Plus, why do we stab ourselves in the faces every day with the horribleness of autoconf, if not for this type of problem?
* For C++, you already do the messy work of detecting the availability of static_assert.
* In C11, static_assert is always a macro, so you can:
#if !defined(__cplusplus)
# include <assert.h>
# ifndef static_assert
# define static_assert ...
# endif
#else
# <do what you are already doing, but
# #define static_assert instead of MOZ_STATIC_ASSERT>
#endif
Also, I have found PR_STATIC_ASSERT's signature to be *MUCH* more convenient than static_assert's signature, for the same reason that MOZ_ASSERT's signature is usually more convenient than NS_ASSERTION: the second "reason" string parameter is usually unhelpful. Rewriting code that uses PR_STATIC_ASSERT to use MOZ_STATIC_ASSERT, as proposed in bug 712936, would often just make the code harder to read.
> someone who understands these win32 nuances, go ahead. (The comment
> suggests JS may have originally done what NSPR did, then encountered
> the DebugBreak issue, then fixed JS without fixing NSPR. More evidence
> for fewer implementations == better.)
Yes, this is my exactly my point.
> SpiderMonkey doesn't depend on NSPR in some configurations, so it's
> not possible to use PR_Assert.
Interesting, I did not know that. So we have the case where Spidermonkey can't use PR_Assert, and NSPR and NSS cannot use JS_Assert, even though they do the exact same thing.
Or, rather, they *should* be doing the same thing. I filed bug 713631 to improve the NSPR PR_Assert on Windows.
> Someday we'll just create a micro-library for mfbt and have JS/Gecko
> link against that (in whatever the most efficient way is -- I really
> don't know much about linking) and have mfbt not depend on JS at all.
We already have such a micro-library: libplc, which is part of NSPR, and which is only 22kb (on Windows). I think it would be good to move the parts of mfbt that also apply to C (e.g. static_assert, a good implementation of JS_Assert/PR_Assert, and the stdint support) to libplc, so that NSS and NSPR can benefit from them. Otherwise, work like this needs to be duplicated between mfbt and NSPR.
- Brian