Remove implicit conversion using to_str method; fix #3854

We have added internal convenience method `__to_str` which
does string type check.

The issue #3854 was fixed but fundamental flaw of lack of stack
depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA`
for workaround.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2018-09-19 21:51:53 +09:00
parent afca99a40b
commit ff08856fe3
13 changed files with 60 additions and 114 deletions
+9 -2
View File
@@ -504,10 +504,17 @@ check_type(mrb_state *mrb, mrb_value val, enum mrb_vtype t, const char *c, const
return tmp;
}
#define CHECK_TYPE(mrb, val, t, c) do { \
if (mrb_type(val) != (t)) {\
mrb_raisef(mrb, E_TYPE_ERROR, "expected %S", mrb_str_new_lit(mrb, c));\
}\
} while (0)
static mrb_value
to_str(mrb_state *mrb, mrb_value val)
{
return check_type(mrb, val, MRB_TT_STRING, "String", "to_str");
CHECK_TYPE(mrb, val, MRB_TT_STRING, "String");
return val;
}
static mrb_value
@@ -1972,7 +1979,7 @@ mrb_mod_const_get(mrb_state *mrb, mrb_value mod)
}
/* const get with class path string */
path = mrb_string_type(mrb, path);
path = mrb_ensure_string_type(mrb, path);
ptr = RSTRING_PTR(path);
len = RSTRING_LEN(path);
off = 0;