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

ruby-changes:28123

From: naruse <ko1@a...>
Date: Sun, 7 Apr 2013 21:28:28 +0900 (JST)
Subject: [ruby-changes:28123] naruse:r40175 (trunk): * object.c (rb_mod_const_set): call to_str for string only once.

naruse	2013-04-07 21:28:21 +0900 (Sun, 07 Apr 2013)

  New Revision: 40175

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

  Log:
    * object.c (rb_mod_const_set): call to_str for string only once.
      to_str was called from rb_is_const_name and rb_to_id before.

  Modified files:
    trunk/ChangeLog
    trunk/object.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40174)
+++ ChangeLog	(revision 40175)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Apr  7 21:27:40 2013  NARUSE, Yui  <naruse@r...>
+
+	* object.c (rb_mod_const_set): call to_str for string only once.
+	  to_str was called from rb_is_const_name and rb_to_id before.
+
+
 Sun Apr  7 21:16:19 2013  NARUSE, Yui  <naruse@r...>
 
 	* object.c (rb_mod_cvar_set): call to_str for string only once.
Index: object.c
===================================================================
--- object.c	(revision 40174)
+++ object.c	(revision 40175)
@@ -2051,12 +2051,17 @@ rb_mod_const_set(VALUE mod, VALUE name, https://github.com/ruby/ruby/blob/trunk/object.c#L2051
 			  QUOTE_ID(id));
 	}
     }
-    else if (!rb_is_const_name(name)) {
-	rb_name_error_str(name, "wrong constant name %"PRIsVALUE,
-			  QUOTE(name));
-    }
     else {
-	id = rb_to_id(name);
+	VALUE cname = rb_check_string_type(name);
+	if (NIL_P(cname)) {
+	    rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol or string",
+		    name);
+	}
+	if (!rb_is_const_name(cname)) {
+	    rb_name_error_str(cname, "wrong constant name %"PRIsVALUE,
+		    QUOTE(cname));
+	}
+	id = rb_to_id(cname);
     }
     rb_const_set(mod, id, value);
     return value;

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

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