Simplify conversion process for i in mrb_get_args()

This commit is contained in:
KOBAYASHI Shuji
2019-05-03 13:39:19 +09:00
parent 8c8e6e25ad
commit 0692f7916c
2 changed files with 8 additions and 27 deletions
+1 -23
View File
@@ -838,29 +838,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_int*);
if (i < argc) {
switch (mrb_type(ARGV[arg_i])) {
case MRB_TT_FIXNUM:
*p = mrb_fixnum(ARGV[arg_i]);
break;
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT:
{
mrb_float f = mrb_float(ARGV[arg_i]);
if (!FIXABLE_FLOAT(f)) {
mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
}
*p = (mrb_int)f;
}
break;
#endif
case MRB_TT_STRING:
mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion of String into Integer");
break;
default:
*p = mrb_fixnum(mrb_Integer(mrb, ARGV[arg_i]));
break;
}
*p = mrb_fixnum(mrb_to_int(mrb, ARGV[arg_i]));
arg_i++;
i++;
}
+7 -4
View File
@@ -37,11 +37,14 @@ end
assert('String#*', '15.2.10.5.5') do
assert_equal 'aaaaa', 'a' * 5
assert_equal '', 'a' * 0
assert_raise(ArgumentError) do
'a' * -1
end
assert_equal 'aa', 'a' * 2.1
assert_raise(ArgumentError) { 'a' * -1 }
assert_raise(RangeError) { '' * 1e30 }
assert_raise(RangeError) { '' * Float::INFINITY }
assert_raise(RangeError) { '' * Float::NAN }
assert_raise(TypeError) { 'a' * '1' }
assert_raise(TypeError) { 'a' * nil }
end
assert('String#[]', '15.2.10.5.6') do
# length of args is 1
a = 'abc'[0]