summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-04 07:54:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-04 07:54:44 +0000
commit4e59c822a07f85c79fbcbac40cba5a591512258c (patch)
tree0bc51466bdb3e76101cd5334e7fb6a18fa74ee83 /object.c
parent9f87297c21e2e375990166214327634b212e50fb (diff)
object.c: avoid inadvertent symbol creation
* object.c (rb_mod_const_set): avoid inadvertent symbol creation. (rb_obj_ivar_set): ditto. (rb_mod_cvar_set): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/object.c b/object.c
index 72de18f7ef..a6844bab99 100644
--- a/object.c
+++ b/object.c
@@ -2043,13 +2043,11 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
static VALUE
rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
{
- ID id = rb_to_id(name);
-
- if (!rb_is_const_id(id)) {
- rb_name_error(id, "wrong constant name %"PRIsVALUE,
- QUOTE_ID(id));
+ if (!SYMBOL_P(name) && !rb_is_const_name(name)) {
+ rb_name_error_str(name, "wrong constant name %"PRIsVALUE,
+ QUOTE(name));
}
- rb_const_set(mod, id, value);
+ rb_const_set(mod, rb_to_id(name), value);
return value;
}
@@ -2166,13 +2164,11 @@ rb_obj_ivar_get(VALUE obj, VALUE iv)
static VALUE
rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
{
- ID id = rb_to_id(iv);
-
- if (!rb_is_instance_id(id)) {
- rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name",
- QUOTE_ID(id));
+ if (!SYMBOL_P(iv) && !rb_is_instance_name(iv)) {
+ rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name",
+ QUOTE(iv));
}
- return rb_ivar_set(obj, id, val);
+ return rb_ivar_set(obj, rb_to_id(iv), val);
}
/*
@@ -2277,13 +2273,11 @@ rb_mod_cvar_get(VALUE obj, VALUE iv)
static VALUE
rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
{
- ID id = rb_to_id(iv);
-
- if (!rb_is_class_id(id)) {
- rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
- QUOTE_ID(id));
+ if (!SYMBOL_P(iv) && !rb_is_class_id(iv)) {
+ rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
+ QUOTE(iv));
}
- rb_cvar_set(obj, id, val);
+ rb_cvar_set(obj, rb_to_id(iv), val);
return val;
}