なかだです。

やっぱりruby_wrapperを特別扱いするくらいしか思いつきません。


Index: class.c =================================================================== RCS file: /cvs/ruby/src/ruby/class.c,v retrieving revision 1.92 diff -U2 -p -r1.92 class.c --- class.c 12 Sep 2005 10:44:19 -0000 1.92 +++ class.c 15 Sep 2005 11:20:52 -0000 @@ -347,4 +347,5 @@ rb_include_module(VALUE klass, VALUE mod VALUE p, c; int changed = 0; + int wrapper = 0; rb_frozen_class_p(klass); @@ -359,4 +360,7 @@ rb_include_module(VALUE klass, VALUE mod Check_Type(module, T_MODULE); } + if (FL_TEST(klass, FL_WRAPPER) && BUILTIN_TYPE(klass) == T_MODULE) { + wrapper = 1; + } OBJ_INFECT(klass, module); @@ -365,6 +369,8 @@ rb_include_module(VALUE klass, VALUE mod int superclass_seen = Qfalse; - if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl) + if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl) { + if (wrapper) goto skip; rb_raise(rb_eArgError, "cyclic include detected"); + } /* ignore if the module included already in superclasses */ for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) { Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.831 diff -U2 -p -r1.831 eval.c --- eval.c 14 Sep 2005 08:30:15 -0000 1.831 +++ eval.c 15 Sep 2005 11:21:03 -0000 @@ -1593,4 +1593,12 @@ rb_eval_string_protect(const char *str, } +static VALUE +new_wrapper(void) +{ + VALUE mod = rb_module_new(); + FL_SET(mod, FL_WRAPPER); + return mod; +} + VALUE rb_eval_string_wrap(const char *str, int *state) @@ -1601,5 +1609,5 @@ rb_eval_string_wrap(const char *str, int VALUE val; - PUSH_CLASS(ruby_wrapper = rb_module_new()); + PUSH_CLASS(ruby_wrapper = new_wrapper()); ruby_top_self = rb_obj_clone(ruby_top_self); rb_extend_object(ruby_top_self, ruby_wrapper); @@ -6489,5 +6497,5 @@ rb_load(VALUE fname, int wrap) else { /* load in anonymous module as toplevel */ - ruby_class = ruby_wrapper = rb_module_new(); + ruby_class = ruby_wrapper = new_wrapper(); self = rb_obj_clone(ruby_top_self); rb_extend_object(self, ruby_wrapper); @@ -7295,6 +7303,9 @@ top_include(int argc, VALUE *argv, VALUE rb_secure(4); if (ruby_wrapper) { + VALUE ret; rb_warning("main#include in the wrapped load is effective only in wrapper module"); - return rb_mod_include(argc, argv, ruby_wrapper); + ret = rb_mod_include(argc, argv, ruby_wrapper); + rb_extend_object(self, ruby_wrapper); + return ret; } return rb_mod_include(argc, argv, rb_cObject); Index: ruby.h =================================================================== RCS file: /cvs/ruby/src/ruby/ruby.h,v retrieving revision 1.122 diff -U2 -p -r1.122 ruby.h --- ruby.h 14 Sep 2005 13:40:43 -0000 1.122 +++ ruby.h 15 Sep 2005 11:20:42 -0000 @@ -447,4 +447,5 @@ struct RBignum { #define FL_SINGLETON FL_USER0 +#define FL_WRAPPER FL_USER1 #define FL_MARK (1<<5) #define FL_RESERVED (1<<6) /* will be used in the future GC */
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦