From 19ec803179eb698e5aa72e1a024d60a4e4ff1a87 Mon Sep 17 00:00:00 2001 From: Satoshi Tagomori Date: Wed, 31 Jul 2024 10:15:29 +0900 Subject: [PATCH] Reset the counter for two consecutive runs --- ext/-test-/ensure_and_callcc/ensure_and_callcc.c | 8 ++++++++ test/-ext-/test_ensure_and_callcc.rb | 1 + 2 files changed, 9 insertions(+) diff --git a/ext/-test-/ensure_and_callcc/ensure_and_callcc.c b/ext/-test-/ensure_and_callcc/ensure_and_callcc.c index aef83769a67693..1a92de69c37854 100644 --- a/ext/-test-/ensure_and_callcc/ensure_and_callcc.c +++ b/ext/-test-/ensure_and_callcc/ensure_and_callcc.c @@ -40,11 +40,19 @@ ensure_called(VALUE self) return rb_iv_get(rb_mEnsureAndCallcc, "@ensure_called"); } +static VALUE +reset(VALUE self) +{ + rb_iv_set(rb_mEnsureAndCallcc, "@ensure_called", INT2FIX(0)); + return Qnil; +} + void Init_ensure_and_callcc(void) { rb_mEnsureAndCallcc = rb_define_module("EnsureAndCallcc"); rb_iv_set(rb_mEnsureAndCallcc, "@ensure_called", INT2FIX(0)); + rb_define_singleton_method(rb_mEnsureAndCallcc, "reset", reset, 0); rb_define_singleton_method(rb_mEnsureAndCallcc, "ensure_called", ensure_called, 0); rb_define_singleton_method(rb_mEnsureAndCallcc, "require_with_ensure", require_with_ensure, 1); } diff --git a/test/-ext-/test_ensure_and_callcc.rb b/test/-ext-/test_ensure_and_callcc.rb index 695ca3b64694f1..9303a094eabbca 100644 --- a/test/-ext-/test_ensure_and_callcc.rb +++ b/test/-ext-/test_ensure_and_callcc.rb @@ -23,6 +23,7 @@ def test_bug20655_dir_chdir_using_rb_ensure def test_bug20655_extension_using_rb_ensure need_continuation require '-test-/ensure_and_callcc' + EnsureAndCallcc.reset assert_equal(0, EnsureAndCallcc.ensure_called) EnsureAndCallcc.require_with_ensure(File.join(__dir__, 'required')) assert_equal(1, EnsureAndCallcc.ensure_called,