Commit f77fb11f authored by take_cheeze's avatar take_cheeze

Use RString in `mesg` instead.

parent e926b532
...@@ -14,11 +14,11 @@ extern "C" { ...@@ -14,11 +14,11 @@ extern "C" {
struct RException { struct RException {
MRB_OBJECT_HEADER; MRB_OBJECT_HEADER;
struct iv_tbl *iv; struct iv_tbl *iv;
mrb_value mesg; struct RString *mesg;
}; };
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v)) #define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
#define MRB_EXC_MESG_INIT_FLAG 0x100 #define MRB_EXC_MESG_STRING_FLAG 0x100
void mrb_sys_fail(mrb_state *mrb, const char *mesg); void mrb_sys_fail(mrb_state *mrb, const char *mesg);
mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str); mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
......
...@@ -21,15 +21,22 @@ ...@@ -21,15 +21,22 @@
static void static void
exc_mesg_set(mrb_state *mrb, struct RException *exc, mrb_value mesg) exc_mesg_set(mrb_state *mrb, struct RException *exc, mrb_value mesg)
{ {
exc->flags |= MRB_EXC_MESG_INIT_FLAG; if (mrb_string_p(mesg)) {
exc->mesg = mesg; exc->flags |= MRB_EXC_MESG_STRING_FLAG;
exc->mesg = RSTRING(mesg);
mrb_field_write_barrier_value(mrb, (struct RBasic*)exc, 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 static mrb_value
exc_mesg_get(mrb_state *mrb, struct RException *exc) 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 mrb_value
......
...@@ -582,8 +582,8 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj) ...@@ -582,8 +582,8 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
case MRB_TT_EXCEPTION: case MRB_TT_EXCEPTION:
mrb_gc_mark_iv(mrb, (struct RObject*)obj); mrb_gc_mark_iv(mrb, (struct RObject*)obj);
if ((obj->flags & MRB_EXC_MESG_INIT_FLAG) != 0) { if ((obj->flags & MRB_EXC_MESG_STRING_FLAG) != 0) {
mrb_gc_mark_value(mrb, ((struct RException*)obj)->mesg); mrb_gc_mark(mrb, (struct RBasic*)((struct RException*)obj)->mesg);
} }
break; break;
...@@ -808,7 +808,7 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj) ...@@ -808,7 +808,7 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj)
case MRB_TT_EXCEPTION: case MRB_TT_EXCEPTION:
children += mrb_gc_mark_iv_size(mrb, (struct RObject*)obj); children += mrb_gc_mark_iv_size(mrb, (struct RObject*)obj);
if ((obj->flags & MRB_EXC_MESG_INIT_FLAG) != 0) { if ((obj->flags & MRB_EXC_MESG_STRING_FLAG) != 0) {
children++; children++;
} }
break; break;
......
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