From d5b7e690320e969d77be665927fe8a493aa5806d Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 15 Dec 2008 05:15:26 +0000 Subject: [PATCH] * vm_eval.c (vm_call_super): uses method_missing(). * vm_eval.c (method_missing): get rid of too large alloca. * vm_eval.c (rb_call0, method_missing): uses idMethodMissing. * vm_method.c (rb_add_method, remove_method, rb_undef): uses id__send__. * vm_method.c (Init_eval_method): removed IDs which are defined as immediate values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++++++++ vm_eval.c | 46 ++++++++++++++++++++-------------------------- vm_method.c | 16 ++++------------ 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7898cf2b4d..8204f798d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Mon Dec 15 14:15:23 2008 Nobuyoshi Nakada + + * vm_eval.c (vm_call_super): uses method_missing(). + + * vm_eval.c (method_missing): get rid of too large alloca. + + * vm_eval.c (rb_call0, method_missing): uses idMethodMissing. + + * vm_method.c (rb_add_method, remove_method, rb_undef): uses + id__send__. + + * vm_method.c (Init_eval_method): removed IDs which are defined as + immediate values. + Mon Dec 15 11:35:27 2008 Nobuyoshi Nakada * vm.c (vm_backtrace): defaults to script name for C functions. diff --git a/vm_eval.c b/vm_eval.c index 12d32d851f..be3c0fc5be 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -137,28 +137,11 @@ vm_call_super(rb_thread_t * const th, const int argc, const VALUE * const argv) } body = rb_method_node(klass, id); /* this returns NODE_METHOD */ - - if (body) { - body = body->nd_body; - } - else { - VALUE *argv_m, result, argv_ary = 0; - if (argc < 0x100) { - argv_m = ALLOCA_N(VALUE, argc+1); - } - else { - argv_ary = rb_ary_tmp_new(argc+1); - argv_m = RARRAY_PTR(argv_ary); - } - MEMCPY(argv_m + 1, argv, VALUE, argc); - argv_m[0] = ID2SYM(id); - th->method_missing_reason = 0; - th->passed_block = 0; - result = rb_funcall2(recv, idMethodMissing, argc + 1, argv_m); - if (argv_ary) rb_ary_clear(argv_ary); - return result; + if (!body) { + return method_missing(recv, id, argc, argv, 0); } + body = body->nd_body; return vm_call0(th, klass, recv, id, id, argc, argv, body, CALL_SUPER); } @@ -221,7 +204,7 @@ rb_call0(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, } - if (mid != missing) { + if (mid != idMethodMissing) { /* receiver specified form for private method */ if (UNLIKELY(noex)) { if (((noex & NOEX_MASK) & NOEX_PRIVATE) && scope == 0) { @@ -347,10 +330,13 @@ rb_method_missing(int argc, const VALUE *argv, VALUE obj) static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status) { - VALUE *nargv; - GET_THREAD()->method_missing_reason = call_status; + VALUE *nargv, result, argv_ary = 0; + rb_thread_t *th = GET_THREAD(); - if (id == missing) { + th->method_missing_reason = call_status; + th->passed_block = 0; + + if (id == idMethodMissing) { rb_method_missing(argc, argv, obj); } else if (id == ID_ALLOCATOR) { @@ -358,11 +344,19 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status) rb_class2name(obj)); } - nargv = ALLOCA_N(VALUE, argc + 1); + if (argc < 0x100) { + nargv = ALLOCA_N(VALUE, argc + 1); + } + else { + argv_ary = rb_ary_tmp_new(argc + 1); + nargv = RARRAY_PTR(argv_ary); + } nargv[0] = ID2SYM(id); MEMCPY(nargv + 1, argv, VALUE, argc); - return rb_funcall2(obj, missing, argc + 1, nargv); + result = rb_funcall2(obj, idMethodMissing, argc + 1, nargv); + if (argv_ary) rb_ary_clear(argv_ary); + return result; } VALUE diff --git a/vm_method.c b/vm_method.c index 72fc33f54e..f3387ed506 100644 --- a/vm_method.c +++ b/vm_method.c @@ -8,9 +8,8 @@ static void rb_vm_check_redefinition_opt_method(const NODE *node); -static ID __send__, object_id; +static ID object_id; static ID removed, singleton_removed, undefined, singleton_undefined; -static ID eqq, each, aref, aset, match, missing; static ID added, singleton_added; struct cache_entry { /* method hash table. */ @@ -166,7 +165,7 @@ rb_add_method(VALUE klass, ID mid, NODE * node, int noex) rb_warn("redefining Object#initialize may cause infinite loop"); } - if (mid == object_id || mid == __send__) { + if (mid == object_id || mid == id__send__) { if (node && nd_type(node) == RUBY_VM_METHOD_NODE) { rb_warn("redefining `%s' may cause serious problem", rb_id2name(mid)); @@ -313,7 +312,7 @@ remove_method(VALUE klass, ID mid) } if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); - if (mid == object_id || mid == __send__ || mid == idInitialize) { + if (mid == object_id || mid == id__send__ || mid == idInitialize) { rb_warn("removing `%s' may cause serious problem", rb_id2name(mid)); } if (st_lookup(RCLASS_M_TBL(klass), mid, &data)) { @@ -480,7 +479,7 @@ rb_undef(VALUE klass, ID id) rb_id2name(id)); } rb_frozen_class_p(klass); - if (id == object_id || id == __send__ || id == idInitialize) { + if (id == object_id || id == id__send__ || id == idInitialize) { rb_warn("undefining `%s' may cause serious problem", rb_id2name(id)); } body = search_method(klass, id, &origin); @@ -1128,13 +1127,6 @@ Init_eval_method(void) rb_define_singleton_method(rb_vm_top_self(), "private", top_private, -1); object_id = rb_intern("object_id"); - __send__ = rb_intern("__send__"); - eqq = rb_intern("==="); - each = rb_intern("each"); - aref = rb_intern("[]"); - aset = rb_intern("[]="); - match = rb_intern("=~"); - missing = rb_intern("method_missing"); added = rb_intern("method_added"); singleton_added = rb_intern("singleton_method_added"); removed = rb_intern("method_removed");