Prohibit mixture of posarg and nextarg; ref #3347

parent 9781f7f0
...@@ -136,29 +136,62 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) ...@@ -136,29 +136,62 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
blen += (l);\ blen += (l);\
} while (0) } while (0)
#define GETARG() (!mrb_undef_p(nextvalue) ? nextvalue : \ static void
posarg == -1 ? \ check_next_arg(mrb_state *mrb, int posarg, int nextarg)
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with numbered", mrb_fixnum_value(nextarg)), mrb_undef_value()) : \ {
posarg == -2 ? \ switch (posarg) {
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with named", mrb_fixnum_value(nextarg)), mrb_undef_value()) : \ case -1:
mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with numbered", mrb_fixnum_value(nextarg));
break;
case -2:
mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with named", mrb_fixnum_value(nextarg));
break;
default:
break;
}
}
static void
check_pos_arg(mrb_state *mrb, int posarg, int n)
{
if (posarg > 0) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after unnumbered(%S)", mrb_fixnum_value(n));
}
if (posarg == -2) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after named", mrb_fixnum_value(n));
}
if (n < 1) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid index - %S$", mrb_fixnum_value(n));
}
}
static void
check_name_arg(mrb_state *mrb, int posarg, const char *name, int len)
{
if (posarg > 0) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after unnumbered(%S)",
mrb_str_new(mrb, (name), (len)), mrb_fixnum_value(posarg));
}
if (posarg == -1) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after numbered", mrb_str_new(mrb, (name), (len)));
}
}
#define GETNEXTARG() (\
check_next_arg(mrb, posarg, nextarg),\
(posarg = nextarg++, GETNTHARG(posarg))) (posarg = nextarg++, GETNTHARG(posarg)))
#define GETPOSARG(n) (posarg > 0 ? \ #define GETARG() (!mrb_undef_p(nextvalue) ? nextvalue : GETNEXTARG())
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after unnumbered(%S)", mrb_fixnum_value(n), mrb_fixnum_value(posarg)), mrb_undef_value()) : \
posarg == -2 ? \ #define GETPOSARG(n) (\
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after named", mrb_fixnum_value(n)), mrb_undef_value()) : \ check_pos_arg(mrb, posarg, n),\
((n < 1) ? \ (posarg = -1, GETNTHARG(n)))
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid index - %S$", mrb_fixnum_value(n)), mrb_undef_value()) : \
(posarg = -1, GETNTHARG(n))))
#define GETNTHARG(nth) \ #define GETNTHARG(nth) \
((nth >= argc) ? (mrb_raise(mrb, E_ARGUMENT_ERROR, "too few arguments"), mrb_undef_value()) : argv[nth]) ((nth >= argc) ? (mrb_raise(mrb, E_ARGUMENT_ERROR, "too few arguments"), mrb_undef_value()) : argv[nth])
#define GETNAMEARG(id, name, len) ( \ #define GETNAMEARG(id, name, len) (\
posarg > 0 ? \ check_name_arg(mrb, posarg, name, len),\
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after unnumbered(%S)", mrb_str_new(mrb, (name), (len)), mrb_fixnum_value(posarg)), mrb_undef_value()) : \
posarg == -1 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after numbered", mrb_str_new(mrb, (name), (len))), mrb_undef_value()) : \
(posarg = -2, mrb_hash_fetch(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value()))) (posarg = -2, mrb_hash_fetch(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value())))
#define GETNUM(n, val) \ #define GETNUM(n, val) \
...@@ -182,7 +215,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) ...@@ -182,7 +215,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
tmp_v = GETPOSARG(n); \ tmp_v = GETPOSARG(n); \
} \ } \
else { \ else { \
tmp_v = GETARG(); \ tmp_v = GETNEXTARG(); \
p = t; \ p = t; \
} \ } \
num = mrb_fixnum(tmp_v); \ num = mrb_fixnum(tmp_v); \
......
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