diff options
Diffstat (limited to 'src/error.c')
| -rw-r--r-- | src/error.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/error.c b/src/error.c index 9fc6fe468..2f893a382 100644 --- a/src/error.c +++ b/src/error.c @@ -21,15 +21,22 @@ static void exc_mesg_set(mrb_state *mrb, struct RException *exc, mrb_value mesg) { - exc->flags |= MRB_EXC_MESG_INIT_FLAG; - exc->mesg = mesg; - mrb_field_write_barrier_value(mrb, (struct RBasic*)exc, mesg); + if (mrb_string_p(mesg)) { + exc->flags |= MRB_EXC_MESG_STRING_FLAG; + exc->mesg = RSTRING(mesg); + mrb_field_write_barrier_value(mrb, (struct RBasic*)exc, mesg); + } + else if (!mrb_nil_p(mesg)) { + exc->flags &= ~MRB_EXC_MESG_STRING_FLAG; + mrb_obj_iv_set(mrb, (struct RObject*)exc, mrb_intern_lit(mrb, "mesg"), mesg); + } } static mrb_value exc_mesg_get(mrb_state *mrb, struct RException *exc) { - return (exc->flags & MRB_EXC_MESG_INIT_FLAG) != 0 ? exc->mesg : mrb_nil_value(); + return (exc->flags & MRB_EXC_MESG_STRING_FLAG) != 0 + ? mrb_obj_value(exc->mesg) : mrb_obj_iv_get(mrb, (struct RObject*)exc, mrb_intern_lit(mrb, "mesg")); } mrb_value |
