Skip to content

Commit

Permalink
Add C extension spec for rb_undefine_finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 3, 2025
1 parent f9ada5b commit 040d6e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions optional/capi/ext/finalizer_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ static VALUE define_finalizer(VALUE self, VALUE obj, VALUE finalizer) {
return rb_define_finalizer(obj, finalizer);
}

static VALUE undefine_finalizer(VALUE self, VALUE obj) {
return rb_undefine_finalizer(obj);
}

void Init_finalizer_spec(void) {
VALUE cls = rb_define_class("CApiFinalizerSpecs", rb_cObject);

rb_define_method(cls, "rb_define_finalizer", define_finalizer, 2);
rb_define_method(cls, "rb_undefine_finalizer", undefine_finalizer, 1);
}

#ifdef __cplusplus
Expand Down
17 changes: 17 additions & 0 deletions optional/capi/finalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@
ruby_exe(code).should include("finalizer run\n")
end
end

describe "rb_undefine_finalizer" do
ruby_bug "#20981", "3.4.0"..."3.4.2" do
it "removes finalizers from the object" do
code = <<~RUBY
require #{extension_path.dump}
obj = Object.new
finalizer = Proc.new { puts "finalizer run" }
ObjectSpace.define_finalizer(obj, finalizer)
CApiFinalizerSpecs.new.rb_undefine_finalizer(obj)
RUBY

ruby_exe(code).should.empty?
end
end
end
end

0 comments on commit 040d6e6

Please sign in to comment.