object.c: remove `mrb_convert_to_integer()' function.
And merged to `mrb_f_integer()` which is only usage of the function.
MODIFY
include/mruby.h
include/mruby.h
@@ -1249,7 +1249,6 @@ MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name);
MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
-MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base);
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_to_float(mrb_state *mrb, mrb_value val);
#endif

MODIFY
mrbgems/mruby-kernel-ext/src/kernel.c
mrbgems/mruby-kernel-ext/src/kernel.c
#include <mruby/array.h>
#include <mruby/hash.h>
#include <mruby/range.h>
+#include <mruby/string.h>
+#include <mruby/numeric.h>
#include <mruby/presym.h>
static mrb_value
@@ -107,11 +109,43 @@ mrb_f_method(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_f_integer(mrb_state *mrb, mrb_value self)
{
- mrb_value arg;
+ mrb_value val, tmp;
mrb_int base = 0;
- mrb_get_args(mrb, "o|i", &arg, &base);
- return mrb_convert_to_integer(mrb, arg, base);
+ mrb_get_args(mrb, "o|i", &val, &base);
+ if (mrb_nil_p(val)) {
+ if (base != 0) goto arg_error;
+ mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Integer");
+ }
+ switch (mrb_type(val)) {
+#ifndef MRB_NO_FLOAT
+ case MRB_TT_FLOAT:
+ if (base != 0) goto arg_error;
+ return mrb_float_to_integer(mrb, val);
+#endif
+
+ case MRB_TT_INTEGER:
+ if (base != 0) goto arg_error;
+ return val;
+
+ case MRB_TT_STRING:
+ string_conv:
+ return mrb_str_to_inum(mrb, val, base, TRUE);
+
+ default:
+ break;
+ }
+ if (base != 0) {
+ tmp = mrb_obj_as_string(mrb, val);
+ if (mrb_string_p(tmp)) {
+ val = tmp;
+ goto string_conv;
+ }
+arg_error:
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "base specified for non string value");
+ }
+ /* to raise TypeError */
+ return mrb_to_int(mrb, val);
}
#ifndef MRB_NO_FLOAT

MODIFY
src/object.c
src/object.c
@@ -495,46 +495,6 @@ mrb_to_int(mrb_state *mrb, mrb_value val)
return val;
}
-MRB_API mrb_value
-mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base)
-{
- mrb_value tmp;
-
- if (mrb_nil_p(val)) {
- if (base != 0) goto arg_error;
- mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Integer");
- }
- switch (mrb_type(val)) {
-#ifndef MRB_NO_FLOAT
- case MRB_TT_FLOAT:
- if (base != 0) goto arg_error;
- return mrb_float_to_integer(mrb, val);
-#endif
-
- case MRB_TT_INTEGER:
- if (base != 0) goto arg_error;
- return val;
-
- case MRB_TT_STRING:
- string_conv:
- return mrb_str_to_inum(mrb, val, base, TRUE);
-
- default:
- break;
- }
- if (base != 0) {
- tmp = mrb_check_string_type(mrb, val);
- if (!mrb_nil_p(tmp)) {
- val = tmp;
- goto string_conv;
- }
-arg_error:
- mrb_raise(mrb, E_ARGUMENT_ERROR, "base specified for non string value");
- }
- /* to raise TypeError */
- return mrb_to_int(mrb, val);
-}
-
#ifndef MRB_NO_FLOAT
MRB_API mrb_value
mrb_to_float(mrb_state *mrb, mrb_value val)

object.c: remove `mrb_convert_to_integer()' function.

And merged to `mrb_f_integer()` which is only usage of the function.