зеркало из https://github.com/github/ruby.git
Fixed inadvertent ID creation in rb_iv_get
This commit is contained in:
Родитель
6982a9049e
Коммит
99dc885974
|
@ -20,6 +20,13 @@ sym_pinneddown_p(VALUE dummy, VALUE sym)
|
|||
#endif
|
||||
}
|
||||
|
||||
static VALUE
|
||||
sym_iv_get(VALUE dummy, VALUE obj, VALUE name)
|
||||
{
|
||||
const char *n = StringValueCStr(name);
|
||||
return rb_iv_get(obj, n);
|
||||
}
|
||||
|
||||
void
|
||||
Init_symbol(void)
|
||||
{
|
||||
|
@ -27,5 +34,6 @@ Init_symbol(void)
|
|||
VALUE klass = rb_define_class_under(mBug, "Symbol", rb_cSymbol);
|
||||
rb_define_singleton_method(klass, "find", sym_find, 1);
|
||||
rb_define_singleton_method(klass, "pinneddown?", sym_pinneddown_p, 1);
|
||||
rb_define_singleton_method(klass, "iv_get", sym_iv_get, 2);
|
||||
TEST_INIT_FUNCS(init);
|
||||
}
|
||||
|
|
|
@ -482,5 +482,14 @@ module Test_Symbol
|
|||
foo.call(name.to_sym => 42)
|
||||
end
|
||||
end
|
||||
|
||||
def test_iv_get
|
||||
obj = Object.new
|
||||
assert_warning(/not initialized/) do
|
||||
assert_no_immortal_symbol_created("rb_iv_get") do |name|
|
||||
Bug::Symbol.iv_get(obj, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3361,8 +3361,13 @@ rb_mod_remove_cvar(VALUE mod, VALUE name)
|
|||
VALUE
|
||||
rb_iv_get(VALUE obj, const char *name)
|
||||
{
|
||||
ID id = rb_intern(name);
|
||||
ID id = rb_check_id_cstr(name, strlen(name), rb_usascii_encoding());
|
||||
|
||||
if (!id) {
|
||||
if (RTEST(ruby_verbose))
|
||||
rb_warning("instance variable %s not initialized", name);
|
||||
return Qnil;
|
||||
}
|
||||
return rb_ivar_get(obj, id);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче