From 2d97cee4d57b4f6bc1358c63d8ffd99047e4965e Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 19 Dec 2015 15:29:01 +0000 Subject: proc.c: fix infinite loop * proc.c (rb_proc_get_iseq): proc made from symbol does not have iseq. fix infinite loop. [ruby-core:72381] [Bug #11845] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ proc.c | 4 +--- test/ruby/test_symbol.rb | 12 ++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe54268cdb..ca1452ae3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sun Dec 20 00:29:00 2015 Nobuyoshi Nakada + + * proc.c (rb_proc_get_iseq): proc made from symbol does not have + iseq. fix infinite loop. [ruby-core:72381] [Bug #11845] + +Sun Dec 20 00:28:51 2015 Nobuyoshi Nakada + + * proc.c (rb_proc_get_iseq): proc made from symbol does not have + iseq. fix infinite loop. [ruby-core:72381] [Bug #11845] + Sat Dec 19 20:06:10 2015 Naohisa Goto * enc/windows_1250.c: Should not use C++ style comments (C99 feature). diff --git a/proc.c b/proc.c index 615a6e9d5a..b8c40a1d84 100644 --- a/proc.c +++ b/proc.c @@ -975,7 +975,6 @@ rb_proc_get_iseq(VALUE self, int *is_proc) const rb_proc_t *proc; const rb_iseq_t *iseq; - again: GetProcPtr(self, proc); iseq = proc->block.iseq; if (is_proc) *is_proc = !proc->is_lambda; @@ -990,8 +989,7 @@ rb_proc_get_iseq(VALUE self, int *is_proc) return iseq; } else if (SYMBOL_P(iseq)) { - self = rb_sym_to_proc((VALUE)iseq); - goto again; + return NULL; } else { return rb_iseq_check(iseq); diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 94541865f2..8960bec0d1 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -164,6 +164,18 @@ class TestSymbol < Test::Unit::TestCase end; end + def test_to_proc_iseq + assert_separately([], <<~"end;", timeout: 1) # do + bug11845 = '[ruby-core:72381] [Bug #11845]' + assert_nil(:class.to_proc.source_location, bug11845) + assert_equal([[:rest]], :class.to_proc.parameters, bug11845) + c = Class.new {define_method(:klass, :class.to_proc)} + m = c.instance_method(:klass) + assert_nil(m.source_location, bug11845) + assert_equal([[:rest]], m.parameters, bug11845) + end; + end + def test_call o = Object.new def o.foo(x, y); x + y; end -- cgit v1.2.3