1
0
Fork 0
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:
Nobuyoshi Nakada 2019-07-01 13:56:55 +09:00
parent 6982a9049e
commit 99dc885974
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 23 additions and 1 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -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);
}