1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

parse.y: check for symbol

* parse.y (rb_sym2id, rb_sym2id_without_pindown): reject
  non-symbol values.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-04-24 03:08:49 +00:00
parent e923de6d4a
commit a680ee9ffa

21
parse.y
View file

@ -10768,17 +10768,24 @@ lookup_id_str(ID id, st_data_t *data)
return FALSE; return FALSE;
} }
static void
must_be_dynamic_symbol(VALUE x)
{
if (SPECIAL_CONST_P(x) || BUILTIN_TYPE(x) != T_SYMBOL) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)",
rb_builtin_class_name(x));
}
}
ID ID
rb_sym2id(VALUE x) rb_sym2id(VALUE x)
{ {
if (STATIC_SYM_P(x)) { if (STATIC_SYM_P(x)) {
return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT); return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT);
} }
else if (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) == T_SYMBOL) {
return rb_pin_dynamic_symbol(x);
}
else { else {
return 0; must_be_dynamic_symbol(x);
return rb_pin_dynamic_symbol(x);
} }
} }
@ -10788,11 +10795,9 @@ rb_sym2id_without_pindown(VALUE x)
if (STATIC_SYM_P(x)) { if (STATIC_SYM_P(x)) {
return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT); return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT);
} }
else if (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) == T_SYMBOL) {
return (ID)x;
}
else { else {
return 0; must_be_dynamic_symbol(x);
return (ID)x;
} }
} }