merge revision(s) 39236: [Backport #7841]

* class.c (include_modules_at): detect cyclic prepend with original
	  method table.  [ruby-core:52205] [Bug #7841]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2013-03-02 17:24:30 +00:00
parent 362f70c3cf
commit e8237c5b32
4 changed files with 20 additions and 4 deletions

View file

@ -1,3 +1,8 @@
Sun Mar 3 02:22:56 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* class.c (include_modules_at): detect cyclic prepend with original
method table. [ruby-core:52205] [Bug #7841]
Sun Mar 3 02:16:24 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Mar 3 02:16:24 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_method.c: call method_removed hook on called class, not on * vm_method.c: call method_removed hook on called class, not on

View file

@ -681,7 +681,7 @@ rb_include_class_new(VALUE module, VALUE super)
return (VALUE)klass; return (VALUE)klass;
} }
static int include_modules_at(VALUE klass, VALUE c, VALUE module); static int include_modules_at(const VALUE klass, VALUE c, VALUE module);
void void
rb_include_module(VALUE klass, VALUE module) rb_include_module(VALUE klass, VALUE module)
@ -713,17 +713,18 @@ add_refined_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
} }
static int static int
include_modules_at(VALUE klass, VALUE c, VALUE module) include_modules_at(const VALUE klass, VALUE c, VALUE module)
{ {
VALUE p; VALUE p;
int changed = 0; int changed = 0;
const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
while (module) { while (module) {
int superclass_seen = FALSE; int superclass_seen = FALSE;
if (RCLASS_ORIGIN(module) != module) if (RCLASS_ORIGIN(module) != module)
goto skip; goto skip;
if (RCLASS_M_TBL(klass) && RCLASS_M_TBL(klass) == RCLASS_M_TBL(module)) if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
return -1; return -1;
/* ignore if the module included already in superclasses */ /* ignore if the module included already in superclasses */
for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) { for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {

View file

@ -1465,6 +1465,16 @@ class TestModule < Test::Unit::TestCase
assert_equal([:m1], Class.new(Class.new{def m2;end}){ prepend Module.new; def m1; end }.instance_methods(false), bug6660) assert_equal([:m1], Class.new(Class.new{def m2;end}){ prepend Module.new; def m1; end }.instance_methods(false), bug6660)
end end
def test_cyclic_prepend
bug7841 = '[ruby-core:52205] [Bug #7841]'
m1 = Module.new
m2 = Module.new
m1.instance_eval { prepend(m2) }
assert_raise(ArgumentError, bug7841) do
m2.instance_eval { prepend(m1) }
end
end
def test_class_variables def test_class_variables
m = Module.new m = Module.new
m.class_variable_set(:@@foo, 1) m.class_variable_set(:@@foo, 1)

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0" #define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2013-03-03" #define RUBY_RELEASE_DATE "2013-03-03"
#define RUBY_PATCHLEVEL 5 #define RUBY_PATCHLEVEL 6
#define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 3 #define RUBY_RELEASE_MONTH 3