mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Reorganize the struct RException::mesg member
There is no need to limit the type to `struct RString`. Also, the `MRB_EXC_MESG_STRING_FLAG` flag can be eliminated by checking if `struct RException::mesg` is `NULL` or not. ref. #2485
This commit is contained in:
@@ -17,11 +17,10 @@ MRB_BEGIN_DECL
|
||||
struct RException {
|
||||
MRB_OBJECT_HEADER;
|
||||
struct iv_tbl *iv;
|
||||
struct RString *mesg;
|
||||
struct RObject *mesg; // NULL or probably RString
|
||||
};
|
||||
|
||||
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
|
||||
#define MRB_EXC_MESG_STRING_FLAG 0x100
|
||||
|
||||
MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
|
||||
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
|
||||
|
||||
+6
-11
@@ -20,26 +20,21 @@
|
||||
void
|
||||
mrb_exc_mesg_set(mrb_state *mrb, struct RException *exc, mrb_value mesg)
|
||||
{
|
||||
if (mrb_string_p(mesg)) {
|
||||
exc->flags |= MRB_EXC_MESG_STRING_FLAG;
|
||||
exc->mesg = RSTRING(mesg);
|
||||
if (!mrb_immediate_p(mesg)) {
|
||||
exc->mesg = mrb_obj_ptr(mesg);
|
||||
mrb_field_write_barrier_value(mrb, (struct RBasic*)exc, mesg);
|
||||
mrb_iv_remove(mrb, mrb_obj_value(exc), MRB_SYM(mesg));
|
||||
}
|
||||
else {
|
||||
exc->flags &= ~MRB_EXC_MESG_STRING_FLAG;
|
||||
if (mrb_nil_p(mesg)) {
|
||||
exc->mesg = 0;
|
||||
}
|
||||
else {
|
||||
mrb_obj_iv_set(mrb, (struct RObject*)exc, MRB_SYM(mesg), mesg);
|
||||
}
|
||||
exc->mesg = NULL;
|
||||
mrb_obj_iv_set(mrb, (struct RObject*)exc, MRB_SYM(mesg), mesg);
|
||||
}
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_exc_mesg_get(mrb_state *mrb, struct RException *exc)
|
||||
{
|
||||
if ((exc->flags & MRB_EXC_MESG_STRING_FLAG) != 0) {
|
||||
if (exc->mesg) {
|
||||
return mrb_obj_value(exc->mesg);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -760,7 +760,7 @@ gc_mark_children(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
|
||||
|
||||
case MRB_TT_EXCEPTION:
|
||||
mrb_gc_mark_iv(mrb, (struct RObject*)obj);
|
||||
if ((obj->flags & MRB_EXC_MESG_STRING_FLAG) != 0) {
|
||||
if (((struct RException*)obj)->mesg) {
|
||||
mrb_gc_mark(mrb, (struct RBasic*)((struct RException*)obj)->mesg);
|
||||
}
|
||||
break;
|
||||
@@ -1049,7 +1049,7 @@ gc_gray_counts(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
|
||||
|
||||
case MRB_TT_EXCEPTION:
|
||||
children += mrb_gc_mark_iv_size(mrb, (struct RObject*)obj);
|
||||
if ((obj->flags & MRB_EXC_MESG_STRING_FLAG) != 0) {
|
||||
if (((struct RException*)obj)->mesg) {
|
||||
children++;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user