Skip to content

Commit

Permalink
fix null m_tbl
Browse files Browse the repository at this point in the history
* class.c (rb_obj_singleton_methods): m_tbl in prepended class/module
  is NULL.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 27, 2012
1 parent cf3a8f0 commit d4269d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,14 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
klass = CLASS_OF(obj);
list = st_init_numtable();
if (klass && FL_TEST(klass, FL_SINGLETON)) {
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
if (RCLASS_M_TBL(klass))
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
if (RTEST(recur)) {
while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
if (RCLASS_M_TBL(klass))
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/ruby/test_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1284,4 +1284,10 @@ def test_prepend_instance_methods
bug6655 = '[ruby-core:45915]'
assert_equal(Object.instance_methods, Class.new {prepend Module.new}.instance_methods, bug6655)
end

def test_prepend_singleton_methods
o = Object.new
o.singleton_class.class_eval {prepend Module.new}
assert_equal([], o.singleton_methods)
end
end

0 comments on commit d4269d7

Please sign in to comment.