1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c (rb_f_send_bang): abandon the name funcall for private

aware method call.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-08-24 08:15:37 +00:00
parent ac150ad226
commit 99ab1fed49
8 changed files with 35 additions and 30 deletions

View file

@ -1,3 +1,8 @@
Fri Aug 24 17:06:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_f_send_bang): abandon the name funcall for private
aware method call.
Thu Aug 23 20:31:31 2007 Koichi Sasada <ko1@atdot.net> Thu Aug 23 20:31:31 2007 Koichi Sasada <ko1@atdot.net>
* compile.c: optimize simple massign. * compile.c: optimize simple massign.

View file

@ -316,7 +316,7 @@ assert_equal '[1, 2]', %q( class C; def m(*a) a end end;
assert_equal '1', %q( class C; def m() 7 end; private :m end assert_equal '1', %q( class C; def m() 7 end; private :m end
begin C.new.send(:m); rescue NoMethodError; 1 end ) begin C.new.send(:m); rescue NoMethodError; 1 end )
assert_equal '1', %q( class C; def m() 1 end; private :m end assert_equal '1', %q( class C; def m() 1 end; private :m end
C.new.funcall(:m) ) C.new.send!(:m) )
# with block # with block
assert_equal '[[:ok1, :foo], [:ok2, :foo, :bar]]', assert_equal '[[:ok1, :foo], [:ok2, :foo, :bar]]',
@ -867,7 +867,7 @@ assert_equal %q{[:ok, :ok, :ok, :ok, :ok, :ok, :ng, :ng]}, %q{
end end
end end
alias funcall send unless defined? funcall alias send! send unless defined? send!
c1 = c2 = nil c1 = c2 = nil
@ -899,8 +899,8 @@ assert_equal %q{[:ok, :ok, :ok, :ok, :ok, :ok, :ng, :ng]}, %q{
test{o2.mm} test{o2.mm}
test{o1.send :m} test{o1.send :m}
test{o2.send :mm} test{o2.send :mm}
test{o1.funcall :m} test{o1.send! :m}
test{o2.funcall :mm} test{o2.send! :mm}
test{o1.method(:m).call} test{o1.method(:m).call}
test{o2.method(:mm).call} test{o2.method(:mm).call}
$ans $ans

20
eval.c
View file

@ -1437,7 +1437,7 @@ rb_apply(VALUE recv, ID mid, VALUE args)
} }
static VALUE static VALUE
send_funcall(int argc, VALUE *argv, VALUE recv, int scope) send_internal(int argc, VALUE *argv, VALUE recv, int scope)
{ {
VALUE vid; VALUE vid;
@ -1479,26 +1479,26 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
scope = NOEX_NOSUPER | NOEX_PRIVATE; scope = NOEX_NOSUPER | NOEX_PRIVATE;
} }
return send_funcall(argc, argv, recv, scope); return send_internal(argc, argv, recv, scope);
} }
/* /*
* call-seq: * call-seq:
* obj.funcall(symbol [, args...]) => obj * obj.send!(symbol [, args...]) => obj
* obj.__send!(symbol [, args...]) => obj * obj.__send!(symbol [, args...]) => obj
* *
* Invokes the method identified by _symbol_, passing it any * Invokes the method identified by _symbol_, passing it any
* arguments specified. Unlike send, which calls private methods only * arguments specified. Unlike send, which calls public methods only
* when it is invoked in function call style, funcall always aware of * when it is invoked in function call style, send! always aware of
* private methods. * private methods.
* *
* 1.funcall(:puts, "hello") # prints "foo" * 1.send!(:puts, "hello") # prints "foo"
*/ */
VALUE VALUE
rb_f_funcall(int argc, VALUE *argv, VALUE recv) rb_f_send_bang(int argc, VALUE *argv, VALUE recv)
{ {
return send_funcall(argc, argv, recv, NOEX_NOSUPER | NOEX_PRIVATE); return send_internal(argc, argv, recv, NOEX_NOSUPER | NOEX_PRIVATE);
} }
VALUE VALUE
@ -2730,8 +2730,8 @@ Init_eval(void)
rb_define_method(rb_cBasicObject, "send", rb_f_send, -1); rb_define_method(rb_cBasicObject, "send", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "__send", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "funcall", rb_f_funcall, -1); rb_define_method(rb_cBasicObject, "send!", rb_f_send_bang, -1);
rb_define_method(rb_cBasicObject, "__send!", rb_f_funcall, -1); rb_define_method(rb_cBasicObject, "__send!", rb_f_send_bang, -1);
rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1); rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1); rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1);

View file

@ -580,10 +580,10 @@ vm_send_optimize(rb_control_frame_t *reg_cfp,
{ {
if (*mn && nd_type((*mn)->nd_body) == NODE_CFUNC) { if (*mn && nd_type((*mn)->nd_body) == NODE_CFUNC) {
NODE *node = (*mn)->nd_body; NODE *node = (*mn)->nd_body;
extern VALUE rb_f_funcall(int argc, VALUE *argv, VALUE recv); extern VALUE rb_f_send_bang(int argc, VALUE *argv, VALUE recv);
extern VALUE rb_f_send(int argc, VALUE *argv, VALUE recv); extern VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
if (node->nd_cfnc == rb_f_funcall || node->nd_cfnc == rb_f_send) { if (node->nd_cfnc == rb_f_send_bang || node->nd_cfnc == rb_f_send) {
int i = *num - 1; int i = *num - 1;
VALUE sym = TOPN(i); VALUE sym = TOPN(i);
*id = SYMBOL_P(sym) ? SYM2ID(sym) : rb_to_id(sym); *id = SYMBOL_P(sym) ? SYM2ID(sym) : rb_to_id(sym);
@ -598,7 +598,7 @@ vm_send_optimize(rb_control_frame_t *reg_cfp,
DEC_SP(1); DEC_SP(1);
} }
if (node->nd_cfnc == rb_f_funcall) { if (node->nd_cfnc == rb_f_send_bang) {
*flag |= VM_CALL_FCALL_BIT; *flag |= VM_CALL_FCALL_BIT;
} }
} }

View file

@ -115,7 +115,7 @@
# implementation, see SimpleDelegator. # implementation, see SimpleDelegator.
# #
class Delegator class Delegator
preserved = [:__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :funcall] preserved = [:__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :send!]
instance_methods.each do |m| instance_methods.each do |m|
next if preserved.include?(m) next if preserved.include?(m)
undef_method m undef_method m
@ -262,7 +262,7 @@ def DelegateClass(superclass)
klass = Class.new klass = Class.new
methods = superclass.public_instance_methods(true) methods = superclass.public_instance_methods(true)
methods -= [ methods -= [
:__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :funcall, :__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :send!,
:==, :equal?, :initialize, :method_missing, :__getobj__, :__setobj__, :==, :equal?, :initialize, :method_missing, :__getobj__, :__setobj__,
:clone, :dup, :marshal_dump, :marshal_load, :clone, :dup, :marshal_dump, :marshal_load,
] ]

View file

@ -246,7 +246,7 @@ class Matrix
# use to general users. # use to general users.
# #
def initialize(init_method, *argv) def initialize(init_method, *argv)
self.funcall(init_method, *argv) self.send!(init_method, *argv)
end end
def init_rows(rows, copy) def init_rows(rows, copy)

View file

@ -91,13 +91,13 @@ module MonitorMixin
if timeout if timeout
raise NotImplementedError, "timeout is not implemented yet" raise NotImplementedError, "timeout is not implemented yet"
end end
@monitor.funcall(:mon_check_owner) @monitor.send!(:mon_check_owner)
count = @monitor.funcall(:mon_exit_for_cond) count = @monitor.send!(:mon_exit_for_cond)
begin begin
@cond.wait(@monitor.instance_variable_get("@mon_mutex")) @cond.wait(@monitor.instance_variable_get("@mon_mutex"))
return true return true
ensure ensure
@monitor.funcall(:mon_enter_for_cond, count) @monitor.send!(:mon_enter_for_cond, count)
end end
end end
@ -114,12 +114,12 @@ module MonitorMixin
end end
def signal def signal
@monitor.funcall(:mon_check_owner) @monitor.send!(:mon_check_owner)
@cond.signal @cond.signal
end end
def broadcast def broadcast
@monitor.funcall(:mon_check_owner) @monitor.send!(:mon_check_owner)
@cond.broadcast @cond.broadcast
end end
@ -137,7 +137,7 @@ module MonitorMixin
def self.extend_object(obj) def self.extend_object(obj)
super(obj) super(obj)
obj.funcall(:mon_initialize) obj.send!(:mon_initialize)
end end
# #

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0" #define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-08-23" #define RUBY_RELEASE_DATE "2007-08-24"
#define RUBY_VERSION_CODE 190 #define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070823 #define RUBY_RELEASE_CODE 20070824
#define RUBY_PATCHLEVEL 0 #define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0 #define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 8 #define RUBY_RELEASE_MONTH 8
#define RUBY_RELEASE_DAY 23 #define RUBY_RELEASE_DAY 24
#ifdef RUBY_EXTERN #ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];