From: David Flanagan Date: 2007-11-08T08:24:45+09:00 Subject: Re: send can't call protected methods, but invoke_method can Nobu, This patch and the previous one for invoke_method fix the two problems I was seeing. Are you going to be checking them in? David Nobuyoshi Nakada wrote: > Hi, > > At Wed, 7 Nov 2007 09:42:34 +0900, > David Flanagan wrote in [ruby-core:13254]: >> With the current builds I can't call a protected method with send, but I >> can with invoke_method. This seems like a bug to me, but I don't >> understand the NOEX_ scope bits, so I don't know how to track it down. > > HTH. > > > Index: eval.c > =================================================================== > --- eval.c (revision 13827) > +++ eval.c (working copy) > @@ -1356,5 +1356,5 @@ method_missing(VALUE obj, ID id, int arg > > static VALUE > -rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope) > +rb_call0(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope, VALUE self) > { > NODE *body, *method; > @@ -1410,6 +1410,5 @@ rb_call(VALUE klass, VALUE recv, ID mid, > } > > - if (!rb_obj_is_kind_of(rb_frame_self(), > - rb_class_real(defined_class))) { > + if (!rb_obj_is_kind_of(self, rb_class_real(defined_class))) { > return method_missing(recv, mid, argc, argv, NOEX_PROTECTED); > } > @@ -1443,4 +1442,10 @@ rb_call(VALUE klass, VALUE recv, ID mid, > } > > +static VALUE > +rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope) > +{ > + return rb_call0(klass, recv, mid, argc, argv, scope, rb_frame_self()); > +} > + > VALUE > rb_apply(VALUE recv, ID mid, VALUE args) > @@ -1459,4 +1464,5 @@ send_internal(int argc, VALUE *argv, VAL > { > VALUE vid; > + VALUE self = RUBY_VM_PREVIOUS_CONTROL_FRAME(GET_THREAD()->cfp)->self; > > if (argc == 0) { > @@ -1466,5 +1472,5 @@ send_internal(int argc, VALUE *argv, VAL > vid = *argv++; argc--; > PASS_PASSED_BLOCK(); > - return rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, scope); > + return rb_call0(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, scope, self); > } > > Index: insnhelper.ci > =================================================================== > --- insnhelper.ci (revision 13827) > +++ insnhelper.ci (working copy) > @@ -539,5 +539,5 @@ vm_call_method(rb_thread_t *th, rb_contr > } > else if (((mn->nd_noex & NOEX_MASK) & NOEX_PROTECTED) && > - !(flag & VM_CALL_SEND_BANG_BIT)) { > + !(flag & VM_CALL_SEND_BIT)) { > VALUE defined_class = mn->nd_clss; > > >