Skip to content

Commit

Permalink
Update finalizer spec to run with Ruby 3.4.2
Browse files Browse the repository at this point in the history
This is most likely not the best way to do this, but it works.
Inside the MRI codebase of the latest stable release , the value of
RUBY_VERSION_TEENY is defined as 2, but once you install this version it
is defined as 0. So, when running an installed MRI 3.4.2, the method
undefine_finalizer in the spec would still return nil instead of
actually removing the finalizer, and the spec would fail.
The value of RUBY_API_VERSION_CODE is created from the sum of the major,
minor and teeny components, with the property that
`RUBY_API_VERSION_CODE % 100 == RUBY_VERSION_TEENY`, so the original
check could not have worked if RUBY_VERSION_TEENY actually had the value
1, since that would make the check `RUBY_API_VERSION_CODE == 30400`
fail.

As a workaround, the spec for rb_undefine_finalizer has been disabled
for all Ruby 3.4 releases.
  • Loading branch information
herwinw committed Feb 15, 2025
1 parent c7e52a5 commit 575abab
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion optional/capi/ext/finalizer_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static VALUE define_finalizer(VALUE self, VALUE obj, VALUE finalizer) {
static VALUE undefine_finalizer(VALUE self, VALUE obj) {
// Ruby 3.4.0 and 3.4.1 have a bug where rb_undefine_finalizer is missing
// See: https://bugs.ruby-lang.org/issues/20981
#if RUBY_API_VERSION_CODE == 30400 && (RUBY_VERSION_TEENY == 0 || RUBY_VERSION_TEENY == 1)
#if RUBY_API_VERSION_CODE == 30400
return Qnil;
#else
return rb_undefine_finalizer(obj);
Expand Down
2 changes: 1 addition & 1 deletion optional/capi/finalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
end

describe "rb_undefine_finalizer" do
ruby_bug "#20981", "3.4.0"..."3.4.2" do
ruby_bug "#20981", "3.4.0"..."3.5.0" do
it "removes finalizers from the object" do
code = <<~RUBY
require #{extension_path.dump}
Expand Down

0 comments on commit 575abab

Please sign in to comment.