114
114
#elif __APPLE__ && __MACH__
115
115
#define thread_local __thread
116
116
#else /* C11 and newer define thread_local in threads.h */
117
+ #undef HAS_C11_THREADS
118
+ #define HAS_C11_THREADS 1
117
119
#include <threads.h>
118
120
#endif
119
121
#elif defined(__cplusplus ) /* Compiling as C++ Language */
127
129
#endif
128
130
#else /* In C++ >= 11, thread_local in a builtin keyword */
129
131
/* Don't do anything */
132
+ #undef HAS_C11_THREADS
133
+ #define HAS_C11_THREADS 1
130
134
#endif
131
135
#endif
132
136
#endif
@@ -215,7 +219,24 @@ enum {
215
219
#define rethrow () \
216
220
ex_throw(ex_err.ex, ex_err.file, ex_err.line, ex_err.function, ex_err.panic)
217
221
222
+ #define ex_throw_loc (E , F , L , C ) \
223
+ do \
224
+ { \
225
+ C_API const char EX_NAME(E)[]; \
226
+ ex_throw(EX_NAME(E), F, L, C, NULL); \
227
+ } while (0)
228
+
229
+ /* An macro that stops the ordinary flow of control and begins panicking,
230
+ throws an exception of given message. */
231
+ #define raii_panic (message ) \
232
+ do \
233
+ { \
234
+ C_API const char EX_NAME(panic)[]; \
235
+ ex_throw(EX_NAME(panic), __FILE__, __LINE__, __FUNCTION__, (message)); \
236
+ } while (0)
237
+
218
238
#ifdef _WIN32
239
+ #define throw (E ) raii_panic(EX_STR(E))
219
240
#define ex_signal_block (ctrl ) \
220
241
CRITICAL_SECTION ctrl##__FUNCTION__; \
221
242
InitializeCriticalSection(&ctrl##__FUNCTION__); \
@@ -225,29 +246,31 @@ enum {
225
246
LeaveCriticalSection(&ctrl##__FUNCTION__); \
226
247
DeleteCriticalSection(&ctrl##__FUNCTION__);
227
248
228
- #define ex_try \
229
- { \
230
- /* local context */ \
231
- ex_context_t ex_err ; \
232
- if (!ex_context ) \
233
- ex_init (); \
234
- ex_err .next = ex_context ; \
235
- ex_err .stack = 0 ; \
236
- ex_err .ex = 0 ; \
237
- ex_err .unstack = 0 ; \
238
- /* global context updated */ \
239
- ex_context = & ex_err ; \
240
- /* save jump location */ \
241
- ex_err .state = ex_setjmp (ex_err .buf ); \
242
- __try \
243
- { \
249
+ #define ex_try \
250
+ { \
251
+ if (!exception_signal_set) \
252
+ ex_signal_setup(); \
253
+ /* local context */ \
254
+ ex_context_t ex_err ; \
255
+ if (!ex_context ) \
256
+ ex_init (); \
257
+ ex_err .next = ex_context ; \
258
+ ex_err .stack = 0 ; \
259
+ ex_err .ex = 0 ; \
260
+ ex_err .unstack = 0 ; \
261
+ /* global context updated */ \
262
+ ex_context = & ex_err ; \
263
+ /* save jump location */ \
264
+ ex_err .state = ex_setjmp (ex_err .buf ); \
265
+ __try \
266
+ { \
244
267
if (ex_err .state == ex_try_st ) {
245
268
246
- #define ex_catch (E ) \
247
- } \
248
- } __except(catch_seh(E , GetExceptionCode(), GetExceptionInformation())) { \
269
+ #define ex_catch (E ) \
270
+ } \
271
+ } __except(catch_seh(EX_STR(E) , GetExceptionCode(), GetExceptionInformation())) { \
249
272
if (ex_err.state == ex_throw_st) { \
250
- EX_MAKE(); \
273
+ EX_MAKE(); \
251
274
ex_err.state = ex_catch_st;
252
275
253
276
#define ex_catch_any \
@@ -298,23 +321,27 @@ enum {
298
321
#define ex_signal_unblock (ctrl ) \
299
322
pthread_sigmask(SIG_SETMASK, &ctrl_all##__FUNCTION__, NULL);
300
323
301
- #define ex_try \
302
- { \
303
- /* local context */ \
304
- ex_context_t ex_err ; \
305
- if (!ex_context ) \
306
- ex_init (); \
307
- ex_err .next = ex_context ; \
308
- ex_err .stack = 0 ; \
309
- ex_err .ex = 0 ; \
310
- ex_err .unstack = 0 ; \
311
- /* global context updated */ \
312
- ex_context = & ex_err ; \
313
- /* save jump location */ \
314
- ex_err .state = ex_setjmp (ex_err .buf ); \
315
- if (ex_err .state == ex_try_st ) \
316
- { \
317
- {
324
+ #define throw (E ) \
325
+ ex_throw_loc(E, __FILE__, __LINE__, __FUNCTION__)
326
+ #define ex_try \
327
+ { \
328
+ if (!exception_signal_set) \
329
+ ex_signal_setup(); \
330
+ /* local context */ \
331
+ ex_context_t ex_err ; \
332
+ if (!ex_context ) \
333
+ ex_init (); \
334
+ ex_err .next = ex_context ; \
335
+ ex_err .stack = 0 ; \
336
+ ex_err .ex = 0 ; \
337
+ ex_err .unstack = 0 ; \
338
+ /* global context updated */ \
339
+ ex_context = & ex_err ; \
340
+ /* save jump location */ \
341
+ ex_err .state = ex_setjmp (ex_err .buf ); \
342
+ if (ex_err .state == ex_try_st ) \
343
+ { \
344
+ {
318
345
319
346
#define ex_catch_any \
320
347
} \
@@ -357,32 +384,13 @@ enum {
357
384
} \
358
385
if (ex_err.state == ex_throw_st) \
359
386
{ \
360
- C_API const char EX_NAME(E)[]; \
387
+ C_API const char EX_NAME(E)[]; \
361
388
if (ex_err.ex == EX_NAME(E)) \
362
389
{ \
363
390
EX_MAKE(); \
364
391
ex_err.state = ex_catch_st;
365
392
#endif
366
393
367
- #define ex_throw_loc (E , F , L , C ) \
368
- do \
369
- { \
370
- C_API const char EX_NAME(E)[]; \
371
- ex_throw(EX_NAME(E), F, L, C, NULL); \
372
- } while (0)
373
-
374
- #define throw (E ) \
375
- ex_throw_loc(E, __FILE__, __LINE__, __FUNCTION__)
376
-
377
- /* An macro that stops the ordinary flow of control and begins panicking,
378
- throws an exception of given message. */
379
- #define raii_panic (message ) \
380
- do \
381
- { \
382
- C_API const char EX_NAME(panic)[]; \
383
- ex_throw(EX_NAME(panic), __FILE__, __LINE__, __FUNCTION__, (message)); \
384
- } while (0)
385
-
386
394
/* types
387
395
*/
388
396
0 commit comments