* numeric.c (num_step_scan_args): turn a macro into a function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-05-07 08:05:00 +00:00
Родитель 5c5180256a
Коммит ba90ac2529
1 изменённых файлов: 33 добавлений и 28 удалений

Просмотреть файл

@ -1859,39 +1859,44 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
}
}
#define NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc) do { \
argc = rb_scan_args(argc, argv, "02:", &to, &step, &hash); \
if (!NIL_P(hash)) { \
step = rb_hash_aref(hash, sym_by); \
to = rb_hash_aref(hash, sym_to); \
} \
else { \
/* compatibility */ \
if (argc > 1 && NIL_P(step)) { \
rb_raise(rb_eTypeError, "step must be numeric"); \
} \
if (rb_equal(step, INT2FIX(0))) { \
rb_raise(rb_eArgError, "step can't be 0"); \
} \
} \
if (NIL_P(step)) { \
step = INT2FIX(1); \
} \
desc = !positive_int_p(step); \
if (NIL_P(to)) { \
to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY); \
} \
} while (0)
static int
num_step_scan_args(int argc, const VALUE *argv, VALUE *to, VALUE *step)
{
VALUE hash;
int desc;
argc = rb_scan_args(argc, argv, "02:", to, step, &hash);
if (!NIL_P(hash)) {
step = rb_hash_aref(hash, sym_by);
to = rb_hash_aref(hash, sym_to);
}
else {
/* compatibility */
if (argc > 1 && NIL_P(*step)) {
rb_raise(rb_eTypeError, "step must be numeric");
}
if (rb_equal(*step, INT2FIX(0))) {
rb_raise(rb_eArgError, "step can't be 0");
}
}
if (NIL_P(*step)) {
*step = INT2FIX(1);
}
desc = !positive_int_p(*step);
if (NIL_P(*to)) {
*to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
}
return desc;
}
static VALUE
num_step_size(VALUE from, VALUE args, VALUE eobj)
{
VALUE to, step, hash;
int desc;
VALUE to, step;
int argc = args ? RARRAY_LENINT(args) : 0;
const VALUE *argv = args ? RARRAY_CONST_PTR(args) : 0;
NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc);
num_step_scan_args(argc, argv, &to, &step);
return ruby_num_interval_step_size(from, to, step, FALSE);
}
@ -1952,12 +1957,12 @@ num_step_size(VALUE from, VALUE args, VALUE eobj)
static VALUE
num_step(int argc, VALUE *argv, VALUE from)
{
VALUE to, step, hash;
VALUE to, step;
int desc, inf;
RETURN_SIZED_ENUMERATOR(from, argc, argv, num_step_size);
NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc);
desc = num_step_scan_args(argc, argv, &to, &step);
if (RTEST(rb_num_coerce_cmp(step, INT2FIX(0), id_eq))) {
inf = 1;
}