mruby  2.0.1
mruby is the lightweight implementation of the Ruby language
throw.h
Go to the documentation of this file.
1 
7 #ifndef MRB_THROW_H
8 #define MRB_THROW_H
9 
10 #if defined(MRB_ENABLE_CXX_ABI)
11 # if !defined(__cplusplus)
12 # error Trying to use C++ exception handling in C code
13 # endif
14 #endif
15 
16 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
17 
18 #define MRB_TRY(buf) try {
19 #define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; }
20 #define MRB_END_EXC(buf) }
21 
22 #define MRB_THROW(buf) throw((buf)->impl)
23 typedef mrb_int mrb_jmpbuf_impl;
24 
25 #else
26 
27 #include <setjmp.h>
28 
29 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
30 #define MRB_SETJMP _setjmp
31 #define MRB_LONGJMP _longjmp
32 #else
33 #define MRB_SETJMP setjmp
34 #define MRB_LONGJMP longjmp
35 #endif
36 
37 #define MRB_TRY(buf) if (MRB_SETJMP((buf)->impl) == 0) {
38 #define MRB_CATCH(buf) } else {
39 #define MRB_END_EXC(buf) }
40 
41 #define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
42 #define mrb_jmpbuf_impl jmp_buf
43 
44 #endif
45 
46 struct mrb_jmpbuf {
47  mrb_jmpbuf_impl impl;
48 
49 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
50  static mrb_int jmpbuf_id;
51  mrb_jmpbuf() : impl(jmpbuf_id++) {}
52 #endif
53 };
54 
55 #endif /* MRB_THROW_H */
Definition: throw.h:46