Skip to content

Commit

Permalink
Reset the counter for two consecutive runs
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris authored and ko1 committed Jul 31, 2024
1 parent 7aea269 commit 19ec803
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/-test-/ensure_and_callcc/ensure_and_callcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions test/-ext-/test_ensure_and_callcc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 19ec803

Please sign in to comment.