object.c: avoid implicit `to_i` and `to_f` calls.

mruby have removed `to_int` implicit conversion, so `mrb_to_integer`
should not call `to_i` for conversion.
parent 41e8b210
...@@ -487,17 +487,13 @@ mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c) ...@@ -487,17 +487,13 @@ mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c)
MRB_API mrb_value MRB_API mrb_value
mrb_to_integer(mrb_state *mrb, mrb_value val) mrb_to_integer(mrb_state *mrb, mrb_value val)
{ {
if (!mrb_integer_p(val)) { if (!mrb_integer_p(val)) {
#ifndef MRB_NO_FLOAT #ifndef MRB_NO_FLOAT
if (mrb_float_p(val)) { if (mrb_float_p(val)) {
return mrb_float_to_integer(mrb, val); return mrb_float_to_integer(mrb, val);
} }
#endif #endif
if (mrb_string_p(val)) { mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be converted to Integer", val);
mrb_raise(mrb, E_TYPE_ERROR, "can't convert String to Integer");
}
return mrb_type_convert(mrb, val, MRB_TT_INTEGER, MRB_SYM(to_i));
} }
return val; return val;
} }
...@@ -520,7 +516,9 @@ mrb_to_float(mrb_state *mrb, mrb_value val) ...@@ -520,7 +516,9 @@ mrb_to_float(mrb_state *mrb, mrb_value val)
return mrb_float_value(mrb, mrb_str_to_dbl(mrb, val, TRUE)); return mrb_float_value(mrb, mrb_str_to_dbl(mrb, val, TRUE));
default: default:
return mrb_type_convert(mrb, val, MRB_TT_FLOAT, MRB_SYM(to_f)); mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be converted to Float", val);
/* not reached */
return val;
} }
} }
#endif #endif
......
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