From ffa3b760d1bc2871303fea95b876fda33c138b61 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 15 Jun 2008 16:50:37 +0000 Subject: * eval.c (rb_f_block_given_p): fix to skip class frame. [ruby-core:14813] * KNOWNBUGS.rb, bootstraptest/test_method.rb: move solved test. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@17351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ KNOWNBUGS.rb | 26 -------------------------- bootstraptest/test_method.rb | 31 +++++++++++++++++++++++++++++++ eval.c | 8 ++++++-- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c362eb71..122f3758b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Jun 16 01:49:39 2008 Koichi Sasada + + * eval.c (rb_f_block_given_p): fix to skip class frame. + [ruby-core:14813] + + * KNOWNBUGS.rb, bootstraptest/test_method.rb: move solved test. + Mon Jun 16 01:48:08 2008 Koichi Sasada * vm_dump.c (vm_stack_dump_raw): disable verbose debug output. diff --git a/KNOWNBUGS.rb b/KNOWNBUGS.rb index 54ae030f6..7f6fa9274 100644 --- a/KNOWNBUGS.rb +++ b/KNOWNBUGS.rb @@ -3,32 +3,6 @@ # So all tests will cause failure. # -assert_equal 'ok', %q{ - class C - define_method(:foo) { - if block_given? - :ng - else - :ok - end - } - end - C.new.foo {} -}, '[ruby-core:14813]' - -assert_equal 'ok', %q{ - class C - define_method(:foo) { - if block_given? - :ng - else - :ok - end - } - end - C.new.foo -}, '[ruby-core:14813]' - assert_equal %q{[:bar, :foo]}, %q{ def foo klass = Class.new do diff --git a/bootstraptest/test_method.rb b/bootstraptest/test_method.rb index 8b5d584e3..28cd2fbaf 100644 --- a/bootstraptest/test_method.rb +++ b/bootstraptest/test_method.rb @@ -1026,3 +1026,34 @@ assert_not_match /method_missing/, %q{ STDERR.reopen(STDOUT) variable_or_mehtod_not_exist } + +assert_equal '[false, false, false, false, true, true]', %q{ + class C + define_method(:foo) { + block_given? + } + end + + C.new.foo {} + + class D + def foo + D.module_eval{ + define_method(:m1){ + block_given? + } + } + end + def bar + D.module_eval{ + define_method(:m2){ + block_given? + } + } + end + end + + D.new.foo + D.new.bar{} + [C.new.foo, C.new.foo{}, D.new.m1, D.new.m1{}, D.new.m2, D.new.m2{}] +}, '[ruby-core:14813]' diff --git a/eval.c b/eval.c index f6424372f..3e9512e5f 100644 --- a/eval.c +++ b/eval.c @@ -545,7 +545,9 @@ int rb_block_given_p(void) { rb_thread_t *th = GET_THREAD(); - if (GC_GUARDED_PTR_REF(th->cfp->lfp[0])) { + + if ((th->cfp->lfp[0] & 0x02) == 0 && + GC_GUARDED_PTR_REF(th->cfp->lfp[0])) { return Qtrue; } else { @@ -588,7 +590,9 @@ rb_f_block_given_p(void) rb_control_frame_t *cfp = th->cfp; cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); - if (cfp != 0 && GC_GUARDED_PTR_REF(cfp->lfp[0])) { + if (cfp != 0 && + (cfp->lfp[0] & 0x02) == 0 && + GC_GUARDED_PTR_REF(cfp->lfp[0])) { return Qtrue; } else { -- cgit