Bug #12743
closedthrow(false) does not work as expected
Description
I expect UncaughtThrowError for these examples:
$ ruby -e'throw false'
-e: unexpected throw
$ ruby -e'Fiber.new{throw false}.resume'
$ ruby -e'Thread.new{throw false}.join'
-e:1: [BUG] thread_join: THROW_DATA should not reach here.
ruby 2.4.0dev (2016-09-09 trunk 56124) [x86_64-linux]
-- Control frame information -----------------------------------------------
<snip>
The cause is that Kernel#throw incorrectly finds a tag that is not created by Kernel#catch, because TH_PUSH_TAG() initializes rb_vm_tag::tag with 0.
The attached patch seems to fix the issue, by making TH_PUSH_TAG() initialize with Qundef that should never appear in Ruby code.
Files
        
           Updated by Anonymous about 9 years ago
          Updated by Anonymous about 9 years ago
          
          
        
        
      
      - Status changed from Open to Closed
Applied in changeset r56252.
eval_intern.h: make TH_PUSH_TAG() initialize rb_vm_tag::tag with Qundef
- 
eval_intern.h (TH_PUSH_TAG): Initialize struct rb_vm_tag::tag with 
 Qundef rather than 0 which is equal to Qfalse. Since Kernel#throw(obj)
 searches a tag with rb_vm_tag::tag == obj, throw(false) can
 accidentally find an unrelated tag which is not created by
 Kernel#catch. [ruby-core:77229] [Bug #12743]
- 
test/ruby/test_exception.rb (test_throw_false): Add a test case for 
 this.
        
           Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
          Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
          
          
        
        
      
      - Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED
        
           Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
          Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
          
          
        
        
      
      - Backport changed from 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: DONE
ruby_2_3 r56441 merged revision(s) 56252,56254.
        
           Updated by usa (Usaku NAKAMURA) about 9 years ago
          Updated by usa (Usaku NAKAMURA) about 9 years ago
          
          
        
        
      
      - Backport changed from 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: DONE to 2.1: UNKNOWN, 2.2: DONE, 2.3: DONE
ruby_2_2 r56505 merged revision(s) 56252,56254.