diff options
| author | take_cheeze <[email protected]> | 2015-05-25 21:19:24 +0900 |
|---|---|---|
| committer | take_cheeze <[email protected]> | 2015-05-25 21:19:24 +0900 |
| commit | 6498d90f1be9564e75d34d94d61374fb98b7c01c (patch) | |
| tree | aad59db11c251868252062ed5683a6d89fae508f /include | |
| parent | f70905491008ec9657f706dd2183afc13d49cc10 (diff) | |
| download | mruby-6498d90f1be9564e75d34d94d61374fb98b7c01c.tar.gz mruby-6498d90f1be9564e75d34d94d61374fb98b7c01c.zip | |
Move "src/mrb_throw.h" to "include/mruby/throw.h".
Related to #2760.
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/throw.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/mruby/throw.h b/include/mruby/throw.h new file mode 100644 index 000000000..7f720d512 --- /dev/null +++ b/include/mruby/throw.h @@ -0,0 +1,41 @@ +/* +** mruby/throw.h - mruby exception throwing handler +** +** See Copyright Notice in mruby.h +*/ + +#ifndef MRB_THROW_H +#define MRB_THROW_H + +#ifdef MRB_ENABLE_CXX_EXCEPTION + +#define MRB_TRY(buf) do { try { +#define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; } +#define MRB_END_EXC(buf) } } while(0) + +#define MRB_THROW(buf) throw((buf)->impl) +typedef mrb_int mrb_jmpbuf_impl; + +#else + +#include <setjmp.h> + +#define MRB_TRY(buf) do { if (setjmp((buf)->impl) == 0) { +#define MRB_CATCH(buf) } else { +#define MRB_END_EXC(buf) } } while(0) + +#define MRB_THROW(buf) longjmp((buf)->impl, 1); +#define mrb_jmpbuf_impl jmp_buf + +#endif + +struct mrb_jmpbuf { + mrb_jmpbuf_impl impl; + +#ifdef MRB_ENABLE_CXX_EXCEPTION + static mrb_int jmpbuf_id; + mrb_jmpbuf() : impl(jmpbuf_id++) {} +#endif +}; + +#endif /* MRB_THROW_H */ |
