From: "mame (Yusuke Endoh) via ruby-core" Date: 2024-07-28T08:34:04+00:00 Subject: [ruby-core:118715] [Ruby master Bug#20655] Calling continuation triggers ensure function of rb_ensure Issue #20655 has been updated by mame (Yusuke Endoh). I guess https://github.com/ruby/ruby/pull/11264 will solve your issue. Could you give it a try with your patch? ---------------------------------------- Bug #20655: Calling continuation triggers ensure function of rb_ensure https://bugs.ruby-lang.org/issues/20655#change-109249 * Author: tagomoris (Satoshi Tagomori) * Status: Open * ruby -v: ruby 3.4.0dev (2024-07-26T10:18:32Z test-ensure-called.. 9327e49d31) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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 -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 ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/