ruby-changes:24187
From: nobu <ko1@a...>
Date: Wed, 27 Jun 2012 22:40:45 +0900 (JST)
Subject: [ruby-changes:24187] nobu:r36238 (trunk): fix null m_tbl
nobu 2012-06-27 22:40:34 +0900 (Wed, 27 Jun 2012) New Revision: 36238 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36238 Log: fix null m_tbl * class.c (rb_obj_singleton_methods): m_tbl in prepended class/module is NULL. Modified files: trunk/class.c trunk/test/ruby/test_module.rb Index: class.c =================================================================== --- class.c (revision 36237) +++ class.c (revision 36238) @@ -1172,12 +1172,14 @@ 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); } } Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 36237) +++ test/ruby/test_module.rb (revision 36238) @@ -1284,4 +1284,10 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/