Skip to content

Commit

Permalink
Check return value of ObjectSpace.define_finalizer
Browse files Browse the repository at this point in the history
ObjectSpace.define_finalizer returns an array of `[0, finalizer]`. When
the finalizer is not defined, it returns the finalizer that was passed
in. Otherwise, it returns the originally defined finalizer.
  • Loading branch information
peterzhu2118 committed Jul 18, 2024
1 parent 3ef8e47 commit c8285d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/objectspace/define_finalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ def finalizer(zelf)
ruby_exe(code).should == "ok"
end

it "returns the defined finalizer" do
obj = Object.new
p = proc { |id| }
p2 = p.dup

ret = ObjectSpace.define_finalizer(obj, p)
ret.should == [0, p]
ret[1].should.equal?(p)

ret = ObjectSpace.define_finalizer(obj, p2)
ret.should == [0, p]
ret[1].should.equal?(p)
end

ruby_version_is "3.1" do
describe "when $VERBOSE is not nil" do
it "warns if an exception is raised in finalizer" do
Expand Down

0 comments on commit c8285d3

Please sign in to comment.