Actions
Bug #20253
closed`Proc.dup` and `Proc#clone` don't preserve finalizers
Bug #20253:
`Proc.dup` and `Proc#clone` don't preserve finalizers
Description
While reviewing the fix for [Bug #20250] @peterzhu2118 (Peter Zhu) pointed that FL_FINALIZE should probably also be cleared.
However after some extra testing, it appears Object#dup and Object#clone do copy over the finalizer (which makes sense).
But for some reason Proc has its own dup/clone implementation, which does copy the FL_FINALIZE flag, but doesn't copy the finalizer:
Test script:
def fin(sym)
->(_) { p sym }
end
obj = Object.new
ObjectSpace.define_finalizer(obj, fin(:obj))
obj.dup
obj.clone
proc = Proc.new { }
ObjectSpace.define_finalizer(proc, fin(:proc))
proc.dup
proc.clone
Expected output:
:proc
:proc
:proc
:obj
:obj
:obj
Actual output:
:proc
:obj
:obj
:obj
This discrepancy is present all the way back to Ruby 1.9.
It's so niche I'm not sure it's worth a backport though...
Actions