From b30b998966553a614f18703536b49a4dc273e0c6 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sat, 27 Dec 2008 03:57:21 +0000 Subject: * vm_insnhelper.c (vm_call_method, vm_call_cfunc): use original id instead of calling id when NODE_CFUNC or NODE_BMETHOD. fixes Bug #632 [ruby-core:19282]. * vm_eval.c (vm_call0, vm_call_super): ditto. * vm_method.c (rb_add_method, rb_alias): store original id in nd_file field of NODE_METHOD. * test/stringio/test_stringio.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ test/stringio/test_stringio.rb | 15 +++++++++++++++ vm_eval.c | 8 ++++---- vm_insnhelper.c | 8 ++++---- vm_method.c | 10 +++++++--- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7ae7a867b..ee12312013 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sat Dec 27 11:41:45 2008 Koichi Sasada + + * vm_insnhelper.c (vm_call_method, vm_call_cfunc): use original id instead of + calling id when NODE_CFUNC or NODE_BMETHOD. + fixes Bug #632 [ruby-core:19282]. + + * vm_eval.c (vm_call0, vm_call_super): ditto. + + * vm_method.c (rb_add_method, rb_alias): store original id + in nd_file field of NODE_METHOD. + + * test/stringio/test_stringio.rb: add a test. + Sat Dec 27 09:48:54 2008 Koichi Sasada * vm.c (Init_VM): create and define TOPLEVEL_BINDING at first. diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 8f0dc8702c..98cf84e00f 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -379,4 +379,19 @@ class TestStringIO < Test::Unit::TestCase assert_equal(4, f.size) end + # This test is should in ruby/test_method.rb + # However this test depends on stringio library, + # we write it here. + class C < StringIO + alias old_init initialize + attr_reader :foo + def initialize + @foo = :ok + old_init + end + end + + def test_method + assert_equal(:ok, C.new.foo, 'Bug #632 [ruby-core:19282]') + end end diff --git a/vm_eval.c b/vm_eval.c index aea00e2f5c..851eaaf9ff 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -64,7 +64,7 @@ vm_call0(rb_thread_t * th, VALUE klass, VALUE recv, VALUE id, ID oid, vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); - cfp->method_id = id; + cfp->method_id = oid; cfp->method_class = klass; val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv); @@ -96,7 +96,7 @@ vm_call0(rb_thread_t * th, VALUE klass, VALUE recv, VALUE id, ID oid, break; } case NODE_BMETHOD:{ - val = vm_call_bmethod(th, id, body->nd_cval, + val = vm_call_bmethod(th, oid, body->nd_cval, recv, klass, argc, (VALUE *)argv, blockptr); break; } @@ -152,8 +152,8 @@ vm_call_super(rb_thread_t * const th, const int argc, const VALUE * const argv) 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); + return vm_call0(th, klass, recv, id, (ID)body->nd_file, + argc, argv, body->nd_body, CALL_SUPER); } VALUE diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 28eaeb7951..3a13a0774e 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -355,7 +355,7 @@ call_cfunc(VALUE (*func)(), VALUE recv, static inline VALUE vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, - int num, ID id, VALUE recv, VALUE klass, + int num, ID id, ID oid, VALUE recv, VALUE klass, VALUE flag, const NODE *mn, const rb_block_t *blockptr) { VALUE val; @@ -366,7 +366,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, (VALUE) blockptr, 0, reg_cfp->sp, 0, 1); - cfp->method_id = id; + cfp->method_id = oid; cfp->method_class = klass; reg_cfp->sp -= num + 1; @@ -497,7 +497,7 @@ vm_call_method(rb_thread_t * const th, rb_control_frame_t * const cfp, return Qundef; } case NODE_CFUNC:{ - val = vm_call_cfunc(th, cfp, num, id, recv, mn->nd_clss, flag, node, blockptr); + val = vm_call_cfunc(th, cfp, num, id, (ID)mn->nd_file, recv, mn->nd_clss, flag, node, blockptr); break; } case NODE_ATTRSET:{ @@ -518,7 +518,7 @@ vm_call_method(rb_thread_t * const th, rb_control_frame_t * const cfp, VALUE *argv = ALLOCA_N(VALUE, num); MEMCPY(argv, cfp->sp - num, VALUE, num); cfp->sp += - num - 1; - val = vm_call_bmethod(th, id, node->nd_cval, recv, mn->nd_clss, num, argv, blockptr); + val = vm_call_bmethod(th, (ID)mn->nd_file, node->nd_cval, recv, mn->nd_clss, num, argv, blockptr); break; } case NODE_ZSUPER:{ diff --git a/vm_method.c b/vm_method.c index f3387ed506..774fa1eda9 100644 --- a/vm_method.c +++ b/vm_method.c @@ -129,6 +129,7 @@ rb_add_method(VALUE klass, ID mid, NODE * node, int noex) /* * NODE_METHOD (NEW_METHOD(body, klass, vis)): + * nd_file : original id // RBASIC()->klass (TODO: dirty hack) * nd_body : method body // (2) // mark * nd_clss : klass // (1) // mark * nd_noex : visibility // (3) @@ -139,7 +140,9 @@ rb_add_method(VALUE klass, ID mid, NODE * node, int noex) * nd_cnt : alias count // (3) */ if (node) { - body = NEW_FBODY(NEW_METHOD(node, klass, NOEX_WITH_SAFE(noex)), 0); + NODE *method = NEW_METHOD(node, klass, NOEX_WITH_SAFE(noex)); + method->nd_file = (void *)mid; + body = NEW_FBODY(method, mid); } else { body = 0; @@ -725,7 +728,7 @@ rb_mod_protected_method_defined(VALUE mod, VALUE mid) void rb_alias(VALUE klass, ID name, ID def) { - NODE *orig_fbody, *node; + NODE *orig_fbody, *node, *method; VALUE singleton = 0; st_data_t data; @@ -762,9 +765,10 @@ rb_alias(VALUE klass, ID name, ID def) st_insert(RCLASS_M_TBL(klass), name, (st_data_t) NEW_FBODY( - NEW_METHOD(orig_fbody->nd_body->nd_body, + method = NEW_METHOD(orig_fbody->nd_body->nd_body, orig_fbody->nd_body->nd_clss, NOEX_WITH_SAFE(orig_fbody->nd_body->nd_noex)), def)); + method->nd_file = (void *)def; rb_clear_cache_by_id(name); -- cgit v1.2.3