Project

General

Profile

Actions

Bug #20655

open

Calling continuation triggers ensure function of rb_ensure

Added by tagomoris (Satoshi Tagomori) about 8 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-07-26T10:18:32Z test-ensure-called.. 9327e49d31) [arm64-darwin23]
[ruby-core:118706]

Description

The bug is reproduced when:

  • rb_ensure(func1, arg1, func2, arg2) is called with arguments:
    • func1: eventually calls rb_f_require() (or Kernel#require via rb_funcall)
    • func2: any C func
    • the required ruby script requires 'continuation' and calls callcc + cont.call

In this situation, cont.call triggers the func2 specified with rb_ensure, even without any exceptions.
The func2 call is triggered every time when cont.call is executed. If cont.call happens multiple times, func2 will be called multiple times.

I created a pull-request to add the test case of this bug: https://github.com/ruby/ruby/pull/11254

And @ko1 (Koichi Sasada) -san said this bug is reproduceable by this code (Dir.chdir uses rb_ensure):

require 'continuation'

Dir.chdir('/tmp') do
  p [__LINE__, tmp = Dir.pwd]
  cont = nil
  callcc{|c| cont = c}
  p [__LINE__, Dir.pwd]
  exit! if Dir.pwd != tmp
  cont.call
end

No data to display

Actions

Also available in: Atom PDF

Like0