なかだです。

http://nokada.jin.gr.jp/t/20040611.html#p03 で書いた話ですが、
define_methodでは呼び出されたときの$SAFEを使うようにするパッチ
です。いまいちすっきりしませんが。


* eval.c (proc_invoke0): do not restore safe level when invoked as
  bound method.


Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.667 diff -U2 -p -d -r1.667 eval.c --- eval.c 28 May 2004 02:20:34 -0000 1.667 +++ eval.c 31 May 2004 08:29:39 -0000 @@ -135,5 +135,7 @@ typedef jmp_buf rb_jmpbuf_t; VALUE rb_cProc; static VALUE rb_cBinding; -static VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE)); +static VALUE proc_invoke0 _((VALUE,VALUE,VALUE,VALUE,int)); +#define proc_invoke(proc, args, self, klass) proc_invoke0(proc, args, self, klass, Qfalse) +#define bmethod_invoke(proc, args, self, klass) proc_invoke0(proc, args, self, klass, Qtrue) static VALUE rb_f_binding _((VALUE)); static void rb_f_END _((void)); @@ -5521,5 +5523,5 @@ rb_call0(klass, recv, id, oid, argc, arg case NODE_BMETHOD: - result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass); + result = bmethod_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass); break; @@ -8024,7 +8026,8 @@ block_orphan(data) static VALUE -proc_invoke(proc, args, self, klass) +proc_invoke0(proc, args, self, klass, bmethod) VALUE proc, args; /* OK */ VALUE self, klass; + int bmethod; { struct BLOCK * volatile old_block; @@ -8067,5 +8070,5 @@ proc_invoke(proc, args, self, klass) state = EXEC_TAG(); if (state == 0) { - proc_set_safe_level(proc); + if (!bmethod) proc_set_safe_level(proc); result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, pcall | YIELD_PROC_CALL, avalue); @@ -8079,5 +8082,5 @@ proc_invoke(proc, args, self, klass) ruby_wrapper = old_wrapper; ruby_dyna_vars = old_dvars; - ruby_safe_level = safe; + if (!bmethod) ruby_safe_level = safe; switch (state) {
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦