mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+9
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user