mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fixed inadvertent ID creation in rb_iv_get
This commit is contained in:
parent
6982a9049e
commit
99dc885974
3 changed files with 23 additions and 1 deletions
|
@ -20,6 +20,13 @@ sym_pinneddown_p(VALUE dummy, VALUE sym)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
sym_iv_get(VALUE dummy, VALUE obj, VALUE name)
|
||||||
|
{
|
||||||
|
const char *n = StringValueCStr(name);
|
||||||
|
return rb_iv_get(obj, n);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Init_symbol(void)
|
Init_symbol(void)
|
||||||
{
|
{
|
||||||
|
@ -27,5 +34,6 @@ Init_symbol(void)
|
||||||
VALUE klass = rb_define_class_under(mBug, "Symbol", rb_cSymbol);
|
VALUE klass = rb_define_class_under(mBug, "Symbol", rb_cSymbol);
|
||||||
rb_define_singleton_method(klass, "find", sym_find, 1);
|
rb_define_singleton_method(klass, "find", sym_find, 1);
|
||||||
rb_define_singleton_method(klass, "pinneddown?", sym_pinneddown_p, 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);
|
TEST_INIT_FUNCS(init);
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,5 +482,14 @@ module Test_Symbol
|
||||||
foo.call(name.to_sym => 42)
|
foo.call(name.to_sym => 42)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -3361,8 +3361,13 @@ rb_mod_remove_cvar(VALUE mod, VALUE name)
|
||||||
VALUE
|
VALUE
|
||||||
rb_iv_get(VALUE obj, const char *name)
|
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);
|
return rb_ivar_get(obj, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue