"backport" CRuby r46756; ref #3500

Based on cremno/mruby@6bd0119
parent caee1f68
...@@ -192,9 +192,9 @@ check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len) ...@@ -192,9 +192,9 @@ check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len)
#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 CHECKNAMEARG(name, len) (\
check_name_arg(mrb, posarg, name, len),\ check_name_arg(mrb, posarg, name, len),\
(posarg = -2, mrb_hash_fetch(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value()))) posarg = -2)
#define GETNUM(n, val) do { \ #define GETNUM(n, val) do { \
if (!(p = get_num(mrb, p, end, &(n)))) \ if (!(p = get_num(mrb, p, end, &(n)))) \
...@@ -236,12 +236,12 @@ get_num(mrb_state *mrb, const char *p, const char *end, mrb_int *valp) ...@@ -236,12 +236,12 @@ get_num(mrb_state *mrb, const char *p, const char *end, mrb_int *valp)
return p; return p;
} }
static mrb_value static void
get_hash(mrb_state *mrb, mrb_value *hash, mrb_int argc, const mrb_value *argv) get_hash(mrb_state *mrb, mrb_value *hash, mrb_int argc, const mrb_value *argv)
{ {
mrb_value tmp; mrb_value tmp;
if (!mrb_undef_p(*hash)) return *hash; if (!mrb_undef_p(*hash)) return;
if (argc != 2) { if (argc != 2) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "one hash required"); mrb_raise(mrb, E_ARGUMENT_ERROR, "one hash required");
} }
...@@ -249,7 +249,7 @@ get_hash(mrb_state *mrb, mrb_value *hash, mrb_int argc, const mrb_value *argv) ...@@ -249,7 +249,7 @@ get_hash(mrb_state *mrb, mrb_value *hash, mrb_int argc, const mrb_value *argv)
if (mrb_nil_p(tmp)) { if (mrb_nil_p(tmp)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "one hash required"); mrb_raise(mrb, E_ARGUMENT_ERROR, "one hash required");
} }
return (*hash = tmp); *hash = tmp;
} }
/* /*
...@@ -690,7 +690,6 @@ retry: ...@@ -690,7 +690,6 @@ retry:
case '{': { case '{': {
const char *start = p; const char *start = p;
char term = (*p == '<') ? '>' : '}'; char term = (*p == '<') ? '>' : '}';
mrb_value symname;
for (; p < end && *p != term; ) for (; p < end && *p != term; )
p++; p++;
...@@ -698,10 +697,13 @@ retry: ...@@ -698,10 +697,13 @@ retry:
mrb_raisef(mrb, E_ARGUMENT_ERROR, "name%l after <%n>", mrb_raisef(mrb, E_ARGUMENT_ERROR, "name%l after <%n>",
start, p - start + 1, id); start, p - start + 1, id);
} }
symname = mrb_str_new(mrb, start + 1, p - start - 1); CHECKNAMEARG(start, p - start + 1);
id = mrb_intern_str(mrb, symname); get_hash(mrb, &hash, argc, argv);
nextvalue = GETNAMEARG(mrb_symbol_value(id), start, p - start + 1); id = mrb_check_intern(mrb, start + 1, p - start - 1);
if (mrb_undef_p(nextvalue)) { if (id) {
nextvalue = mrb_hash_fetch(mrb, hash, mrb_symbol_value(id), mrb_undef_value());
}
if (!id || mrb_undef_p(nextvalue)) {
mrb_raisef(mrb, E_KEY_ERROR, "key%l not found", start, p - start + 1); mrb_raisef(mrb, E_KEY_ERROR, "key%l not found", start, p - start + 1);
} }
if (term == '}') goto format_s; if (term == '}') goto format_s;
......
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