diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-27 13:40:34 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-27 13:40:34 +0000 |
commit | d4269d7b7c5c89b98c3f920dcadde1a635f5d72d (patch) | |
tree | f396f54b8813668aa1eb83dee6bd567399f8efe3 | |
parent | cf3a8f09b806dc6f31363e845d9e93d5e046af91 (diff) | |
download | ruby-d4269d7b7c5c89b98c3f920dcadde1a635f5d72d.tar.gz |
fix null m_tbl
* 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
-rw-r--r-- | class.c | 6 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 6 |
2 files changed, 10 insertions, 2 deletions
@@ -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); } } diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 7f66911e43..aa48e1793c 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1284,4 +1284,10 @@ class TestModule < Test::Unit::TestCase 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 |