9#ifndef mozilla_Assertions_h
10#define mozilla_Assertions_h
12#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus)
13#define MOZ_DUMP_ASSERTION_STACK
20#ifdef MOZ_DUMP_ASSERTION_STACK
38TerminateProcess(
void* hProcess,
unsigned int uExitCode);
39__declspec(dllimport)
void* __stdcall GetCurrentProcess(
void);
47# include <android/log.h>
75# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
77# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE
79# define MOZ_STATIC_ASSERT_GLUE1(x, y) x##y
80# define MOZ_STATIC_ASSERT_GLUE(x, y) MOZ_STATIC_ASSERT_GLUE1(x, y)
81# if defined(__SUNPRO_CC)
93# define MOZ_STATIC_ASSERT(cond, reason) \
94 extern char MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)[(cond) ? 1 : -1]
95# elif defined(__COUNTER__)
110# define MOZ_STATIC_ASSERT(cond, reason) \
111 typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE
113# define MOZ_STATIC_ASSERT(cond, reason) \
114 extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE
117#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason)
119#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) static_assert(!(cond) || (expr), reason)
139 __android_log_print(ANDROID_LOG_FATAL,
"MOZ_Assert",
140 "Assertion failure: %s, at %s:%d\n",
141 aStr, aFilename, aLine);
143 fprintf(stderr,
"Assertion failure: %s, at %s:%d\n",
aStr, aFilename, aLine);
144#if defined (MOZ_DUMP_ASSERTION_STACK) && !defined(MOZILLA_XPCOMRT_API)
156 __android_log_print(ANDROID_LOG_FATAL,
"MOZ_CRASH",
157 "Hit MOZ_CRASH(%s) at %s:%d\n",
aStr, aFilename, aLine);
159 fprintf(stderr,
"Hit MOZ_CRASH(%s) at %s:%d\n",
aStr, aFilename, aLine);
160#if defined(MOZ_DUMP_ASSERTION_STACK) && !defined(MOZILLA_XPCOMRT_API)
195__declspec(noreturn) __inline
void MOZ_NoReturn() {}
198# define MOZ_REALLY_CRASH() \
201 *((volatile int*) NULL) = __LINE__; \
202 ::TerminateProcess(::GetCurrentProcess(), 3); \
206# define MOZ_REALLY_CRASH() \
209 *((volatile int*) NULL) = __LINE__; \
210 TerminateProcess(GetCurrentProcess(), 3); \
216# define MOZ_REALLY_CRASH() \
218 *((volatile int*) NULL) = __LINE__; \
222# define MOZ_REALLY_CRASH() \
224 *((volatile int*) NULL) = __LINE__; \
252# define MOZ_CRASH(...) MOZ_REALLY_CRASH()
254# define MOZ_CRASH(...) \
256 MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \
257 MOZ_REALLY_CRASH(); \
319 static const bool value =
false;
322template<
typename R,
typename...
A>
323struct IsFunction<
R(
A...)>
325 static const bool value =
true;
329struct AssertionConditionType
333 "Expected boolean assertion condition, got an array or a "
335 static_assert(!IsFunction<ValueT>::value,
336 "Expected boolean assertion condition, got a function! Did "
337 "you intend to call that function?");
339 "It's often a bad idea to assert that a floating-point number "
340 "is nonzero, because such assertions tend to intermittently "
341 "fail. Shouldn't your code gracefully handle this case instead "
342 "of asserting? Anyway, if you really want to do that, write an "
343 "explicit boolean condition, like !!x or x!=0.");
345 static const bool isValid =
true;
350# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \
351 static_assert(mozilla::detail::AssertionConditionType<decltype(x)>::isValid, \
352 "invalid assertion condition")
354# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x)
358#define MOZ_ASSERT_HELPER1(expr) \
360 MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \
361 if (MOZ_UNLIKELY(!(expr))) { \
362 MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \
363 MOZ_REALLY_CRASH(); \
367#define MOZ_ASSERT_HELPER2(expr, explain) \
369 MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \
370 if (MOZ_UNLIKELY(!(expr))) { \
371 MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \
372 MOZ_REALLY_CRASH(); \
376#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b
377#define MOZ_RELEASE_ASSERT(...) \
378 MOZ_RELEASE_ASSERT_GLUE( \
379 MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \
383# define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__)
385# define MOZ_ASSERT(...) do { } while (0)
389# define MOZ_DIAGNOSTIC_ASSERT MOZ_ASSERT
391# define MOZ_DIAGNOSTIC_ASSERT MOZ_RELEASE_ASSERT
404# define MOZ_ASSERT_IF(cond, expr) \
411# define MOZ_ASSERT_IF(cond, expr) do { } while (0)
421#if defined(__clang__) || defined(__GNUC__)
422# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable()
423#elif defined(_MSC_VER)
424# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0)
427# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort()
429# define MOZ_ASSUME_UNREACHABLE_MARKER() abort()
478#define MOZ_ASSERT_UNREACHABLE(reason) \
479 MOZ_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason)
481#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \
483 MOZ_ASSERT_UNREACHABLE(reason); \
484 MOZ_ASSUME_UNREACHABLE_MARKER(); \
494# define MOZ_ALWAYS_TRUE(expr) MOZ_ASSERT((expr))
495# define MOZ_ALWAYS_FALSE(expr) MOZ_ASSERT(!(expr))
497# define MOZ_ALWAYS_TRUE(expr) ((void)(expr))
498# define MOZ_ALWAYS_FALSE(expr) ((void)(expr))
501#undef MOZ_DUMP_ASSERTION_STACK
static MOZ_COLD MOZ_ALWAYS_INLINE void MOZ_ReportAssertionFailure(const char *aStr, const char *aFilename, int aLine) MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS
static MOZ_COLD MOZ_ALWAYS_INLINE void MOZ_ReportCrash(const char *aStr, const char *aFilename, int aLine) MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS
#define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS
#define MOZ_ALWAYS_INLINE
#define MOZ_COLD
MOZ_COLD tells the compiler that a function is "cold", meaning infrequently executed.
static void WalkTheStack(FILE *aStream)
Compares two VersionParts.
__declspec(dllexport) UINT __stdcall RestartIndexingService(MSIHANDLE)