diff --git a/ChangeLog b/ChangeLog index fd0001122f..3a1f2c7a6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Oct 9 23:57:02 2013 Nobuyoshi Nakada + + * object.c (id_for_attr): avoid inadvertent symbol creation. + Wed Oct 9 18:03:01 2013 Nobuyoshi Nakada * vm_method.c (rb_attr): preserve encoding of the attribute ID in 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