From e7dac48a9190169a241865cd706566b52e07b3b7 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 19 Jun 2008 15:43:25 +0000 Subject: * proc.c (proc_new): fix to return Proc object if block is already in heap. [ruby-core:15711] * bootstraptest/test_proc.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ bootstraptest/test_proc.rb | 17 +++++++++++++++++ proc.c | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1001b475ac..73b8561b83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Jun 20 00:40:08 2008 Koichi Sasada + + * proc.c (proc_new): fix to return Proc object if block is already + in heap. [ruby-core:15711] + + * bootstraptest/test_proc.rb: add a test. + Fri Jun 20 00:18:04 2008 Koichi Sasada * thread_win32.c (native_sleep): fix to decrement sleeper count. diff --git a/bootstraptest/test_proc.rb b/bootstraptest/test_proc.rb index f384ba3510..2fb5da41c9 100644 --- a/bootstraptest/test_proc.rb +++ b/bootstraptest/test_proc.rb @@ -378,3 +378,20 @@ assert_equal 'ok', %q{ m() } +assert_equal 'ok', %q{ + class Foo + def call_it + p = Proc.new + p.call + end + end + + def give_it + proc { :ok } + end + + f = Foo.new + a_proc = give_it + p :call_it + f.call_it(&give_it()) +}, '[ruby-core:15711]' diff --git a/proc.c b/proc.c index eecff7ae12..f2d69c7317 100644 --- a/proc.c +++ b/proc.c @@ -358,6 +358,10 @@ proc_new(VALUE klass, int is_lambda) block = GC_GUARDED_PTR_REF(cfp->lfp[0]); + if (block->proc) { + return block->proc; + } + /* TODO: check more (cfp limit, called via cfunc, etc) */ while (cfp->dfp != block->dfp) { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); -- cgit v1.2.3