[前][次][番号順一覧][スレッド一覧]

ruby-changes:38769

From: nobu <ko1@a...>
Date: Fri, 12 Jun 2015 22:01:50 +0900 (JST)
Subject: [ruby-changes:38769] nobu:r50850 (trunk): vm.c: break from orphan block

nobu	2015-06-12 22:01:40 +0900 (Fri, 12 Jun 2015)

  New Revision: 50850

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50850

  Log:
    vm.c: break from orphan block
    
    * vm.c (rb_vm_search_cf_from_ep): break from orphan block is
      possible condition, but not [BUG].
      [ruby-core:69548] [Bug #11254]

  Modified files:
    trunk/test/ruby/test_enum.rb
    trunk/vm.c
Index: vm.c
===================================================================
--- vm.c	(revision 50849)
+++ vm.c	(revision 50850)
@@ -44,7 +44,7 @@ rb_vm_search_cf_from_ep(const rb_thread_ https://github.com/ruby/ruby/blob/trunk/vm.c#L44
 	    cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
 	}
 
-	rb_bug("rb_vm_search_cf_from_ep: no corresponding cfp");
+	return NULL;
     }
 }
 
@@ -1201,6 +1201,12 @@ vm_iter_break(rb_thread_t *th, VALUE val https://github.com/ruby/ruby/blob/trunk/vm.c#L1201
     VALUE *ep = VM_CF_PREV_EP(cfp);
     rb_control_frame_t *target_cfp = rb_vm_search_cf_from_ep(th, cfp, ep);
 
+#if 0				/* raise LocalJumpError */
+    if (!target_cfp) {
+	rb_vm_localjump_error("unexpected break", val, TAG_BREAK);
+    }
+#endif
+
     th->state = TAG_BREAK;
     th->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK);
     TH_JUMP_TAG(th, TAG_BREAK);
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 50849)
+++ test/ruby/test_enum.rb	(revision 50850)
@@ -53,7 +53,8 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L53
 
     bug5801 = '[ruby-dev:45041]'
     @empty.grep(//)
-    assert_nothing_raised(bug5801) {100.times {@empty.block.call}}
+    block = @empty.block
+    assert_nothing_raised(bug5801) {100.times {block.call}}
 
     a = []
     lambda = ->(x, i) {a << [x, i]}
@@ -201,6 +202,21 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L202
     assert_equal(1, @obj.first)
     assert_equal([1, 2, 3], @obj.first(3))
     assert_nil(@empty.first)
+
+    bug5801 = '[ruby-dev:45041]'
+    assert_in_out_err([], <<-'end;', [], /unexpected break/)
+      empty = Object.new
+      class << empty
+        attr_reader :block
+        include Enumerable
+        def each(&block)
+          @block = block
+          self
+        end
+      end
+      empty.first
+      empty.block.call
+    end;
   end
 
   def test_sort
@@ -440,7 +456,8 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L456
 
     bug5801 = '[ruby-dev:45040]'
     @empty.take_while {true}
-    assert_nothing_raised(bug5801) {100.times {@empty.block.call}}
+    block = @empty.block
+    assert_nothing_raised(bug5801) {100.times {block.call}}
   end
 
   def test_drop

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]