From 24cf72029f0c43f59520b88d1eafee4959bcddc1 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Oct 2013 14:57:04 +0000 Subject: object.c: avoid inadvertent symbol creation * object.c (id_for_attr): avoid inadvertent symbol creation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 72868120a9..6b87c8d705 100644 --- a/object.c +++ b/object.c @@ -1889,6 +1889,35 @@ check_setter_id(VALUE name, int (*valid_id_p)(ID), int (*valid_name_p)(VALUE), return id; } +static int +rb_is_attr_id(ID id) +{ + return rb_is_local_id(id) || rb_is_const_id(id); +} + +static int +rb_is_attr_name(VALUE name) +{ + return rb_is_local_name(name) || rb_is_const_name(name); +} + +static const char invalid_attribute_name[] = "invalid attribute name `%"PRIsVALUE"'"; + +static ID +id_for_attr(VALUE name) +{ + return id_for_setter(name, attr, invalid_attribute_name); +} + +ID +rb_check_attr_id(ID id) +{ + if (!rb_is_attr_id(id)) { + rb_name_error_str(id, invalid_attribute_name, QUOTE_ID(id)); + } + return id; +} + /* * call-seq: * attr_reader(symbol, ...) -> nil @@ -1908,7 +1937,7 @@ rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass) int i; for (i=0; i