Use `MRB_SYM()` for error class retrieval; ref #5277

Note that `MRB_SYM()` is only available when `mruby/presym.h` is
included. Use `mrb_intern_lit()` otherwise.
parent 17ecf145
......@@ -1303,6 +1303,13 @@ MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap);
+ those E_* macros requires mrb_state* variable named mrb.
+ exception objects obtained from those macros are local to mrb
*/
#ifdef MRB_SYM
/* mruby/presym.h is included earlier */
# define MRB_E_SYM(sym) MRB_SYM(sym)
#else
# define MRB_E_SYM(sym) mrb_intern_lit(mrb, #sym)
#endif
#define E_RUNTIME_ERROR mrb_exc_get_id(mrb, mrb_intern_lit(mrb, "RuntimeError"))
#define E_TYPE_ERROR mrb_exc_get_id(mrb, mrb_intern_lit(mrb, "TypeError"))
#define E_ZERODIV_ERROR mrb_exc_get_id(mrb, mrb_intern_lit(mrb, "ZeroDivisionError"))
......
......@@ -38,4 +38,8 @@ enum mruby_presym {
static const mrb_sym name[] = {__VA_ARGS__}; \
static void init_##name(mrb_state *mrb) {}
/* use MRB_SYM() for E_RUNTIME_ERROR etc. */
# undef MRB_E_SYM
# define MRB_E_SYM(sym) MRB_SYM(sym)
#endif /* MRUBY_PRESYM_ENABLE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment