summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--object.c15
2 files changed, 16 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 60dd77f49e..9dbe9db019 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Apr 7 21:27:40 2013 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* object.c (rb_mod_cvar_set): call to_str for string only once.
diff --git a/object.c b/object.c
index 81f7893a21..e2da8d5092 100644
--- a/object.c
+++ b/object.c
@@ -2051,12 +2051,17 @@ rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
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;