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.
MODIFY
include/mruby/error.h
include/mruby/error.h
@@ -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);

MODIFY
src/error.c
src/error.c
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 {
+ 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 {

MODIFY
src/gc.c
src/gc.c
@@ -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;

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