Commit f9076230 authored by take_cheeze's avatar take_cheeze

Fix crash in method call in `ObjectSpace.each_object` block.

* Filter `MRB_TT_ENV` and `MRB_TT_ICLASS`.
* Set `mrb->string_class` in `mrb_init_exception` instead.
parent 919af617
......@@ -119,6 +119,13 @@ os_each_object_cb(mrb_state *mrb, struct RBasic *obj, void *ud)
return;
}
/* filter internal objects */
switch (obj->tt) {
case MRB_TT_ENV:
case MRB_TT_ICLASS:
return;
}
/* filter class kind if target module defined */
if (d->target_module && !mrb_obj_is_kind_of(mrb, mrb_obj_value(obj), d->target_module)) {
return;
......
......@@ -54,3 +54,7 @@ assert('ObjectSpace.each_object') do
assert_equal arys.length, arys_count
assert_true arys.length < objs.length
end
assert 'Check class pointer of ObjectSpace.each_object.' do
ObjectSpace.each_object { |obj| !obj }
end
......@@ -91,15 +91,10 @@ static mrb_value
exc_to_s(mrb_state *mrb, mrb_value exc)
{
mrb_value mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
struct RObject *p;
if (!mrb_string_p(mesg)) {
return mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc));
}
p = mrb_obj_ptr(mesg);
if (!p->c) {
p->c = mrb->string_class;
}
return mesg;
}
......@@ -441,6 +436,9 @@ mrb_init_exception(mrb_state *mrb)
{
struct RClass *exception, *runtime_error, *script_error;
/* initialize mrb->string_class before creating RString object for nomem_err */
mrb->string_class = mrb_define_class(mrb, "String", mrb->object_class);
mrb->eException_class = exception = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */
mrb_define_class_method(mrb, exception, "exception", mrb_instance_new, MRB_ARGS_ANY());
mrb_define_method(mrb, exception, "exception", exc_exception, MRB_ARGS_ANY());
......
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