Project

General

Profile

Bug #7308 » prevent-circular-using.patch

Anonymous, 11/09/2012 07:37 PM

View differences:

eval.c
rb_hash_foreach(refinements, using_refinement, (VALUE) cref);
}
static int
check_circular_using(VALUE mod, VALUE _, VALUE search)
{
VALUE using_modules;
ID id_using_modules;
CONST_ID(id_using_modules, "__using_modules__");
if(mod == search) {
rb_raise(rb_eTypeError, "circular using is not allowed");
}
using_modules = rb_attr_get(mod, id_using_modules);
if (!NIL_P(using_modules)) {
rb_hash_foreach(using_modules, check_circular_using, search);
}
return ST_CONTINUE;
}
/*
* call-seq:
* using(module) -> self
......
VALUE using_modules;
Check_Type(module, T_MODULE);
check_circular_using(module, 0, self);
CONST_ID(id_using_modules, "__using_modules__");
using_modules = rb_attr_get(self, id_using_modules);
if (NIL_P(using_modules)) {
test/ruby/test_refinement.rb
assert_equal("#<refinement:#{c.inspect}@#{m.inspect}>",
m.refinements[c].inspect)
end
def test_circular_using_is_not_allowed
a = Module.new
b = Module.new
assert_raise TypeError do
a.module_eval do
using a
end
end
b.module_eval do
using a
end
assert_raise TypeError do
a.module_eval do
using b
end
end
end
end
(2-2/2)