[前][次][番号順一覧][スレッド一覧]

ruby-changes:33621

From: nobu <ko1@a...>
Date: Thu, 24 Apr 2014 12:08:55 +0900 (JST)
Subject: [ruby-changes:33621] nobu:r45702 (trunk): parse.y: check for symbol

nobu	2014-04-24 12:08:49 +0900 (Thu, 24 Apr 2014)

  New Revision: 45702

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45702

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

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 45701)
+++ parse.y	(revision 45702)
@@ -10768,17 +10768,24 @@ lookup_id_str(ID id, st_data_t *data) https://github.com/ruby/ruby/blob/trunk/parse.y#L10768
     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
 rb_sym2id(VALUE x)
 {
     if (STATIC_SYM_P(x)) {
 	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 {
-	return 0;
+	must_be_dynamic_symbol(x);
+	return rb_pin_dynamic_symbol(x);
     }
 }
 
@@ -10788,11 +10795,9 @@ rb_sym2id_without_pindown(VALUE x) https://github.com/ruby/ruby/blob/trunk/parse.y#L10795
     if (STATIC_SYM_P(x)) {
 	return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT);
     }
-    else if (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) == T_SYMBOL) {
-	return (ID)x;
-    }
     else {
-	return 0;
+	must_be_dynamic_symbol(x);
+	return (ID)x;
     }
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]