~ubuntu-branches/ubuntu/quantal/lightning-extension/quantal

« back to all changes in this revision

Viewing changes to mozilla/mfbt/Assertions.h

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-06-20 23:50:32 UTC
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20120620235032-haecscdskaopvm10
Tags: upstream-1.6~b1+build1
ImportĀ upstreamĀ versionĀ 1.6~b1+build1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
2
 * vim: set ts=8 sw=4 et tw=99 ft=cpp:
3
3
 *
4
4
 * ***** BEGIN LICENSE BLOCK *****
46
46
#include "mozilla/Attributes.h"
47
47
#include "mozilla/Types.h"
48
48
 
 
49
#include <stdio.h>
 
50
#include <stdlib.h>
 
51
#ifndef WIN32
 
52
#  include <signal.h>
 
53
#endif
 
54
#ifdef ANDROID
 
55
#  include <android/log.h>
 
56
#endif
 
57
 
49
58
/*
50
59
 * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time*.  This
51
60
 * can be useful when you make certain assumptions about what must hold for
131
140
extern "C" {
132
141
#endif
133
142
 
134
 
extern MFBT_API(void)
135
 
MOZ_Crash(void);
 
143
#if defined(WIN32)
 
144
   /*
 
145
    * We used to call DebugBreak() on Windows, but amazingly, it causes
 
146
    * the MSVS 2010 debugger not to be able to recover a call stack.
 
147
    */
 
148
#  define MOZ_CRASH() \
 
149
     do { \
 
150
       *((volatile int *) NULL) = 123; \
 
151
       exit(3); \
 
152
     } while (0)
 
153
#elif defined(ANDROID)
 
154
   /*
 
155
    * On Android, raise(SIGABRT) is handled asynchronously. Seg fault now
 
156
    * so we crash immediately and capture the current call stack. We need
 
157
    * to specifically use the global namespace in the C++ case.
 
158
    */
 
159
#  ifdef __cplusplus
 
160
#    define MOZ_CRASH() \
 
161
       do { \
 
162
         *((volatile int *) NULL) = 123; \
 
163
         ::abort(); \
 
164
       } while (0)
 
165
#  else
 
166
#    define MOZ_CRASH() \
 
167
       do { \
 
168
         *((volatile int *) NULL) = 123; \
 
169
         abort(); \
 
170
       } while (0)
 
171
#  endif
 
172
#elif defined(__APPLE__)
 
173
   /*
 
174
    * On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
 
175
    * trapped.
 
176
    */
 
177
#  define MOZ_CRASH() \
 
178
     do { \
 
179
       *((volatile int *) NULL) = 123; \
 
180
       raise(SIGABRT);  /* In case above statement gets nixed by the optimizer. */ \
 
181
     } while (0)
 
182
#else
 
183
#  define MOZ_CRASH() \
 
184
     do { \
 
185
       raise(SIGABRT);  /* To continue from here in GDB: "signal 0". */ \
 
186
     } while (0)
 
187
#endif
 
188
 
136
189
 
137
190
extern MFBT_API(void)
138
191
MOZ_Assert(const char* s, const char* file, int ln);
139
192
 
 
193
static MOZ_ALWAYS_INLINE void
 
194
MOZ_OutputAssertMessage(const char* s, const char *file, int ln)
 
195
{
 
196
#ifdef ANDROID
 
197
  __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert",
 
198
                      "Assertion failure: %s, at %s:%d\n", s, file, ln);
 
199
#else
 
200
  fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
 
201
  fflush(stderr);
 
202
#endif
 
203
}
 
204
 
140
205
#ifdef __cplusplus
141
206
} /* extern "C" */
142
207
#endif
176
241
#ifdef DEBUG
177
242
   /* First the single-argument form. */
178
243
#  define MOZ_ASSERT_HELPER1(expr) \
179
 
     ((expr) ? ((void)0) : MOZ_Assert(#expr, __FILE__, __LINE__))
 
244
     do { \
 
245
       if (!(expr)) { \
 
246
         MOZ_OutputAssertMessage(#expr, __FILE__, __LINE__); \
 
247
         MOZ_CRASH(); \
 
248
       } \
 
249
     } while (0)
180
250
   /* Now the two-argument form. */
181
251
#  define MOZ_ASSERT_HELPER2(expr, explain) \
182
 
     ((expr) ? ((void)0) : MOZ_Assert(#expr " (" explain ")", __FILE__, __LINE__))
 
252
     do { \
 
253
       if (!(expr)) { \
 
254
         MOZ_OutputAssertMessage(#expr " (" explain ")", __FILE__, __LINE__); \
 
255
         MOZ_CRASH(); \
 
256
       } \
 
257
     } while (0)
183
258
   /* And now, helper macrology up the wazoo. */
184
259
   /*
185
260
    * Count the number of arguments passed to MOZ_ASSERT, very carefully
205
280
     MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \
206
281
                     (__VA_ARGS__))
207
282
#else
208
 
#  define MOZ_ASSERT(...) ((void)0)
 
283
#  define MOZ_ASSERT(...) do { } while(0)
209
284
#endif /* DEBUG */
210
285
 
211
286
/*
218
293
 * designed to catch bugs during debugging, not "in the field".
219
294
 */
220
295
#ifdef DEBUG
221
 
#  define MOZ_ASSERT_IF(cond, expr)  ((cond) ? MOZ_ASSERT(expr) : ((void)0))
 
296
#  define MOZ_ASSERT_IF(cond, expr) \
 
297
     do { \
 
298
       if (cond) \
 
299
         MOZ_ASSERT(expr); \
 
300
     } while (0)
222
301
#else
223
 
#  define MOZ_ASSERT_IF(cond, expr)  ((void)0)
 
302
#  define MOZ_ASSERT_IF(cond, expr)  do { } while (0)
224
303
#endif
225
304
 
226
305
/* MOZ_NOT_REACHED_MARKER() expands (in compilers which support it) to an